diff --git a/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php index a22a9859..288fc05c 100644 --- a/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php @@ -1,49 +1,52 @@ 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(); $strings = $class_declaration->selectDescendantsOfType('n_STRING_SCALAR'); foreach ($strings as $string) { $contents = substr($string->getSemanticString(), 1, -1); $replacement = null; if ($contents == $class_name) { $replacement = '__CLASS__'; } $regex = '/\b'.preg_quote($class_name, '/').'\b/'; if (!preg_match($regex, $contents)) { continue; } $this->raiseLintAtNode( $string, pht( "Don't hard-code class names, use `%s` instead.", '__CLASS__'), $replacement); } } } } diff --git a/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php index d18f0335..4179c899 100644 --- a/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php @@ -1,32 +1,34 @@ selectDescendantsOfType('n_NEW'); foreach ($nodes as $node) { $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.'), $class->getConcreteString().'()'); } } } } diff --git a/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php index 7ad7c238..c87974d7 100644 --- a/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistSelfClassReferenceXHPASTLinterRule.php @@ -1,45 +1,48 @@ 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(); $instantiations = $class_declaration ->selectDescendantsOfType('n_NEW'); foreach ($instantiations as $instantiation) { $type = $instantiation->getChildByIndex(0); if ($type->getTypeName() != 'n_CLASS_NAME') { continue; } if (strtolower($type->getConcreteString()) == strtolower($class_name)) { $this->raiseLintAtNode( $type, pht( 'Use `%s` to instantiate the current class.', 'self'), 'self'); } } } } } diff --git a/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php index 1abbaa01..5c197a60 100644 --- a/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistUnnecessaryFinalModifierXHPASTLinterRule.php @@ -1,52 +1,55 @@ 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; foreach ($attributes->getChildren() as $attribute) { if ($attribute->getConcreteString() == 'final') { $is_final = true; break; } } if (!$is_final) { continue; } $methods = $class->selectDescendantsOfType('n_METHOD_DECLARATION'); foreach ($methods as $method) { $attributes = $method->getChildOfType(0, 'n_METHOD_MODIFIER_LIST'); foreach ($attributes->getChildren() as $attribute) { if ($attribute->getConcreteString() == 'final') { $this->raiseLintAtNode( $attribute, pht( 'Unnecessary `%s` modifier in `%s` class.', 'final', 'final')); } } } } } } 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 index f6050e6f..263fa6bc 100644 --- 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 @@ -1,30 +1,42 @@