Commit 82445bb6 authored by Wenzheng Jiang's avatar Wenzheng Jiang Committed by Joshua Spence

Let lint rules support anonymous classes

Summary: Ref T4334. Depends on D19740. Improve some lint rules so they can handle anonymous classes.

Test Plan: Ran updated tests

Reviewers: joshuaspence, #blessed_reviewers, epriestley

Reviewed By: joshuaspence, #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D19741
parent 6a8e76db
......@@ -17,6 +17,9 @@ final class ArcanistClassNameLiteralXHPASTLinterRule
$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();
......
......@@ -20,7 +20,9 @@ final class ArcanistConstructorParenthesesXHPASTLinterRule
$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.'),
......
......@@ -17,6 +17,9 @@ final class ArcanistSelfClassReferenceXHPASTLinterRule
$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();
......
......@@ -17,6 +17,9 @@ final class ArcanistUnnecessaryFinalModifierXHPASTLinterRule
$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;
......
......@@ -11,6 +11,12 @@ class MyClass {
return __CLASS__;
}
}
$c = new class {
public function someMethod() {
return __CLASS__;
}
};
~~~~~~~~~~
advice:5:12
advice:9:10
......@@ -28,3 +34,9 @@ class MyClass {
return __CLASS__;
}
}
$c = new class {
public function someMethod() {
return __CLASS__;
}
};
......@@ -3,6 +3,7 @@
new Foo;
new Bar();
new Foo\Bar;
new class {};
~~~~~~~~~~
advice:3:5
advice:5:5
......@@ -12,3 +13,4 @@ advice:5:5
new Foo();
new Bar();
new Foo\Bar();
new class {};
......@@ -9,6 +9,12 @@ class Foo extends Bar {
return new self();
}
}
$c = new class {
public function newInstance() {
return new self();
}
};
~~~~~~~~~~
warning:5:16
~~~~~~~~~~
......@@ -23,3 +29,9 @@ class Foo extends Bar {
return new self();
}
}
$c = new class {
public function newInstance() {
return new self();
}
};
......@@ -4,5 +4,6 @@ final class Foo {
public function bar() {}
final public function baz() {}
}
$c = new class {};
~~~~~~~~~~
advice:5:3
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment