From 6525a309c29fa4339b9f3c10b2b99c72368cf7c1 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 13 Apr 2015 07:27:20 +1000 Subject: [PATCH] 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 --- src/lint/linter/ArcanistXHPASTLinter.php | 23 +++++++++++++++++++ .../__tests__/xhpast/keyword-casing.lint-test | 5 ++++ 2 files changed, 28 insertions(+) diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 984690ce..927df241 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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) { diff --git a/src/lint/linter/__tests__/xhpast/keyword-casing.lint-test b/src/lint/linter/__tests__/xhpast/keyword-casing.lint-test index a3454b6e..e813ec40 100644 --- a/src/lint/linter/__tests__/xhpast/keyword-casing.lint-test +++ b/src/lint/linter/__tests__/xhpast/keyword-casing.lint-test @@ -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 ~~~~~~~~~~