]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix two linter issues
authorepriestley <git@epriestley.com>
Tue, 30 Dec 2014 18:02:43 +0000 (10:02 -0800)
committerepriestley <git@epriestley.com>
Tue, 30 Dec 2014 18:02:43 +0000 (10:02 -0800)
Summary:
  - The "exclude static variable access" branch in XHPAST incorrectly excluded all variables in a function or method which used any static access (we were selecting the wrong root node for exclusion).
  - The "PHPLinter" regexp did not work with 5.4.30. Make it more permissive in what it parses.

Test Plan:
  - Added a failing unit test for the variable case and made it pass.
  - PHPLinter tests now pass under 5.4.30

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D11087

src/lint/linter/ArcanistPhpLinter.php
src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/naming-conventions.lint-test

index 7daf75532be382989b7f90b9580879c826c6f6a6..e4851e83cedb956d6358279c88cab4dc864fbb15 100644 (file)
@@ -63,8 +63,8 @@ final class ArcanistPhpLinter extends ArcanistExternalLinter {
     // Combine $stdout and $stderr for consistency
     $stdout = $stderr."\n".$stdout;
     $matches = array();
-    $regex = '/PHP (?<type>.+?) error:\s+(?<error>.*?)\s+in\s+(?<file>.*?)'.
-      '\s+on line\s+(?<line>\d*)/';
+    $regex = '/^(?<type>.+?) error:\s+(?<error>.*?)\s+in\s+(?<file>.*?)'.
+      '\s+on line\s+(?<line>\d*)$/m';
     if (preg_match($regex, $stdout, $matches)) {
       $type = strtolower($matches['type']);
       $message = new ArcanistLintMessage();
index 74682cc706e6c1d4a0bf140c4871322d41585fc7..b43edad6344a6d18c59a88183717b342b32b1d96 100644 (file)
@@ -1902,9 +1902,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
       $statics = $def->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
       foreach ($statics as $static) {
         $rhs = $static->getChildByIndex(1);
-        $rhs_vars = $def->selectDescendantsOfType('n_VARIABLE');
-        foreach ($rhs_vars as $var) {
-          $exclude_tokens[$var->getID()] = true;
+        if ($rhs->getTypeName() == 'n_VARIABLE') {
+          $exclude_tokens[$rhs->getID()] = true;
+        } else {
+          $rhs_vars = $rhs->selectDescendantsOfType('n_VARIABLE');
+          foreach ($rhs_vars as $var) {
+            $exclude_tokens[$var->getID()] = true;
+          }
         }
       }
 
index 892d6e362b9d57e31f1a7935c2d231c96b56395c..cc78e403ebc82ce7ad8ed8947a77ac678d801075 100644 (file)
@@ -48,6 +48,13 @@ function i() {
   Other::$Y_y[0];
   parent::$Z_z[0];
 }
+
+function j() {
+  // Test case for bug where any static access would shadow other variables.
+  Other::$y = 0;
+  $mIxEdCaSe = 1;
+}
+
 ~~~~~~~~~~
 warning:2:13
 warning:3:9
@@ -65,3 +72,4 @@ warning:29:3
 warning:30:3
 warning:31:3
 warning:33:3
+warning:55:3