Bug 1509391 - [eslint] Ignore excluded files that mozlint wasn't able to handle automatically r=Standard8
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 28 Nov 2018 15:16:19 +0000
changeset 507744 a823c2262dbf17325c965a6fdc66f0366de2e249
parent 507743 164213f935e1dfc919dd0f1fbb78cc7cdea98679
child 507745 6c8636acf2cd7b775380d18cce1542a8117a3bc0
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1509391
milestone65.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 1509391 - [eslint] Ignore excluded files that mozlint wasn't able to handle automatically r=Standard8 Normally eslint handles its own file exclusions, but there are still some globally excluded paths that |mach lint| passes in (e.g objdirs and things in ThirdPartyPaths.txt). This makes sure that if they show up in the 'config', we handle them. Differential Revision: https://phabricator.services.mozilla.com/D12712
tools/lint/eslint/__init__.py
tools/lint/test/files/eslint/good.js
tools/lint/test/files/eslint/subdir/bad.js
tools/lint/test/python.ini
tools/lint/test/test_eslint.py
--- a/tools/lint/eslint/__init__.py
+++ b/tools/lint/eslint/__init__.py
@@ -55,27 +55,31 @@ def lint(paths, config, binary=None, fix
     if not binary:
         binary, _ = find_node_executable()
 
     if not binary:
         print(ESLINT_NOT_FOUND_MESSAGE)
         return 1
 
     extra_args = lintargs.get('extra_args') or []
+    exclude_args = []
+    for path in config.get('exclude', []):
+        exclude_args.extend(['--ignore-pattern', os.path.relpath(path, lintargs['root'])])
+
     cmd_args = [binary,
                 os.path.join(module_path, "node_modules", "eslint", "bin", "eslint.js"),
                 # 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',
                 # This keeps ext as a single argument.
                 '--ext', '[{}]'.format(','.join(config['extensions'])),
                 '--format', 'json',
-                ] + extra_args + paths
+                ] + extra_args + exclude_args + paths
 
     # eslint requires that --fix be set before the --ext argument.
     if fix:
         cmd_args.insert(2, '--fix')
 
     shell = False
     if os.environ.get('MSYSTEM') in ('MINGW32', 'MINGW64'):
         # The eslint binary needs to be run from a shell with msys
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/tools/lint/test/files/eslint/subdir/bad.js
@@ -0,0 +1,2 @@
+// Missing semicolon
+let foo = "bar"
--- a/tools/lint/test/python.ini
+++ b/tools/lint/test/python.ini
@@ -1,5 +1,7 @@
 [DEFAULT]
 subsuite=mozlint, os == "linux"
 skip-if = python == 3
 
+[test_eslint.py]
+skip-if = os == "win"  # node not installed on worker
 [test_flake8.py]
new file mode 100644
--- /dev/null
+++ b/tools/lint/test/test_eslint.py
@@ -0,0 +1,15 @@
+import mozunit
+
+from conftest import build
+
+LINTER = 'eslint'
+
+
+def test_lint_with_global_exclude(lint, config, paths):
+    config['exclude'] = ['subdir']
+    results = lint(paths(), config=config, root=build.topsrcdir)
+    assert len(results) == 0
+
+
+if __name__ == '__main__':
+    mozunit.main()