зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1387555 - [mozlint] After using --edit, run lint check again, r=dylan
MozReview-Commit-ID: BlJbWVv1CeO --HG-- extra : rebase_source : 18720a32c8ea562af1602ce4c32e46173c0ca4fb
This commit is contained in:
Родитель
e415614486
Коммит
81abb80919
|
@ -111,6 +111,11 @@ class MozlintParser(ArgumentParser):
|
|||
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 = []
|
||||
|
@ -144,15 +149,10 @@ def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **linta
|
|||
[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)
|
||||
|
||||
|
@ -160,7 +160,7 @@ def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **linta
|
|||
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)
|
||||
|
||||
|
|
|
@ -41,10 +41,14 @@ def test_cli_run_with_fix(run, capfd):
|
|||
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):
|
||||
|
|
Загрузка…
Ссылка в новой задаче