]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve ArcanistXHPASTLinter::LINT_TOSTRING_EXCEPTION
authorJoshua Spence <josh@joshuaspence.com>
Sun, 17 May 2015 23:04:22 +0000 (09:04 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Sun, 17 May 2015 23:14:55 +0000 (09:14 +1000)
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

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/tostring-exception.lint-test

index cad5bffac44d70dccacc0b066e869f230840ede1..88e4ffea4681b936e71409e79457da93475b8dca 100644 (file)
@@ -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(
index 2788fbdca6b3f20c5ffad90ce3f8ac3f0d09c0d0..32913db79c175c8f6b5593f049d0514b12172718 100644 (file)
@@ -14,5 +14,13 @@ class MyOtherClass {
     return 'Success';
   }
 }
+
+interface SomeInterface {
+  public function __toString();
+}
+
+abstract class SomeAbstractClass {
+  abstract public function __toString();
+}
 ~~~~~~~~~~
 error:5:7