1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-22 21:40:54 +01:00

Further improvements to keyword casing linter rule

Summary: Ref T7409. Improve the `ArcanistXHPASTLinter::LINT_KEYWORD_CASING` linter rule to check that magic constants are uppercase.

Test Plan: Added unit test.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T7409

Differential Revision: https://secure.phabricator.com/D12368
This commit is contained in:
Joshua Spence 2015-04-13 07:27:20 +10:00
parent 515e98f1d2
commit 6525a309c2
2 changed files with 28 additions and 0 deletions

View file

@ -2806,6 +2806,29 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
}
}
}
$magic_constants = $root->selectTokensOfTypes(array(
'T_CLASS_C',
'T_METHOD_C',
'T_FUNC_C',
'T_LINE',
'T_FILE',
'T_NS_C',
'T_DIR',
'T_TRAIT_C',
));
foreach ($magic_constants as $magic_constant) {
$value = $magic_constant->getValue();
if ($value != strtoupper($value)) {
$this->raiseLintAtToken(
$magic_constant,
self::LINT_KEYWORD_CASING,
pht('Magic constants should be uppercase.'),
strtoupper($value));
}
}
}
private function lintStrings(XHPASTNode $root) {

View file

@ -14,6 +14,8 @@ function f(array $x, ArRaY $y) {}
new C();
NeW C();
echo __file__;
~~~~~~~~~~
warning:6:1
warning:7:1
@ -22,6 +24,7 @@ warning:9:1
warning:11:1
warning:13:22
warning:16:1
warning:18:6
~~~~~~~~~~
<?php
@ -39,3 +42,5 @@ function f(array $x, array $y) {}
new C();
new C();
echo __FILE__;