diff --git a/tools/lint/mach_commands.py b/tools/lint/mach_commands.py index c644e5ab6376..7869928a7714 100644 --- a/tools/lint/mach_commands.py +++ b/tools/lint/mach_commands.py @@ -18,8 +18,16 @@ from mach.decorators import ( Command, ) +try: + from os import scandir +except ImportError: + from scandir import scandir + here = os.path.abspath(os.path.dirname(__file__)) +GLOBAL_EXCLUDES = [ + 'tools/lint/test/files', +] def setup_argument_parser(): @@ -27,6 +35,13 @@ def setup_argument_parser(): return cli.MozlintParser() +def get_global_excludes(topsrcdir): + excludes = GLOBAL_EXCLUDES[:] + excludes.extend([e.name for e in scandir(topsrcdir) + if e.name.startswith('obj') and e.is_dir()]) + return excludes + + @CommandProvider class MachCommands(MachCommandBase): @@ -36,11 +51,12 @@ class MachCommands(MachCommandBase): parser=setup_argument_parser) def lint(self, *runargs, **lintargs): """Run linters.""" - from mozlint import cli - lintargs.setdefault('root', self.topsrcdir) - lintargs['exclude'] = ['obj*', 'tools/lint/test/files'] - cli.SEARCH_PATHS.append(here) self._activate_virtualenv() + from mozlint import cli + + lintargs.setdefault('root', self.topsrcdir) + lintargs['exclude'] = get_global_excludes(lintargs['root']) + cli.SEARCH_PATHS.append(here) return cli.run(*runargs, **lintargs) @Command('eslint', category='devenv',