Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/PythonFileEncodingLinter.php
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public function lintPath($path) { | ||||
$pattern = "/[(\s]open(\(((?>[^()]+)|(?1))*\))/"; | $pattern = "/[(\s]open(\(((?>[^()]+)|(?1))*\))/"; | ||||
if (preg_match_all($pattern, $fileContent, $matches, | if (preg_match_all($pattern, $fileContent, $matches, | ||||
PREG_OFFSET_CAPTURE)) { | PREG_OFFSET_CAPTURE)) { | ||||
foreach ($matches[0] as $match) { | foreach ($matches[0] as $match) { | ||||
list($open, $offset) = $match; | list($open, $offset) = $match; | ||||
$isBin = preg_match( | $isBin = preg_match( | ||||
"/open\(.*, ['\"][rwxat+]*b[rwxat+]*['\"]/", $open); | "/open\(.*,\s? +['\"][rwxat+]*b[rwxat+]*['\"]/s", $open); | ||||
$hasEncoding = preg_match("/encoding=.(ascii|utf8|utf-8)./", $open); | $hasEncoding = preg_match("/encoding=.(ascii|utf8|utf-8)./", $open); | ||||
if (!$isBin && !$hasEncoding) { | if (!$isBin && !$hasEncoding) { | ||||
$this->raiseLintAtOffset( | $this->raiseLintAtOffset( | ||||
$offset + 1, | $offset + 1, | ||||
self::ENCODING_NOT_FOUND, | self::ENCODING_NOT_FOUND, | ||||
pht("Python's open(...) seems to be used to open text files ". | pht("Python's open(...) seems to be used to open text files ". | ||||
"without explicitly specifying encoding, or with an invalid ". | "without explicitly specifying encoding, or with an invalid ". | ||||
Show All 33 Lines |