mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 18:22: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
|
$class_static_accesses = $class_declaration
|
||||||
->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
|
->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
|
||||||
$self_member_references = array();
|
|
||||||
|
|
||||||
foreach ($class_static_accesses as $class_static_access) {
|
foreach ($class_static_accesses as $class_static_access) {
|
||||||
$double_colons = $class_static_access
|
$double_colons = $class_static_access
|
||||||
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
|
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
|
||||||
$class_ref = $class_static_access
|
$class_ref = $class_static_access->getChildByIndex(0);
|
||||||
->getChildOfType(0, 'n_CLASS_NAME');
|
|
||||||
$class_ref_name = $class_ref->getConcreteString();
|
if ($class_ref->getTypeName() != 'n_CLASS_NAME') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$class_ref_name = $class_ref->getConcreteString();
|
||||||
|
|
||||||
if (strtolower($class_name) == strtolower($class_ref_name)) {
|
if (strtolower($class_name) == strtolower($class_ref_name)) {
|
||||||
$this->raiseLintAtNode(
|
$this->raiseLintAtNode(
|
||||||
|
@ -3441,20 +3443,23 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
pht('PHP keywords should be lowercase.'),
|
pht('PHP keywords should be lowercase.'),
|
||||||
strtolower($class_ref_name));
|
strtolower($class_ref_name));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($double_colons as $double_colon) {
|
$double_colons = $root
|
||||||
$tokens = $double_colon->getNonsemanticTokensBefore() +
|
->selectTokensOfType('T_PAAMAYIM_NEKUDOTAYIM');
|
||||||
$double_colon->getNonsemanticTokensAfter();
|
|
||||||
|
|
||||||
foreach ($tokens as $token) {
|
foreach ($double_colons as $double_colon) {
|
||||||
if ($token->isAnyWhitespace()) {
|
$tokens = $double_colon->getNonsemanticTokensBefore() +
|
||||||
$this->raiseLintAtToken(
|
$double_colon->getNonsemanticTokensAfter();
|
||||||
$token,
|
|
||||||
self::LINT_SELF_MEMBER_REFERENCE,
|
foreach ($tokens as $token) {
|
||||||
pht('Unnecessary whitespace around double colon operator.'),
|
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;
|
echo Self :: FOOBAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function baz() {
|
public function baz(Foo $x) {
|
||||||
echo static::FOOBAR;
|
echo static::FOOBAR;
|
||||||
echo Foo::FOOBAR;
|
echo Foo::FOOBAR;
|
||||||
|
|
||||||
|
$x::bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MyClass :: myMethod();
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
error:3:7
|
error:3:7
|
||||||
advice:7:5
|
advice:7:5
|
||||||
|
@ -24,6 +28,8 @@ advice:12:10
|
||||||
advice:12:14
|
advice:12:14
|
||||||
advice:12:17
|
advice:12:17
|
||||||
advice:17:10
|
advice:17:10
|
||||||
|
advice:23:8
|
||||||
|
advice:23:11
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -39,8 +45,12 @@ class Foo extends Bar {
|
||||||
echo self::FOOBAR;
|
echo self::FOOBAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function baz() {
|
public function baz(Foo $x) {
|
||||||
echo static::FOOBAR;
|
echo static::FOOBAR;
|
||||||
echo self::FOOBAR;
|
echo self::FOOBAR;
|
||||||
|
|
||||||
|
$x::bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MyClass::myMethod();
|
||||||
|
|
Loading…
Reference in a new issue