From: Joshua Spence Date: Sun, 17 May 2015 23:04:22 +0000 (+1000) Subject: Improve ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=8c6e1284cc656034955228412154b22b556b5430;p=arcanist.git Improve ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION Summary: The `ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION` linter rule was introduced in D12854, but fails for the following: - Interfaces which declare the `__toString()` method. - Classes which mark the `__toString()` method as `abstract`. Test Plan: Added test cases. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12892 --- diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index cad5bffa..88e4ffea 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -4144,9 +4144,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { continue; } - $throws = $method - ->getChildOfType(5, 'n_STATEMENT_LIST') - ->selectDescendantsOfType('n_THROW'); + $statements = $method->getChildByIndex(5); + + if ($statements->getTypeName() != 'n_STATEMENT_LIST') { + continue; + } + + $throws = $statements->selectDescendantsOfType('n_THROW'); foreach ($throws as $throw) { $this->raiseLintAtNode( diff --git a/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test b/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test index 2788fbdc..32913db7 100644 --- a/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test +++ b/src/lint/linter/__tests__/xhpast/tostring-exception.lint-test @@ -14,5 +14,13 @@ class MyOtherClass { return 'Success'; } } + +interface SomeInterface { + public function __toString(); +} + +abstract class SomeAbstractClass { + abstract public function __toString(); +} ~~~~~~~~~~ error:5:7