]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix some problems with the module linter that would cause various conflicting
authorepriestley <epriestley@javelinjs.com>
Mon, 10 Jan 2011 04:40:13 +0000 (20:40 -0800)
committerepriestley <epriestley@javelinjs.com>
Mon, 10 Jan 2011 04:40:31 +0000 (20:40 -0800)
warnings raised in __init__.php to overwrite eachother in uncomfortable ways.

src/lint/engine/base/ArcanistLintEngine.php
src/lint/linter/base/ArcanistLinter.php
src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php
src/lint/message/ArcanistLintMessage.php
src/lint/patcher/ArcanistLintPatcher.php
src/lint/renderer/ArcanistLintRenderer.php
src/lint/renderer/__init__.php
src/lint/result/ArcanistLintResult.php
src/workflow/base/ArcanistBaseWorkflow.php
src/workflow/lint/ArcanistLintWorkflow.php

index d2dbd56e022efd100ea7cc3549fa347602805a5e..5a199d4b00ab9f3a61b459c8751811034cc4bd20 100644 (file)
@@ -68,7 +68,9 @@ abstract class ArcanistLintEngine {
   }
 
   public function getFilePathOnDisk($path) {
-    return $path;
+    return Filesystem::resolvePath(
+      $path,
+      $this->getWorkingCopy()->getProjectRoot());
   }
 
   public function setMinimumSeverity($severity) {
@@ -145,12 +147,12 @@ abstract class ArcanistLintEngine {
     }
 
     foreach ($this->results as $path => $result) {
+      $result->setFilePathOnDisk($this->getFilePathOnDisk($path));
       if (isset($this->fileData[$path])) {
         // Only set the data if any linter loaded it. The goal here is to
         // avoid binaries when we don't actually care about their contents,
         // for performance.
         $result->setData($this->fileData[$path]);
-        $result->setFilePathOnDisk($this->getFilePathOnDisk($path));
       }
     }
 
index 5f841247ba0e0edd500b0ec780f80523900bb447..55c7c669c40e627d0286cc4da897aaffafd88376 100644 (file)
@@ -156,7 +156,12 @@ abstract class ArcanistLinter {
 
     $path = $this->getActivePath();
     $engine = $this->getEngine();
-    list($line, $char) = $engine->getLineAndCharFromOffset($path, $offset);
+    if ($offset === null) {
+      $line = null;
+      $char = null;
+    } else {
+      list($line, $char) = $engine->getLineAndCharFromOffset($path, $offset);
+    }
 
     return $this->raiseLintAtLine(
       $line + 1,
index bde388bb42ce6cd6a926af95f06babdb864d9db3..709b0fb38569a7fb28f20ef29fc53a9a1fc6a31f 100644 (file)
@@ -136,12 +136,18 @@ class ArcanistPhutilModuleLinter extends ArcanistLinter {
     $bin = dirname($arc_root).'/scripts/phutil_analyzer.php';
 
     $futures = array();
-    foreach ($modules as $key) {
+    foreach ($modules as $mkey => $key) {
       $disk_path = $this->getModulePathOnDisk($key);
-      $futures[$key] = new ExecFuture(
-        '%s %s',
-        $bin,
-        $disk_path);
+      if (Filesystem::pathExists($disk_path)) {
+        $futures[$key] = new ExecFuture(
+          '%s %s',
+          $bin,
+          $disk_path);
+      } else {
+        // This can occur in git when you add a module in HEAD and then remove
+        // it in unstaged changes in the working copy. Just ignore it.
+        unset($modules[$mkey]);
+      }
     }
 
     $requirements = array();
@@ -340,19 +346,26 @@ class ArcanistPhutilModuleLinter extends ArcanistLinter {
         $need_functions,
         $drop_modules);
       $init_path = $this->getModulePathOnDisk($key).'/__init__.php';
-      $init_path = Filesystem::readablePath($init_path);
-      if (file_exists($init_path)) {
+      $try_path = Filesystem::readablePath($init_path);
+      if (Filesystem::pathExists($try_path)) {
+        $init_path = $try_path;
         $old_file = Filesystem::readFile($init_path);
-        $this->willLintPath($init_path);
-        $message = $this->raiseLintAtOffset(
-          0,
-          self::LINT_INIT_REBUILD,
-          "This regenerated phutil '__init__.php' file is suggested to ".
-          "address lint problems with static dependencies in the module.",
-          $old_file,
-          $new_file);
-        $message->setDependentMessages($resolvable);
+      } else {
+        $old_file = '';
+      }
+      $this->willLintPath($init_path);
+      $message = $this->raiseLintAtOffset(
+        null,
+        self::LINT_INIT_REBUILD,
+        "This generated phutil '__init__.php' file is suggested to address ".
+        "lint problems with static dependencies in the module.",
+        $old_file,
+        $new_file);
+      $message->setDependentMessages($resolvable);
+      foreach ($resolvable as $message) {
+        $message->setObsolete(true);
       }
+      $message->setGenerateFile(true);
     }
   }
 
@@ -456,7 +469,9 @@ EOHEADER;
       foreach ($places as $place) {
         list($file, $offset) = explode(':', $place);
         $this->willLintPath(
-          Filesystem::readablePath($this->getModulePathOnDisk($key).'/'.$file));
+          Filesystem::readablePath(
+            $this->getModulePathOnDisk($key).'/'.$file,
+            $this->getEngine()->getWorkingCopy()->getProjectRoot()));
         return $this->raiseLintAtOffset(
           $offset,
           $code,
index fd938786c64039d3781c3f0b38556a9e6276956f..6a8e1495a57c0e3e589722e899d925e5bc6abe5e 100644 (file)
@@ -28,7 +28,9 @@ class ArcanistLintMessage {
   protected $originalText;
   protected $replacementText;
   protected $appliedToDisk;
+  protected $generateFile;
   protected $dependentMessages = array();
+  protected $obsolete;
 
   public static function newFromDictionary(array $dict) {
     $message = new ArcanistLintMessage();
@@ -142,6 +144,24 @@ class ArcanistLintMessage {
     return ($this->getLine() !== null);
   }
 
+  public function setGenerateFile($generate_file) {
+    $this->generateFile = $generate_file;
+    return $this;
+  }
+
+  public function getGenerateFile() {
+    return $this->generateFile;
+  }
+
+  public function setObsolete($obsolete) {
+    $this->obsolete = $obsolete;
+    return $this;
+  }
+
+  public function getObsolete() {
+    return $this->obsolete;
+  }
+
   public function isPatchable() {
     return ($this->getReplacementText() !== null);
   }
index a2ab8825321a83a1db75e330f28ea7b2a9dfaa77..e8289845efd63c86b58d811504bd41a125ef40da 100644 (file)
@@ -53,7 +53,10 @@ final class ArcanistLintPatcher {
 
     // Copy existing file to preserve permissions. 'chmod --reference' is not
     // supported under OSX.
-    execx('cp -p %s %s', $path, $lint);
+    if (Filesystem::pathExists($path)) {
+      // This path may not exist if we're generating a new file.
+      execx('cp -p %s %s', $path, $lint);
+    }
     Filesystem::writeFile($lint, $data);
 
     list($err) = exec_manual("mv -f %s %s", $lint, $path);
index 8f74f5d2ef7c22c9da92a1ae29e152549362c805..12510377ab3b4afcacfd4d69ca98024610d0cb4e 100644 (file)
@@ -115,7 +115,8 @@ class ArcanistLintRenderer {
 
     for (; $cursor < $line_num + $text_length; $cursor++) {
       $chevron = ($cursor == $line_num);
-      $data = $line_data[$cursor - 1];
+      // We may not have any data if, e.g., the old file does not exist.
+      $data = idx($line_data, $cursor - 1, null);
 
       // Highlight the problem substring.
       $text_line = $text_lines[$cursor - $line_num];
index c89f46b86f6f525abf604eb570f43debf792943b..e8872d7cf110e0ae155ba7ae1e32b097bcaf08f8 100644 (file)
@@ -9,6 +9,7 @@
 phutil_require_module('arcanist', 'lint/severity');
 
 phutil_require_module('phutil', 'console');
+phutil_require_module('phutil', 'utils');
 
 
 phutil_require_source('ArcanistLintRenderer.php');
index 5eb25ead625e7e7cf2379f79abc481d6d331f8a1..d33dee4222c6d22c6d6a2ef067041b204f0c8052 100644 (file)
@@ -22,6 +22,7 @@ final class ArcanistLintResult {
   protected $data;
   protected $filePathOnDisk;
   protected $messages = array();
+  protected $effectiveMessages = array();
   private $needsSort;
 
   public function setPath($path) {
@@ -41,9 +42,9 @@ final class ArcanistLintResult {
 
   public function getMessages() {
     if ($this->needsSort) {
-      $this->sortMessages();
+      $this->sortAndFilterMessages();
     }
-    return $this->messages;
+    return $this->effectiveMessages;
   }
 
   public function setData($data) {
@@ -73,18 +74,32 @@ final class ArcanistLintResult {
     return false;
   }
 
-  private function sortMessages() {
+  private function sortAndFilterMessages() {
     $messages = $this->messages;
+
+    foreach ($messages as $key => $message) {
+      if ($message->getObsolete()) {
+        unset($messages[$key]);
+        continue;
+      }
+      if ($message->getGenerateFile()) {
+        $messages = array(
+          $key => $message,
+        );
+        break;
+      }
+    }
+
     $map = array();
     foreach ($messages as $key => $message) {
       $map[$key] = ($message->getLine() * (2 << 12)) + $message->getChar();
     }
     asort($map);
     $messages = array_select_keys($messages, array_keys($map));
-    $this->messages = $messages;
+
+    $this->effectiveMessages = $messages;
     $this->needsSort = false;
 
-    return $this;
   }
 
 }
index daf6c64745ab5c2707ffa06a731fdaf52e18278b..54bd74f7561d6af563c0e1b9a1740c9c7dd1ff47 100644 (file)
@@ -478,12 +478,17 @@ class ArcanistBaseWorkflow {
     }
 
     if (empty($this->changeCache[$path])) {
-      // TODO: This can legitimately occur under git if you make a change,
-      // "git commit" it, and then revert the change in the working copy and
-      // run "arc lint". We should probably just make a dummy, empty changeset
-      // in this case, at least under git.
-      throw new Exception(
-        "Trying to get change for unchanged path '{$path}'!");
+      if ($repository_api instanceof ArcanistGitAPI) {
+        // This can legitimately occur under git if you make a change, "git
+        // commit" it, and then revert the change in the working copy and run
+        // "arc lint".
+        $change = new ArcanistDiffChange();
+        $change->setCurrentPath($path);
+        return $change;
+      } else {
+        throw new Exception(
+          "Trying to get change for unchanged path '{$path}'!");
+      }
     }
 
     return $this->changeCache[$path];
index dc7c93015e78d8334efbb802232cee706000643c..e32d3426ee760dce1296be26779558742636067a 100644 (file)
@@ -168,6 +168,9 @@ EOTEXT
 
         if ($prompt_patches) {
           $old_file = $result->getFilePathOnDisk();
+          if (!Filesystem::pathExists($old_file)) {
+            $old_file = '/dev/null';
+          }
           $new_file = new TempFile();
           Filesystem::writeFile($new_file, $new);
 
@@ -193,7 +196,7 @@ EOTEXT
         "Amend HEAD with lint patches?",
         $default_no = false);
       if (!$amend) {
-        throw new ArcanistUsageException("Resolve lint changes and rediff.");
+        throw new ArcanistUsageException("Resolve lint changes and relint.");
       }
       execx(
         '(cd %s; git commit -a --amend -C HEAD)',