mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Add a rule to the XHPAST linter to check for whitespace before a semicolon.
Summary: This rule is based on a rule from [[https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php | PHP_CodeSniffer]]. Test Plan: Wrote and executed unit tests. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9195
This commit is contained in:
parent
566c7e9c5c
commit
b251615716
2 changed files with 34 additions and 0 deletions
|
@ -45,6 +45,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
const LINT_KEYWORD_CASING = 40;
|
const LINT_KEYWORD_CASING = 40;
|
||||||
const LINT_DOUBLE_QUOTE = 41;
|
const LINT_DOUBLE_QUOTE = 41;
|
||||||
const LINT_ELSEIF_USAGE = 42;
|
const LINT_ELSEIF_USAGE = 42;
|
||||||
|
const LINT_SEMICOLON_SPACING = 43;
|
||||||
|
|
||||||
private $naminghook;
|
private $naminghook;
|
||||||
private $switchhook;
|
private $switchhook;
|
||||||
|
@ -103,6 +104,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
self::LINT_KEYWORD_CASING => 'Keyword Conventions',
|
self::LINT_KEYWORD_CASING => 'Keyword Conventions',
|
||||||
self::LINT_DOUBLE_QUOTE => 'Unnecessary Double Quotes',
|
self::LINT_DOUBLE_QUOTE => 'Unnecessary Double Quotes',
|
||||||
self::LINT_ELSEIF_USAGE => 'ElseIf Usage',
|
self::LINT_ELSEIF_USAGE => 'ElseIf Usage',
|
||||||
|
self::LINT_SEMICOLON_SPACING => 'Semicolon Spacing',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +140,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
self::LINT_KEYWORD_CASING => $warning,
|
self::LINT_KEYWORD_CASING => $warning,
|
||||||
self::LINT_DOUBLE_QUOTE => $advice,
|
self::LINT_DOUBLE_QUOTE => $advice,
|
||||||
self::LINT_ELSEIF_USAGE => $advice,
|
self::LINT_ELSEIF_USAGE => $advice,
|
||||||
|
self::LINT_SEMICOLON_SPACING => $advice,
|
||||||
|
|
||||||
// This is disabled by default because it implies a very strict policy
|
// This is disabled by default because it implies a very strict policy
|
||||||
// which isn't necessary in the general case.
|
// which isn't necessary in the general case.
|
||||||
|
@ -253,6 +256,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
'lintKeywordCasing' => self::LINT_KEYWORD_CASING,
|
'lintKeywordCasing' => self::LINT_KEYWORD_CASING,
|
||||||
'lintStrings' => self::LINT_DOUBLE_QUOTE,
|
'lintStrings' => self::LINT_DOUBLE_QUOTE,
|
||||||
'lintElseIfStatements' => self::LINT_ELSEIF_USAGE,
|
'lintElseIfStatements' => self::LINT_ELSEIF_USAGE,
|
||||||
|
'lintSemicolons' => self::LINT_SEMICOLON_SPACING,
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($method_codes as $method => $codes) {
|
foreach ($method_codes as $method => $codes) {
|
||||||
|
@ -2454,6 +2458,22 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function lintSemicolons(XHPASTNode $root) {
|
||||||
|
$tokens = $root->selectTokensOfType(';');
|
||||||
|
|
||||||
|
foreach ($tokens as $token) {
|
||||||
|
$prev = $token->getPrevToken();
|
||||||
|
|
||||||
|
if ($prev->isAnyWhitespace()) {
|
||||||
|
$this->raiseLintAtToken(
|
||||||
|
$prev,
|
||||||
|
self::LINT_SEMICOLON_SPACING,
|
||||||
|
pht('Space found before semicolon.'),
|
||||||
|
'');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getSuperGlobalNames() {
|
public function getSuperGlobalNames() {
|
||||||
return array(
|
return array(
|
||||||
'$GLOBALS',
|
'$GLOBALS',
|
||||||
|
|
14
src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test
Normal file
14
src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
foo();
|
||||||
|
bar() ;
|
||||||
|
baz()
|
||||||
|
|
||||||
|
;
|
||||||
|
~~~~~~~~~~
|
||||||
|
advice:3:6
|
||||||
|
advice:4:6
|
||||||
|
~~~~~~~~~~
|
||||||
|
<?php
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
baz();
|
Loading…
Reference in a new issue