Bug 1277641 - [mozlint] Add --no-filter option to make experimenting locally easier, r=smacleod
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 02 Jun 2016 15:14:07 -0400
changeset 341611 259c39227fd6e1ccbc244b39bb6c02136c614cee
parent 341610 5c27bbcba434adef226370f2ffbb3281cfa0f3cd
child 341612 22f34da350173fda29c5048974e6d99e2db028e6
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod
bugs1277641
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -76,16 +76,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)