Bug 1387555 - [mozlint] After using --edit, run lint check again, r?dylan draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 09 Aug 2017 10:02:23 -0400
changeset 645013 28edb0a33c8db39328cdad2c7ff76e3050bd79f4
parent 644996 2261de3ebaaa934e43f4e12835e114ec0c8fec5c
child 645014 92d726d2065a1cea322486af965ed10fb6406ab9
push id73629
push userahalberstadt@mozilla.com
push dateFri, 11 Aug 2017 18:50:20 +0000
reviewersdylan
bugs1387555
milestone57.0a1
Bug 1387555 - [mozlint] After using --edit, run lint check again, r?dylan MozReview-Commit-ID: BlJbWVv1CeO
python/mozlint/mozlint/cli.py
python/mozlint/test/test_cli.py
--- a/python/mozlint/mozlint/cli.py
+++ b/python/mozlint/mozlint/cli.py
@@ -106,16 +106,21 @@ class MozlintParser(ArgumentParser):
 
         self.validate(args)
         return args, extra
 
     def validate(self, args):
         if args.edit and not os.environ.get('EDITOR'):
             self.error("must set the $EDITOR environment variable to use --edit")
 
+        if args.paths:
+            invalid = [p for p in args.paths if not os.path.exists(p)]
+            if invalid:
+                self.error("the following paths do not exist:\n{}".format("\n".join(invalid)))
+
 
 def find_linters(linters=None):
     lints = []
     for search_path in SEARCH_PATHS:
         if not os.path.isdir(search_path):
             continue
 
         sys.path.insert(0, search_path)
@@ -139,33 +144,28 @@ def run(paths, linters, fmt, outgoing, w
     from mozlint import LintRoller, formatters
 
     if list_linters:
         lint_paths = find_linters(linters)
         print("Available linters: {}".format(
             [os.path.splitext(os.path.basename(l))[0] for l in lint_paths]
         ))
         return 0
+
     lint = LintRoller(**lintargs)
     lint.read(find_linters(linters))
 
-    # Check if the path that is entered is a valid one.
-    invalid_paths = [path for path in paths if not os.path.exists(path)]
-    if invalid_paths:
-        print("Error: The following paths do not exist:\n{}".format("\n".join(invalid_paths)))
-        return 1
-
     # run all linters
     results = lint.roll(paths, outgoing=outgoing, workdir=workdir)
 
     if edit:
         editor = os.environ['EDITOR']
         for path in results:
             subprocess.call([editor, path])
-        return 1 if lint.failed else 0
+        results = lint.roll(results.keys())
 
     formatter = formatters.get(fmt)
 
     # Encode output with 'replace' to avoid UnicodeEncodeErrors on
     # environments that aren't using utf-8.
     out = formatter(results, failed=lint.failed).encode(
                     sys.stdout.encoding or 'ascii', 'replace')
     if out:
--- a/python/mozlint/test/test_cli.py
+++ b/python/mozlint/test/test_cli.py
@@ -36,20 +36,24 @@ def test_cli_run_with_fix(run, capfd):
     out, err = capfd.readouterr()
     assert ret == 0
     assert out.endswith('{}\n')
 
 
 def test_cli_run_with_edit(run, parser, capfd):
     os.environ['EDITOR'] = 'echo'
 
-    ret = run(['-f', 'json', '--edit', '--linter', 'external'])
-    out = capfd.readouterr()[0].strip()
-    assert ret == 0
-    assert os.path.basename(out) == 'foobar.js'
+    ret = run(['-f', 'compact', '--edit', '--linter', 'external'])
+    out, err = capfd.readouterr()
+    out = out.splitlines()
+    assert ret == 1
+    assert len(out) == 5
+    assert out[0].endswith('foobar.js')  # from the `echo` editor
+    assert "files/foobar.js: line 1, col 1, Error" in out[1]
+    assert "files/foobar.js: line 2, col 1, Error" in out[2]
 
     del os.environ['EDITOR']
     with pytest.raises(SystemExit):
         parser.parse_args(['--edit'])
 
 
 if __name__ == '__main__':
     sys.exit(pytest.main(['--verbose', __file__]))