]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Further improvements to keyword casing linter rule
authorJoshua Spence <josh@joshuaspence.com>
Sun, 12 Apr 2015 21:27:20 +0000 (07:27 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Sun, 12 Apr 2015 21:27:20 +0000 (07:27 +1000)
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
src/lint/linter/__tests__/xhpast/keyword-casing.lint-test

index 984690ce259e7211f31e032186d6068d05b0a019..927df2414db97a9d4923c89d72630b17e4c86e99 100644 (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) {
index a3454b6e8b120084c186fe1a8bc0731a577be92d..e813ec408fcf7df6753e43f6b22423d4281f2736 100644 (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__;