Page MenuHomePhabricator

D19741.id47163.diff
No OneTemporary

D19741.id47163.diff

diff --git a/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php
@@ -17,6 +17,9 @@
$class_declarations = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($class_declarations as $class_declaration) {
+ if ($class_declaration->getChildByIndex(1)->getTypeName() == 'n_EMPTY') {
+ continue;
+ }
$class_name = $class_declaration
->getChildOfType(1, 'n_CLASS_NAME')
->getConcreteString();
diff --git a/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php
@@ -20,7 +20,9 @@
$class = $node->getChildByIndex(0);
$params = $node->getChildByIndex(1);
- if ($params->getTypeName() == 'n_EMPTY') {
+ if ($class->getTypeName() != 'n_CLASS_DECLARATION' &&
+ $params->getTypeName() == 'n_EMPTY') {
+
$this->raiseLintAtNode(
$class,
pht('Use parentheses when invoking a constructor.'),
diff --git a/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php
@@ -17,6 +17,9 @@
$class_declarations = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($class_declarations as $class_declaration) {
+ if ($class_declaration->getChildByIndex(1)->getTypeName() == 'n_EMPTY') {
+ continue;
+ }
$class_name = $class_declaration
->getChildOfType(1, 'n_CLASS_NAME')
->getConcreteString();
diff --git a/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php
@@ -17,6 +17,9 @@
$classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($classes as $class) {
+ if ($class->getChildByIndex(0)->getTypeName() == 'n_EMPTY') {
+ continue;
+ }
$attributes = $class->getChildOfType(0, 'n_CLASS_ATTRIBUTES');
$is_final = false;
diff --git a/src/lint/linter/xhpast/rules/__tests__/class-name-literal/class-name-literal.lint-test b/src/lint/linter/xhpast/rules/__tests__/class-name-literal/class-name-literal.lint-test
--- a/src/lint/linter/xhpast/rules/__tests__/class-name-literal/class-name-literal.lint-test
+++ b/src/lint/linter/xhpast/rules/__tests__/class-name-literal/class-name-literal.lint-test
@@ -11,6 +11,12 @@
return __CLASS__;
}
}
+
+$c = new class {
+ public function someMethod() {
+ return __CLASS__;
+ }
+};
~~~~~~~~~~
advice:5:12
advice:9:10
@@ -28,3 +34,9 @@
return __CLASS__;
}
}
+
+$c = new class {
+ public function someMethod() {
+ return __CLASS__;
+ }
+};
diff --git a/src/lint/linter/xhpast/rules/__tests__/constructor-parentheses/constructor-parentheses.lint-test b/src/lint/linter/xhpast/rules/__tests__/constructor-parentheses/constructor-parentheses.lint-test
--- a/src/lint/linter/xhpast/rules/__tests__/constructor-parentheses/constructor-parentheses.lint-test
+++ b/src/lint/linter/xhpast/rules/__tests__/constructor-parentheses/constructor-parentheses.lint-test
@@ -3,6 +3,7 @@
new Foo;
new Bar();
new Foo\Bar;
+new class {};
~~~~~~~~~~
advice:3:5
advice:5:5
@@ -12,3 +13,4 @@
new Foo();
new Bar();
new Foo\Bar();
+new class {};
diff --git a/src/lint/linter/xhpast/rules/__tests__/self-class-reference/self-class-references.lint-test b/src/lint/linter/xhpast/rules/__tests__/self-class-reference/self-class-references.lint-test
--- a/src/lint/linter/xhpast/rules/__tests__/self-class-reference/self-class-references.lint-test
+++ b/src/lint/linter/xhpast/rules/__tests__/self-class-reference/self-class-references.lint-test
@@ -9,6 +9,12 @@
return new self();
}
}
+
+$c = new class {
+ public function newInstance() {
+ return new self();
+ }
+};
~~~~~~~~~~
warning:5:16
~~~~~~~~~~
@@ -23,3 +29,9 @@
return new self();
}
}
+
+$c = new class {
+ public function newInstance() {
+ return new self();
+ }
+};
diff --git a/src/lint/linter/xhpast/rules/__tests__/unnecessary-final-modifier/unnecessary-final-modifier.lint-test b/src/lint/linter/xhpast/rules/__tests__/unnecessary-final-modifier/unnecessary-final-modifier.lint-test
--- a/src/lint/linter/xhpast/rules/__tests__/unnecessary-final-modifier/unnecessary-final-modifier.lint-test
+++ b/src/lint/linter/xhpast/rules/__tests__/unnecessary-final-modifier/unnecessary-final-modifier.lint-test
@@ -4,5 +4,6 @@
public function bar() {}
final public function baz() {}
}
+$c = new class {};
~~~~~~~~~~
advice:5:3

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 4:59 AM (5 d, 20 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705902
Default Alt Text
D19741.id47163.diff (5 KB)

Event Timeline