Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/xhpast/rules/ArcanistCommentStyleXHPASTLinterRule.php
Show All 11 Lines | final class ArcanistCommentStyleXHPASTLinterRule | ||||
public function process(XHPASTNode $root) { | public function process(XHPASTNode $root) { | ||||
foreach ($root->selectTokensOfType('T_COMMENT') as $comment) { | foreach ($root->selectTokensOfType('T_COMMENT') as $comment) { | ||||
$value = $comment->getValue(); | $value = $comment->getValue(); | ||||
if ($value[0] !== '#') { | if ($value[0] !== '#') { | ||||
continue; | continue; | ||||
} | } | ||||
// Don't warn about PHP comment directives. In particular, we need | |||||
// to use "#[\ReturnTypeWillChange]" to implement "Iterator" in a way | |||||
// that is compatible with PHP 8.1 and older versions of PHP prior | |||||
// to the introduction of return types. See T13588. | |||||
if (preg_match('/^#\\[\\\\/', $value)) { | |||||
continue; | |||||
} | |||||
$this->raiseLintAtOffset( | $this->raiseLintAtOffset( | ||||
$comment->getOffset(), | $comment->getOffset(), | ||||
pht( | pht( | ||||
'Use `%s` single-line comments, not `%s`.', | 'Use `%s` single-line comments, not `%s`.', | ||||
'//', | '//', | ||||
'#'), | '#'), | ||||
'#', | '#', | ||||
preg_match('/^#\S/', $value) ? '// ' : '//'); | preg_match('/^#\S/', $value) ? '// ' : '//'); | ||||
} | } | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0