Bug 1230300: Fix mach eslint to pass command arguments through to eslint. r=gps

Currently mach treats the first argument to eslint as the path and moves it to
the end of the arguments but this breaks usage like "mach eslint -f json browser".

It used to be necessary to change to the directory you wanted to lint but now
the .eslintignore is at the top level we just run from the top level. This means
the path argument doesn't need to be special anymore.

--HG--
extra : commitid : 5ozct0pVSC4
extra : rebase_source : 22132a240d8e6f4d099dbcdeb793958d7173e154
extra : amend_source : 2b9931b4283e1c84f699027e13eccc33fcdec978
This commit is contained in:
Dave Townsend 2015-12-03 10:38:29 -08:00
Родитель e966ac1914
Коммит 9ee8a4af74
1 изменённых файлов: 5 добавлений и 20 удалений

Просмотреть файл

@ -168,16 +168,12 @@ class MachCommands(MachCommandBase):
description='Run eslint or help configure eslint for optimal development.')
@CommandArgument('-s', '--setup', default=False, action='store_true',
help='configure eslint for optimal development.')
@CommandArgument('path', nargs='?', default='.',
help='Path to files to lint, like "browser/components/loop" '
'or "mobile/android". '
'Defaults to the current directory if not given.')
@CommandArgument('-e', '--ext', default='[.js,.jsm,.jsx,.xml]',
help='Filename extensions to lint, default: "[.js,.jsm,.jsx,.xml]".')
help='Filename extensions to lint, default: "[.js,.jsm,.jsx]".')
@CommandArgument('-b', '--binary', default=None,
help='Path to eslint binary.')
@CommandArgument('args', nargs=argparse.REMAINDER) # Passed through to eslint.
def eslint(self, setup, path, ext=None, binary=None, args=[]):
def eslint(self, setup, ext=None, binary=None, args=None):
'''Run eslint.'''
if setup:
@ -195,25 +191,14 @@ class MachCommands(MachCommandBase):
print(ESLINT_NOT_FOUND_MESSAGE)
return 1
# The cwd below is unfortunate. eslint --config=PATH/TO/.eslintrc works,
# but --ignore-path=PATH/TO/.eslintignore treats paths as relative to
# the current directory, rather than as relative to the location of
# .eslintignore (see https://github.com/eslint/eslint/issues/1382).
# mach commands always execute in the topsrcdir, so we could make all
# paths in .eslint relative to the topsrcdir, but it's not clear if
# that's a good choice for future eslint and IDE integrations.
# Unfortunately, running after chdir does not print the full path to
# files (convenient for opening with copy-and-paste). In the meantime,
# we just print the active path.
self.log(logging.INFO, 'eslint', {'binary': binary, 'args': args},
'Running {binary}')
self.log(logging.INFO, 'eslint', {'binary': binary, 'path': path},
'Running {binary} in {path}')
args = args or ['.']
cmd_args = [binary,
'--ext', ext, # This keeps ext as a single argument.
] + args
# Path must come after arguments.
cmd_args += [path]
return self.run_process(cmd_args,
pass_thru=True, # Allow user to run eslint interactively.