Page MenuHomePhabricator

D10597.id25574.diff
No OneTemporary

D10597.id25574.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
@@ -48,6 +48,7 @@
const LINT_LANGUAGE_CONSTRUCT_PAREN = 46;
const LINT_EMPTY_STATEMENT = 47;
const LINT_ARRAY_SEPARATOR = 48;
+ const LINT_CONSTRUCTOR_PARENTHESES = 49;
private $naminghook;
private $switchhook;
@@ -107,6 +108,7 @@
self::LINT_LANGUAGE_CONSTRUCT_PAREN => 'Language Construct Parentheses',
self::LINT_EMPTY_STATEMENT => 'Empty Block Statement',
self::LINT_ARRAY_SEPARATOR => 'Array Separator',
+ self::LINT_CONSTRUCTOR_PARENTHESES => 'Constructor Parentheses',
);
}
@@ -147,6 +149,7 @@
self::LINT_LANGUAGE_CONSTRUCT_PAREN => $warning,
self::LINT_EMPTY_STATEMENT => $advice,
self::LINT_ARRAY_SEPARATOR => $advice,
+ self::LINT_CONSTRUCTOR_PARENTHESES => $advice,
);
}
@@ -196,7 +199,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '9';
+ return '10';
}
protected function resolveFuture($path, Future $future) {
@@ -267,6 +270,7 @@
'lintLanguageConstructParentheses' => self::LINT_LANGUAGE_CONSTRUCT_PAREN,
'lintEmptyBlockStatements' => self::LINT_EMPTY_STATEMENT,
'lintArraySeparator' => self::LINT_ARRAY_SEPARATOR,
+ 'lintConstructorParentheses' => self::LINT_CONSTRUCTOR_PARENTHESES,
);
foreach ($method_codes as $method => $codes) {
@@ -2792,6 +2796,23 @@
}
}
+ private function lintConstructorParentheses(XHPASTNode $root) {
+ $nodes = $root->selectDescendantsOfType('n_NEW');
+
+ foreach ($nodes as $node) {
+ $class = $node->getChildByIndex(0);
+ $params = $node->getChildByIndex(1);
+
+ if ($params->getTypeName() == 'n_EMPTY') {
+ $this->raiseLintAtNode(
+ $class,
+ self::LINT_CONSTRUCTOR_PARENTHESES,
+ pht('Use parentheses when invoking a constructor.'),
+ $class->getConcreteString().'()');
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/constructor-parentheses.lint-test b/src/lint/linter/__tests__/xhpast/constructor-parentheses.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/constructor-parentheses.lint-test
@@ -0,0 +1,12 @@
+<?php
+new Foo;
+new Bar();
+new Foo\Bar;
+~~~~~~~~~~
+advice:2:5
+advice:4:5
+~~~~~~~~~~
+<?php
+new Foo();
+new Bar();
+new Foo\Bar();

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 9:36 PM (3 d, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6722323
Default Alt Text
D10597.id25574.diff (2 KB)

Event Timeline