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 = file($abspath); | ||||
deadalnix: Why the change? It's probably better to use the facilities of the framework you are working in. | |||||
FabienAuthorUnsubmitted Done Inline ActionsThey don't do the same, Filesystem::readFile() stores the content into a single string, while file() stores an array of lines. There is no equivalent in the Filesystem library. Fabien: They don't do the same, `Filesystem::readFile()` stores the content into a single string, while… | |||||
deadalnixUnsubmitted Not Done Inline ActionsJust explode the string. BTW, this introduce an error condition in the case file returns false, which is exactly why you don't want to do this and just use readFile. deadalnix: Just explode the string.
BTW, this introduce an error condition in the case file returns false… | |||||
$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; | |||||
} | |||||
} | |||||
} | } |
Why the change? It's probably better to use the facilities of the framework you are working in.