--- a/tools/lint/mach_commands.py
+++ b/tools/lint/mach_commands.py
@@ -81,18 +81,20 @@ class MachCommands(MachCommandBase):
@Command('eslint', category='devenv',
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('-e', '--ext', default='[.js,.jsm,.jsx,.xml,.html]',
help='Filename extensions to lint, default: "[.js,.jsm,.jsx,.xml,.html]".')
@CommandArgument('-b', '--binary', default=None,
help='Path to eslint binary.')
+ @CommandArgument('--fix', default=False, action='store_true',
+ help='Request that eslint automatically fix errors, where possible.')
@CommandArgument('args', nargs=argparse.REMAINDER) # Passed through to eslint.
- def eslint(self, setup, ext=None, binary=None, args=None):
+ def eslint(self, setup, ext=None, binary=None, fix=False, args=None):
'''Run eslint.'''
module_path = self.get_eslint_module_path()
# eslint requires at least node 4.2.3
nodePath = self.get_node_or_npm_path("node", LooseVersion("4.2.3"))
if not nodePath:
return 1
@@ -143,16 +145,20 @@ class MachCommands(MachCommandBase):
# Enable the HTML plugin.
# We can't currently enable this in the global config file
# because it has bad interactions with the SublimeText
# ESLint plugin (bug 1229874).
'--plugin', 'html',
'--ext', ext, # This keeps ext as a single argument.
] + args
+ # eslint requires that --fix be set before the --ext argument.
+ if fix:
+ cmd_args.insert(1, '--fix')
+
success = self.run_process(
cmd_args,
pass_thru=True, # Allow user to run eslint interactively.
ensure_exit_code=False, # Don't throw on non-zero exit code.
require_unix_environment=True # eslint is not a valid Win32 binary.
)
self.log(logging.INFO, 'eslint', {'msg': ('No errors' if success == 0 else 'Errors')},