]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improvements to `LINT_IMPLICIT_VISIBILITY`
authorJoshua Spence <josh@joshuaspence.com>
Wed, 7 Jan 2015 20:30:31 +0000 (07:30 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 7 Jan 2015 20:30:31 +0000 (07:30 +1100)
Summary: See D10687#104589.

Test Plan: Wrote unit tests.

Reviewers: richardvanvelzen, epriestley, #blessed_reviewers

Reviewed By: richardvanvelzen, epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11267

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test

index 49381efe801ddd5b5b9653a3e499ab8bf78931d8..2e2ec06645bdcfe8e033cd75a7f83d478530560c 100644 (file)
@@ -3004,20 +3004,36 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
   }
 
   private function lintMethodModifier(XHPASTNode $root) {
+    static $visibilities = array(
+      'public',
+      'protected',
+      'private',
+    );
+
     $methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION');
 
     foreach ($methods as $method) {
-      $modifier_list = $method->getChildOfType(
+      $modifiers_list = $method->getChildOfType(
         0,
         'n_METHOD_MODIFIER_LIST');
 
-      if (!$modifier_list->getChildren()) {
-        $this->raiseLintAtNode(
-          $method,
-          self::LINT_IMPLICIT_VISIBILITY,
-          pht('Methods should have their visibility declared explicitly.'),
-          'public '.$method->getConcreteString());
+      foreach ($modifiers_list->getChildren() as $modifier) {
+        if (in_array($modifier->getConcreteString(), $visibilities)) {
+          continue 2;
+        }
       }
+
+      if ($modifiers_list->getChildren()) {
+        $node = $modifiers_list;
+      } else {
+        $node = $method;
+      }
+
+      $this->raiseLintAtNode(
+        $node,
+        self::LINT_IMPLICIT_VISIBILITY,
+        pht('Methods should have their visibility declared explicitly.'),
+        'public '.$node->getConcreteString());
     }
   }
 
index 877b45a66772d7ab10275db1635ff5ee22ac789a..9f7a05078f752b1aa28b3d952308933923549d73 100644 (file)
@@ -2,6 +2,8 @@
 final class Foo {
   public function bar() {}
   function baz() {}
+  abstract function a();
+  private static function b() {}
 
   var $x;
   static $y;
@@ -10,13 +12,16 @@ final class Foo {
 ~~~~~~~~~~
 error:2:13 XHP19
 advice:4:3
-advice:6:3
-advice:7:3
+advice:5:3
+advice:8:3
+advice:9:3
 ~~~~~~~~~~
 <?php
 final class Foo {
   public function bar() {}
   public function baz() {}
+  public abstract function a();
+  private static function b() {}
 
   public $x;
   public static $y;