Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/DoxygenLinter.php
Show All 38 Lines | final class DoxygenLinter extends ArcanistLinter { | ||||
public function getLintNameMap() { | public function getLintNameMap() { | ||||
return array( | return array( | ||||
self::BAD_INLINE_COMMENT => pht('Misplaced inline doxygen comment.'), | self::BAD_INLINE_COMMENT => pht('Misplaced inline doxygen comment.'), | ||||
); | ); | ||||
} | } | ||||
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 = explode("\n", Filesystem::readFile($abspath)); | ||||
$sanitizedOpenings = array_map('preg_quote', self::$doxygenCommentOpenings); | $sanitizedOpenings = array_map('preg_quote', self::$doxygenCommentOpenings); | ||||
$anyDoxygenCommentOpening = implode('|', $sanitizedOpenings); | $anyDoxygenCommentOpening = implode('|', $sanitizedOpenings); | ||||
if (!preg_match_all("@^\s*($anyDoxygenCommentOpening)<.+@m", $fileContent, | $previousLine = ""; | ||||
foreach ($fileContent as $lineNumber => $lineContent) { | |||||
if (preg_match("@^\s*($anyDoxygenCommentOpening)<.+@m", $lineContent, | |||||
$matches, PREG_OFFSET_CAPTURE)) { | $matches, PREG_OFFSET_CAPTURE)) { | ||||
return; | list($commentOpening, $offset) = $matches[1]; | ||||
} | |||||
foreach ($matches[1] as $match) { | if (strpos($previousLine, $commentOpening) === false) { | ||||
list($commentOpening, $offset) = $match; | |||||
$original = $commentOpening.'<'; | $original = $commentOpening.'<'; | ||||
$replacement = $commentOpening; | $replacement = $commentOpening; | ||||
$this->raiseLintAtOffset( | $this->raiseLintAtLine( | ||||
$offset, | $lineNumber + 1, | ||||
$offset + 1, | |||||
self::BAD_INLINE_COMMENT, | self::BAD_INLINE_COMMENT, | ||||
pht('This comment applies to the previous line and should be '. | pht('This comment applies to the previous line and should be '. | ||||
'located after a statement.'), | 'located after a statement.'), | ||||
$original, | $original, | ||||
$replacement); | $replacement); | ||||
} | } | ||||
} | } | ||||
$previousLine = $lineContent; | |||||
} | |||||
} | |||||
} | } |