Bug 1277641 - [mozlint] Add --no-filter option to make experimenting locally easier, r?smacleod draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 02 Jun 2016 15:14:07 -0400
changeset 374678 3521e1e595dd42340222d230843c2c5b6f038cca
parent 374456 92e0c73391e71a400e2c6674bca5ca70804ab081
child 522667 693a5adda10f392ebcb83909aeb7177b1091545b
push id20058
push userahalberstadt@mozilla.com
push dateThu, 02 Jun 2016 19:17:35 +0000
reviewerssmacleod
bugs1277641
milestone49.0a1
Bug 1277641 - [mozlint] Add --no-filter option to make experimenting locally easier, r?smacleod This makes it easier to lint a path that otherwise wouldn't have been linted due to the include/exclude directives. Now, you can pass in -n/--no-filter instead of needing to modify the linter configuration file. MozReview-Commit-ID: GMJuE2C1NyY
python/mozlint/mozlint/types.py
python/mozlint/test/linters/explicit_path.lint
python/mozlint/test/test_types.py
tools/lint/mach_commands.py
--- a/python/mozlint/mozlint/types.py
+++ b/python/mozlint/mozlint/types.py
@@ -23,17 +23,19 @@ class BaseType(object):
         :param linter: Linter definition paths are being linted against.
         :param lintargs: External arguments to the linter not defined in
                          the definition, but passed in by a consumer.
         :returns: A list of :class:`~result.ResultContainer` objects.
         """
         exclude = lintargs.get('exclude', [])
         exclude.extend(linter.get('exclude', []))
 
-        paths, exclude = filterpaths(paths, linter.get('include'), exclude)
+        if lintargs.get('use_filters', True):
+            paths, exclude = filterpaths(paths, linter.get('include'), exclude)
+
         if not paths:
             print("{}: No files to lint for specified paths!".format(linter['name']))
             return
 
         lintargs['exclude'] = exclude
         if self.batch:
             return self._lint(paths, linter, **lintargs)
 
new file mode 100644
--- /dev/null
+++ b/python/mozlint/test/linters/explicit_path.lint
@@ -0,0 +1,13 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+
+LINTER = {
+    'name': "ExplicitPathLinter",
+    'description': "Only lint a specific file name",
+    'rule': 'no-foobar',
+    'include': [
+        'no_foobar.js',
+    ],
+    'type': 'string',
+    'payload': 'foobar',
+}
--- a/python/mozlint/test/test_types.py
+++ b/python/mozlint/test/test_types.py
@@ -59,11 +59,20 @@ class TestLinterTypes(TestCase):
         self.assertIsInstance(result, dict)
         self.assertIn(self.path('foobar.js'), result.keys())
         self.assertNotIn(self.path('no_foobar.js'), result.keys())
 
         result = result[self.path('foobar.js')][0]
         self.assertIsInstance(result, ResultContainer)
         self.assertEqual(result.linter, 'ExternalLinter')
 
+    def test_no_filter(self):
+        self.lint.read(os.path.join(self.lintdir, 'explicit_path.lint'))
+        result = self.lint.roll(self.files)
+        self.assertEqual(len(result), 0)
+
+        self.lint.lintargs['use_filters'] = False
+        result = self.lint.roll(self.files)
+        self.assertEqual(len(result), 1)
+
 
 if __name__ == '__main__':
     main()
--- a/tools/lint/mach_commands.py
+++ b/tools/lint/mach_commands.py
@@ -35,16 +35,21 @@ class MachCommands(MachCommandBase):
              "Defaults to the current directory if not given.")
     @CommandArgument(
         '-l', '--linter', dest='linters', default=None, action='append',
         help="Linters to run, e.g 'eslint'. By default all linters are run "
              "for all the appropriate files.")
     @CommandArgument(
         '-f', '--format', dest='fmt', default='stylish',
         help="Formatter to use. Defaults to 'stylish'.")
+    @CommandArgument(
+        '-n', '--no-filter', dest='use_filters', default=True, action='store_false',
+        help="Ignore all filtering. This is useful for quickly testing a "
+             "directory that otherwise wouldn't be run, without needing to "
+             "modify the config file.")
     def lint(self, paths, linters=None, fmt='stylish', **lintargs):
         """Run linters."""
         from mozlint import LintRoller, formatters
 
         paths = paths or ['.']
 
         lint_files = self.find_linters(linters)