Bug 1258341 - [mozlint] Add ability to forward miscellaneous command line arguments to the underlying linter, r?smacleod
This is mostly to maintain backwards compatibility with the |mach eslint| command. But it's also going to be used in
automation. The 'mozlint-eslint' task will need to pass in --quiet to eslint.
Maybe in the future we should remove this ability and only allow well-defined arguments in mozlint. But for now it's
convenient and allows us to land the eslint->mozlint patch series quicker.
MozReview-Commit-ID: KYhC6SEySC3
--- a/python/mozlint/mozlint/cli.py
+++ b/python/mozlint/mozlint/cli.py
@@ -1,17 +1,17 @@
# 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/.
from __future__ import print_function, unicode_literals
import os
import sys
-from argparse import ArgumentParser
+from argparse import ArgumentParser, REMAINDER
SEARCH_PATHS = []
class MozlintParser(ArgumentParser):
arguments = [
[['paths'],
@@ -47,24 +47,35 @@ class MozlintParser(ArgumentParser):
"mercurial or git."
}],
[['-w', '--workdir'],
{'default': False,
'action': 'store_true',
'help': "Lint files touched by changes in the working directory "
"(i.e haven't been committed yet). Works with mercurial or git.",
}],
+ [['extra_args'],
+ {'nargs': REMAINDER,
+ 'help': "Extra arguments that will be forwarded to the underlying linter.",
+ }],
]
def __init__(self, **kwargs):
ArgumentParser.__init__(self, usage=self.__doc__, **kwargs)
for cli, args in self.arguments:
self.add_argument(*cli, **args)
+ def parse_known_args(self, *args, **kwargs):
+ # This is here so the eslint mach command doesn't lose 'extra_args'
+ # when using mach's dispatch functionality.
+ args, extra = ArgumentParser.parse_known_args(self, *args, **kwargs)
+ args.extra_args = extra
+ return args, extra
+
def find_linters(linters=None):
lints = []
for search_path in SEARCH_PATHS:
if not os.path.isdir(search_path):
continue
files = os.listdir(search_path)