Page MenuHomePhabricator

D12139.diff
No OneTemporary

D12139.diff

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
@@ -55,6 +55,7 @@
const LINT_CALL_TIME_PASS_BY_REF = 53;
const LINT_FORMATTED_STRING = 54;
const LINT_UNNECESSARY_FINAL_MODIFIER = 55;
+ const LINT_UNNECESSARY_SEMICOLON = 56;
private $blacklistedFunctions = array();
private $naminghook;
@@ -123,6 +124,7 @@
self::LINT_CALL_TIME_PASS_BY_REF => 'Call-Time Pass-By-Reference',
self::LINT_FORMATTED_STRING => 'Formatted String',
self::LINT_UNNECESSARY_FINAL_MODIFIER => 'Unnecessary Final Modifier',
+ self::LINT_UNNECESSARY_SEMICOLON => 'Unnecessary Semicolon',
);
}
@@ -166,6 +168,7 @@
self::LINT_CONSTRUCTOR_PARENTHESES => $advice,
self::LINT_IMPLICIT_VISIBILITY => $advice,
self::LINT_UNNECESSARY_FINAL_MODIFIER => $advice,
+ self::LINT_UNNECESSARY_SEMICOLON => $advice,
);
}
@@ -233,7 +236,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '17';
+ return '18';
}
protected function resolveFuture($path, Future $future) {
@@ -312,6 +315,7 @@
'lintCallTimePassByReference' => self::LINT_CALL_TIME_PASS_BY_REF,
'lintFormattedString' => self::LINT_FORMATTED_STRING,
'lintUnnecessaryFinalModifier' => self::LINT_UNNECESSARY_FINAL_MODIFIER,
+ 'lintUnnecessarySemicolons' => self::LINT_UNNECESSARY_SEMICOLON,
);
foreach ($method_codes as $method => $codes) {
@@ -3229,6 +3233,24 @@
}
}
+ private function lintUnnecessarySemicolons(XHPASTNode $root) {
+ $statements = $root->selectDescendantsOfType('n_STATEMENT');
+
+ foreach ($statements as $statement) {
+ if ($statement->getParentNode()->getTypeName() == 'n_DECLARE') {
+ continue;
+ }
+
+ if ($statement->getSemanticString() == ';') {
+ $this->raiseLintAtNode(
+ $statement,
+ self::LINT_UNNECESSARY_SEMICOLON,
+ pht('Unnecessary semicolons after statement.'),
+ '');
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/empty-statement.lint-test b/src/lint/linter/__tests__/xhpast/empty-statement.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/empty-statement.lint-test
@@ -0,0 +1,11 @@
+<?php
+final class Foo {};
+$x = null;;
+~~~~~~~~~~
+error:2:13 XHP19
+advice:2:19
+advice:3:11
+~~~~~~~~~~
+<?php
+final class Foo {}
+$x = null;

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 22, 1:30 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7706927
Default Alt Text
D12139.diff (2 KB)

Event Timeline