]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve example linter to not lint deleted paths
authorNick Harper <nharper@fb.com>
Wed, 23 May 2012 21:53:37 +0000 (14:53 -0700)
committerNick Harper <nharper@fb.com>
Wed, 23 May 2012 21:59:31 +0000 (14:59 -0700)
Summary:
It's easy to forget to do this when writing a new lint engine (like I recently
just did), so I added it to the example to improve documentation on how to write
a lint engine. This code is copied from PhutilLintEngine (as well as many
others).

Test Plan: php -l

Reviewers: jungejason, vrana, epriestley

Reviewed By: epriestley

CC: aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2553

src/lint/engine/example/ExampleLintEngine.php

index b6106d7949c8b4f4fd86f51ec8c517c73b4061c1..128ddec659d8de501f1f5cad6945990883aa1f0a 100644 (file)
@@ -40,6 +40,16 @@ final class ExampleLintEngine extends ArcanistLintEngine {
     // and raising warnings and errors.
     $pylint_linter = new ArcanistPyLintLinter();
 
+    // Remove any paths that don't exist before we add paths to linters. We want
+    // to do this for linters that operate on file contents because the
+    // generated list of paths will include deleted paths when a file is
+    // removed.
+    foreach ($paths as $key => $path) {
+      if (!$this->pathExists($path)) {
+        unset($paths[$key]);
+      }
+    }
+
     foreach ($paths as $path) {
       if (!preg_match('/\.py$/', $path)) {
         // This isn't a python file, so don't try to apply the PyLint linter