Bug 1379151 - Add --fix and --edit to mozlint, r=standard8
While --fix previously worked with eslint, it is now more official (will show up in the |mach lint --help|). ESlint is still the only thing that implements it, but we can implement it for flake8 using the `autopep8` module. --edit is a new concept that will open an editor for each failing file to let you fix the errors manually. For now it is very naive (just opens the file), and is only really useful if you have an editor integration for the linter(s). But in the future I'd like to have editor-specific implementations for this. For example, with vim, we can use -q to pass in an error file that will start the editor pre-populated with a list of all errors that can then be easily jumped to. Other editors may just open up to the line containing the error. --fix and --edit can be used in conjunction with one another. Doing that means only errors that can't be fixed automatically will show up in your editor. MozReview-Commit-ID: 5JJJhMIrMIB
This commit is contained in:
55
python/mozlint/test/test_cli.py
Normal file
55
python/mozlint/test/test_cli.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from mozlint import cli
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return cli.MozlintParser()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run(parser, lintdir, files):
|
||||
if lintdir not in cli.SEARCH_PATHS:
|
||||
cli.SEARCH_PATHS.append(lintdir)
|
||||
|
||||
def inner(args=None):
|
||||
args = args or []
|
||||
args.extend(files)
|
||||
lintargs = vars(parser.parse_args(args))
|
||||
lintargs['root'] = here
|
||||
return cli.run(**lintargs)
|
||||
return inner
|
||||
|
||||
|
||||
def test_cli_run_with_fix(run, capfd):
|
||||
ret = run(['-f', 'json', '--fix', '--linter', 'external'])
|
||||
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'
|
||||
|
||||
del os.environ['EDITOR']
|
||||
with pytest.raises(SystemExit):
|
||||
parser.parse_args(['--edit'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(pytest.main(['--verbose', __file__]))
|
||||
Reference in New Issue
Block a user