Bug 1291910 - Add ability for mach eslint to accept --fix. r=felipe draft
authorJared Wein <jwein@mozilla.com>
Wed, 03 Aug 2016 19:18:55 -0400
changeset 396505 b42035bd2218a932cfcbbc6a6358cb687779f89a
parent 396494 69b0f784a9a21369d3aba9c467c953dce81b1e59
child 396567 430c61ccf80a10f6dd69a4fe427411931aece71e
push id25025
push userjwein@mozilla.com
push dateWed, 03 Aug 2016 23:19:12 +0000
reviewersfelipe
bugs1291910
milestone51.0a1
Bug 1291910 - Add ability for mach eslint to accept --fix. r=felipe MozReview-Commit-ID: 5PB2oI2jPri
tools/lint/mach_commands.py
--- 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')},