Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F19469790
D9195.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9195.id.diff
View Options
diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -45,6 +45,7 @@
const LINT_KEYWORD_CASING = 40;
const LINT_DOUBLE_QUOTE = 41;
const LINT_ELSEIF_USAGE = 42;
+ const LINT_SEMICOLON_SPACING = 43;
private $naminghook;
private $switchhook;
@@ -103,6 +104,7 @@
self::LINT_KEYWORD_CASING => 'Keyword Conventions',
self::LINT_DOUBLE_QUOTE => 'Unnecessary Double Quotes',
self::LINT_ELSEIF_USAGE => 'ElseIf Usage',
+ self::LINT_SEMICOLON_SPACING => 'Semicolon Spacing',
);
}
@@ -138,6 +140,7 @@
self::LINT_KEYWORD_CASING => $warning,
self::LINT_DOUBLE_QUOTE => $advice,
self::LINT_ELSEIF_USAGE => $advice,
+ self::LINT_SEMICOLON_SPACING => $advice,
// This is disabled by default because it implies a very strict policy
// which isn't necessary in the general case.
@@ -253,6 +256,7 @@
'lintKeywordCasing' => self::LINT_KEYWORD_CASING,
'lintStrings' => self::LINT_DOUBLE_QUOTE,
'lintElseIfStatements' => self::LINT_ELSEIF_USAGE,
+ 'lintSemicolons' => self::LINT_SEMICOLON_SPACING,
);
foreach ($method_codes as $method => $codes) {
@@ -2454,6 +2458,22 @@
}
}
+ 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() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test b/src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test
@@ -0,0 +1,14 @@
+<?php
+foo();
+bar() ;
+baz()
+
+ ;
+~~~~~~~~~~
+advice:3:6
+advice:4:6
+~~~~~~~~~~
+<?php
+foo();
+bar();
+baz();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 6, 4:09 AM (2 d, 13 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
11631362
Default Alt Text
D9195.id.diff (2 KB)
Attached To
Mode
D9195: Add a rule to the XHPAST linter to check for whitespace before a semicolon.
Attached
Detach File
Event Timeline
Log In to Comment