mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Add a linter rule for object operator spacing
Summary: Add a linter rule to check that there is no whitespace surrounding the object operator, `->`. Test Plan: Added test case. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D13798
This commit is contained in:
parent
c8f0deffab
commit
986f5d82d0
3 changed files with 61 additions and 0 deletions
|
@ -171,6 +171,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistNoLintLinterTestCase.php',
|
'ArcanistNoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistNoLintLinterTestCase.php',
|
||||||
'ArcanistNoParentScopeXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistNoParentScopeXHPASTLinterRule.php',
|
'ArcanistNoParentScopeXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistNoParentScopeXHPASTLinterRule.php',
|
||||||
'ArcanistNoneLintRenderer' => 'lint/renderer/ArcanistNoneLintRenderer.php',
|
'ArcanistNoneLintRenderer' => 'lint/renderer/ArcanistNoneLintRenderer.php',
|
||||||
|
'ArcanistObjectOperatorSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistObjectOperatorSpacingXHPASTLinterRule.php',
|
||||||
'ArcanistPEP8Linter' => 'lint/linter/ArcanistPEP8Linter.php',
|
'ArcanistPEP8Linter' => 'lint/linter/ArcanistPEP8Linter.php',
|
||||||
'ArcanistPEP8LinterTestCase' => 'lint/linter/__tests__/ArcanistPEP8LinterTestCase.php',
|
'ArcanistPEP8LinterTestCase' => 'lint/linter/__tests__/ArcanistPEP8LinterTestCase.php',
|
||||||
'ArcanistPHPCloseTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPHPCloseTagXHPASTLinterRule.php',
|
'ArcanistPHPCloseTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPHPCloseTagXHPASTLinterRule.php',
|
||||||
|
@ -445,6 +446,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoLintLinterTestCase' => 'ArcanistLinterTestCase',
|
'ArcanistNoLintLinterTestCase' => 'ArcanistLinterTestCase',
|
||||||
'ArcanistNoParentScopeXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistNoParentScopeXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistNoneLintRenderer' => 'ArcanistLintRenderer',
|
'ArcanistNoneLintRenderer' => 'ArcanistLintRenderer',
|
||||||
|
'ArcanistObjectOperatorSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistPEP8Linter' => 'ArcanistExternalLinter',
|
'ArcanistPEP8Linter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistPEP8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
'ArcanistPEP8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||||
'ArcanistPHPCloseTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistPHPCloseTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
$x -> doSomething();
|
||||||
|
id(new Something())
|
||||||
|
->doSomething();
|
||||||
|
~~~~~~~~~~
|
||||||
|
warning:2:3
|
||||||
|
warning:2:6
|
||||||
|
~~~~~~~~~~
|
||||||
|
<?php
|
||||||
|
$x->doSomething();
|
||||||
|
id(new Something())
|
||||||
|
->doSomething();
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistObjectOperatorSpacingXHPASTLinterRule
|
||||||
|
extends ArcanistXHPASTLinterRule {
|
||||||
|
|
||||||
|
const ID = 74;
|
||||||
|
|
||||||
|
public function getLintName() {
|
||||||
|
return pht('Object Operator Spacing');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLintSeverity() {
|
||||||
|
return ArcanistLintSeverity::SEVERITY_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(XHPASTNode $root) {
|
||||||
|
$operators = $root->selectTokensOfType('T_OBJECT_OPERATOR');
|
||||||
|
|
||||||
|
foreach ($operators as $operator) {
|
||||||
|
$before = $operator->getNonsemanticTokensBefore();
|
||||||
|
$after = $operator->getNonsemanticTokensAfter();
|
||||||
|
|
||||||
|
if ($before) {
|
||||||
|
$value = implode('', mpull($before, 'getValue'));
|
||||||
|
|
||||||
|
if (strpos($value, "\n") !== false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->raiseLintAtOffset(
|
||||||
|
head($before)->getOffset(),
|
||||||
|
pht('There should be no whitespace before the object operator.'),
|
||||||
|
$value,
|
||||||
|
'');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($after) {
|
||||||
|
$this->raiseLintAtOffset(
|
||||||
|
head($after)->getOffset(),
|
||||||
|
pht('There should be no whitespace after the object operator.'),
|
||||||
|
implode('', mpull($before, 'getValue')),
|
||||||
|
'');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue