mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Backed out changeset d24be9fbef98 (bug 1379151) for breaking Windows builds. r=backout on a CLOSED TREE
This commit is contained in:
parent
307402b003
commit
aedd2b0e08
@ -5,12 +5,9 @@
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from argparse import REMAINDER, ArgumentParser
|
||||
|
||||
from mozlint.formatters import all_formatters
|
||||
|
||||
SEARCH_PATHS = []
|
||||
|
||||
|
||||
@ -39,7 +36,6 @@ class MozlintParser(ArgumentParser):
|
||||
[['-f', '--format'],
|
||||
{'dest': 'fmt',
|
||||
'default': 'stylish',
|
||||
'choices': all_formatters.keys(),
|
||||
'help': "Formatter to use. Defaults to 'stylish'.",
|
||||
}],
|
||||
[['-n', '--no-filter'],
|
||||
@ -67,18 +63,6 @@ class MozlintParser(ArgumentParser):
|
||||
"can be used to only consider staged files. Works with "
|
||||
"mercurial or git.",
|
||||
}],
|
||||
[['--fix'],
|
||||
{'action': 'store_true',
|
||||
'default': False,
|
||||
'help': "Fix lint errors if possible. Any errors that could not be fixed "
|
||||
"will be printed as normal."
|
||||
}],
|
||||
[['--edit'],
|
||||
{'action': 'store_true',
|
||||
'default': False,
|
||||
'help': "Each file containing lint errors will be opened in $EDITOR one after "
|
||||
"the other."
|
||||
}],
|
||||
[['extra_args'],
|
||||
{'nargs': REMAINDER,
|
||||
'help': "Extra arguments that will be forwarded to the underlying linter.",
|
||||
@ -103,14 +87,8 @@ class MozlintParser(ArgumentParser):
|
||||
# when using mach's dispatch functionality.
|
||||
args, extra = ArgumentParser.parse_known_args(self, *args, **kwargs)
|
||||
args.extra_args = extra
|
||||
|
||||
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")
|
||||
|
||||
|
||||
def find_linters(linters=None):
|
||||
lints = []
|
||||
@ -135,7 +113,7 @@ def find_linters(linters=None):
|
||||
return lints
|
||||
|
||||
|
||||
def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **lintargs):
|
||||
def run(paths, linters, fmt, outgoing, workdir, list_linters=None, **lintargs):
|
||||
from mozlint import LintRoller, formatters
|
||||
|
||||
if list_linters:
|
||||
@ -155,13 +133,6 @@ def run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **linta
|
||||
|
||||
# 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
|
||||
|
||||
formatter = formatters.get(fmt)
|
||||
|
||||
# Encode output with 'replace' to avoid UnicodeEncodeErrors on
|
||||
|
@ -11,10 +11,6 @@ def badreturncode(files, config, **lintargs):
|
||||
|
||||
|
||||
def external(files, config, **lintargs):
|
||||
if lintargs.get('fix'):
|
||||
# mimics no results because they got fixed
|
||||
return []
|
||||
|
||||
results = []
|
||||
for path in files:
|
||||
with open(path, 'r') as fh:
|
||||
|
@ -1,7 +1,6 @@
|
||||
[DEFAULT]
|
||||
subsuite = mozlint, os == "linux"
|
||||
|
||||
[test_cli.py]
|
||||
[test_formatters.py]
|
||||
[test_parser.py]
|
||||
[test_roller.py]
|
||||
|
@ -1,55 +0,0 @@
|
||||
# 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, err = capfd.readouterr()
|
||||
assert ret == 0
|
||||
assert out.endswith('foobar.js\n')
|
||||
|
||||
del os.environ['EDITOR']
|
||||
with pytest.raises(SystemExit):
|
||||
parser.parse_args(['--edit'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(pytest.main(['--verbose', __file__]))
|
Loading…
Reference in New Issue
Block a user