mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Improvements to "self member reference" linter rule
Summary: Ref T7409. A few fixes and improvements to `ArcanistXHPASTLinter::LINT_SELF_MEMBER_REFERENCE`. Test Plan: Added test cases. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7409 Differential Revision: https://secure.phabricator.com/D12385
This commit is contained in:
parent
2bab09df38
commit
c011f948d3
2 changed files with 34 additions and 19 deletions
|
@ -3407,14 +3407,16 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
|
||||
$class_static_accesses = $class_declaration
|
||||
->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
|
||||
$self_member_references = array();
|
||||
|
||||
foreach ($class_static_accesses as $class_static_access) {
|
||||
$double_colons = $class_static_access
|
||||
$double_colons = $class_static_access
|
||||
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
|
||||
$class_ref = $class_static_access
|
||||
->getChildOfType(0, 'n_CLASS_NAME');
|
||||
$class_ref_name = $class_ref->getConcreteString();
|
||||
$class_ref = $class_static_access->getChildByIndex(0);
|
||||
|
||||
if ($class_ref->getTypeName() != 'n_CLASS_NAME') {
|
||||
continue;
|
||||
}
|
||||
$class_ref_name = $class_ref->getConcreteString();
|
||||
|
||||
if (strtolower($class_name) == strtolower($class_ref_name)) {
|
||||
$this->raiseLintAtNode(
|
||||
|
@ -3441,20 +3443,23 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
pht('PHP keywords should be lowercase.'),
|
||||
strtolower($class_ref_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($double_colons as $double_colon) {
|
||||
$tokens = $double_colon->getNonsemanticTokensBefore() +
|
||||
$double_colon->getNonsemanticTokensAfter();
|
||||
$double_colons = $root
|
||||
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if ($token->isAnyWhitespace()) {
|
||||
$this->raiseLintAtToken(
|
||||
$token,
|
||||
self::LINT_SELF_MEMBER_REFERENCE,
|
||||
pht('Unnecessary whitespace around double colon operator.'),
|
||||
'');
|
||||
}
|
||||
}
|
||||
foreach ($double_colons as $double_colon) {
|
||||
$tokens = $double_colon->getNonsemanticTokensBefore() +
|
||||
$double_colon->getNonsemanticTokensAfter();
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if ($token->isAnyWhitespace()) {
|
||||
$this->raiseLintAtToken(
|
||||
$token,
|
||||
self::LINT_SELF_MEMBER_REFERENCE,
|
||||
pht('Unnecessary whitespace around double colon operator.'),
|
||||
'');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,15 @@ class Foo extends Bar {
|
|||
echo Self :: FOOBAR;
|
||||
}
|
||||
|
||||
public function baz() {
|
||||
public function baz(Foo $x) {
|
||||
echo static::FOOBAR;
|
||||
echo Foo::FOOBAR;
|
||||
|
||||
$x::bar();
|
||||
}
|
||||
}
|
||||
|
||||
MyClass :: myMethod();
|
||||
~~~~~~~~~~
|
||||
error:3:7
|
||||
advice:7:5
|
||||
|
@ -24,6 +28,8 @@ advice:12:10
|
|||
advice:12:14
|
||||
advice:12:17
|
||||
advice:17:10
|
||||
advice:23:8
|
||||
advice:23:11
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
|
||||
|
@ -39,8 +45,12 @@ class Foo extends Bar {
|
|||
echo self::FOOBAR;
|
||||
}
|
||||
|
||||
public function baz() {
|
||||
public function baz(Foo $x) {
|
||||
echo static::FOOBAR;
|
||||
echo self::FOOBAR;
|
||||
|
||||
$x::bar();
|
||||
}
|
||||
}
|
||||
|
||||
MyClass::myMethod();
|
||||
|
|
Loading…
Reference in a new issue