]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix ArcanistSingleLintEngine for deleted paths
authorepriestley <git@epriestley.com>
Sat, 20 Oct 2012 13:12:24 +0000 (06:12 -0700)
committerepriestley <git@epriestley.com>
Sat, 20 Oct 2012 13:12:24 +0000 (06:12 -0700)
Summary:
Currently, ArcanisSingleLintEngine lints deleted paths and directories. These are sometimes appropriate, but SingleLintEngine is a less-sophisticated linter and should have more safe defaults.

Also fix an error where JSHint reported useless messages on failure.

Test Plan:
Reproduced the problem:

  $ git show
  commit d71efe2b13770c8861bcd3415c15503fc377339f
  Author: epriestley <git@epriestley.com>
  Date:   Fri Oct 19 12:22:50 2012 -0700

      WIP

  diff --git a/test.js b/test.js
  deleted file mode 100644
  index 8bd6648..0000000
  --- a/test.js
  +++ /dev/null
  @@ -1 +0,0 @@
  -asdf
  $ arc set-config --local lint.engine.single.linter ArcanistJSHintLinter
  Set key 'lint.engine.single.linter' = "ArcanistJSHintLinter" in local config (was null).
  $ arc lint --engine ArcanistSingleLintEngine --rev HEAD^
  Usage Exception: JSHint returned output we can't parse. Check that your JSHint installation.
  Output:

Applied the error message fix:

  $ arc lint --engine ArcanistSingleLintEngine --rev HEAD^
  Usage Exception: JSHint returned unparseable output.
  stdout:

  stderr:

  node.js:181
          throw e; // process.nextTick error, or 'error' event on first tick
          ^
  Error: ENOENT, No such file or directory '/INSECURE/repos/git-working-copy/test.js'
      at Object.statSync (fs.js:400:18)
      at _collect (/usr/lib/node_modules/jshint/lib/hint.js:77:12)
      at /usr/lib/node_modules/jshint/lib/hint.js:93:13
      at Array.forEach (native)
      at Object.hint (/usr/lib/node_modules/jshint/lib/hint.js:92:17)
      at Object.interpret (/usr/lib/node_modules/jshint/lib/cli.js:137:21)
      at Object.<anonymous> (/usr/lib/node_modules/jshint/bin/hint:2:25)
      at Module._compile (module.js:420:26)
      at Object..js (module.js:426:10)
      at Module.load (module.js:336:31)

Applied the remove paths fix:

  $ arc lint --engine ArcanistSingleLintEngine --rev HEAD^
  Usage Exception: No paths are lintable.

Reviewers: magazovski, btrahan, vrana

Reviewed By: btrahan

CC: aran, Korvin, vissi
Differential Revision: https://secure.phabricator.com/D3735

src/lint/engine/ArcanistSingleLintEngine.php
src/lint/linter/ArcanistJSHintLinter.php

index 35c4ac382ed091fe1a32b538d66de11f97e4bc74..f133043e7d9281bb397e695ee97a54a170e09c21 100644 (file)
@@ -50,8 +50,28 @@ final class ArcanistSingleLintEngine extends ArcanistLintEngine {
         "ArcanistLinter.");
     }
 
+    // Filter the affected paths.
+    $paths = $this->getPaths();
+    foreach ($paths as $key => $path) {
+      if (!$this->pathExists($path)) {
+        // Don't lint removed files. In more complex linters it is sometimes
+        // appropriate to lint removed files so you can raise a warning like
+        // "you deleted X, but forgot to delete Y!", but most linters do not
+        // operate correctly on removed files.
+        unset($paths[$key]);
+        continue;
+      }
+      $disk = $this->getFilePathOnDisk($path);
+      if (is_dir($disk)) {
+        // Don't lint directories. (In SVN, they can be directly modified by
+        // changing properties on them, and may appear as modified paths.)
+        unset($paths[$key]);
+        continue;
+      }
+    }
+
     $linter = newv($linter_name, array());
-    foreach ($this->getPaths() as $path) {
+    foreach ($paths as $path) {
       $linter->addPath($path);
     }
 
index 06f0fa1c53326e6b0047155bcb8e295c8cd67089..8dfbc52f354f2d3e8e735d932832419456f63230 100644 (file)
@@ -145,7 +145,7 @@ final class ArcanistJSHintLinter extends ArcanistLinter {
   }
 
   public function lintPath($path) {
-    list($rc, $stdout) = $this->results[$path];
+    list($rc, $stdout, $stderr) = $this->results[$path];
 
     if ($rc === 0) {
       return;
@@ -155,9 +155,9 @@ final class ArcanistJSHintLinter extends ArcanistLinter {
     if (!is_array($errors)) {
       // Something went wrong and we can't decode the output. Exit abnormally.
       throw new ArcanistUsageException(
-        "JSHint returned output we can't parse. Check that your JSHint installation.\n".
-        "Output:\n".
-        $stdout);
+        "JSHint returned unparseable output.\n".
+        "stdout:\n\n{$stdout}".
+        "stderr:\n\n{$stderr}");
     }
 
     foreach ($errors as $err) {