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
}
}
}
+
+ $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) {
new C();
NeW C();
+
+echo __file__;
~~~~~~~~~~
warning:6:1
warning:7:1
warning:11:1
warning:13:22
warning:16:1
+warning:18:6
~~~~~~~~~~
<?php
new C();
new C();
+
+echo __FILE__;