1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-10 23:01:04 +01:00

Improvements to LINT_IMPLICIT_VISIBILITY

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
This commit is contained in:
Joshua Spence 2015-01-08 07:30:31 +11:00
parent 2ad2c04774
commit a232f7d5b8
2 changed files with 30 additions and 9 deletions

View file

@ -3004,20 +3004,36 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
private function lintMethodModifier(XHPASTNode $root) { private function lintMethodModifier(XHPASTNode $root) {
static $visibilities = array(
'public',
'protected',
'private',
);
$methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION'); $methods = $root->selectDescendantsOfType('n_METHOD_DECLARATION');
foreach ($methods as $method) { foreach ($methods as $method) {
$modifier_list = $method->getChildOfType( $modifiers_list = $method->getChildOfType(
0, 0,
'n_METHOD_MODIFIER_LIST'); 'n_METHOD_MODIFIER_LIST');
if (!$modifier_list->getChildren()) { foreach ($modifiers_list->getChildren() as $modifier) {
$this->raiseLintAtNode( if (in_array($modifier->getConcreteString(), $visibilities)) {
$method, continue 2;
self::LINT_IMPLICIT_VISIBILITY, }
pht('Methods should have their visibility declared explicitly.'),
'public '.$method->getConcreteString());
} }
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());
} }
} }

View file

@ -2,6 +2,8 @@
final class Foo { final class Foo {
public function bar() {} public function bar() {}
function baz() {} function baz() {}
abstract function a();
private static function b() {}
var $x; var $x;
static $y; static $y;
@ -10,13 +12,16 @@ final class Foo {
~~~~~~~~~~ ~~~~~~~~~~
error:2:13 XHP19 error:2:13 XHP19
advice:4:3 advice:4:3
advice:6:3 advice:5:3
advice:7:3 advice:8:3
advice:9:3
~~~~~~~~~~ ~~~~~~~~~~
<?php <?php
final class Foo { final class Foo {
public function bar() {} public function bar() {}
public function baz() {} public function baz() {}
public abstract function a();
private static function b() {}
public $x; public $x;
public static $y; public static $y;