Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/WhitespaceLinter.php
Show All 29 Lines | final class WhitespaceLinter extends ArcanistLinter { | ||||
} | } | ||||
public function getLintNameMap() { | public function getLintNameMap() { | ||||
return array( | return array( | ||||
self::TRAILING_SPACE_FOUND => pht('Found trailing whitespace(s).'), | self::TRAILING_SPACE_FOUND => pht('Found trailing whitespace(s).'), | ||||
); | ); | ||||
} | } | ||||
private function endsWithExactly2Spaces($line) { | |||||
return (rtrim($line) == substr($line, 0, strlen($line) - 2) && | |||||
substr($line, -2) == " "); | |||||
} | |||||
public function lintPath($path) { | public function lintPath($path) { | ||||
$abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | $abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | ||||
$fileContent = Filesystem::readFile($abspath); | $fileContent = Filesystem::readFile($abspath); | ||||
if (preg_match_all('/.*[\t ]+$/m', $fileContent, $matches, | $is_markdown = pathinfo($path, PATHINFO_EXTENSION) == "md"; | ||||
if (preg_match_all('/.*([\t ])+$/m', $fileContent, $matches, | |||||
PREG_OFFSET_CAPTURE)) { | PREG_OFFSET_CAPTURE)) { | ||||
foreach ($matches[0] as $match) { | foreach ($matches[0] as $match) { | ||||
list($fullLine, $offset) = $match; | list($fullLine, $offset) = $match; | ||||
/* Exactly two trailing whitespaces is a hard line break in markdown */ | |||||
if ($is_markdown && $this->endsWithExactly2Spaces($fullLine)) { | |||||
continue; | |||||
} | |||||
$this->raiseLintAtOffset( | $this->raiseLintAtOffset( | ||||
$offset, | $offset, | ||||
self::TRAILING_SPACE_FOUND, | self::TRAILING_SPACE_FOUND, | ||||
pht('Found trailing whitespace(s).'), | pht('Found trailing whitespace(s).'), | ||||
$fullLine, | $fullLine, | ||||
rtrim($fullLine)); | rtrim($fullLine)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |