Bug 1608535 - [lint] Forward new --no-error-on-unmatched-pattern to eslint, r=Standard8
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 23 Jan 2020 13:30:27 +0000
changeset 573988 2fbc8cd3c4f59d4ba1b31f34f7883d3453e67f18
parent 573987 332ffb5bdfba7acccc2c8353d75930d648d5d9ed
child 573989 d32ebb2508c08af7323d0f4f60baf5299fb109f8
push id12662
push userffxbld-merge
push dateMon, 10 Feb 2020 10:43:10 +0000
treeherdermozilla-beta@ace4081e8200 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1608535
milestone74.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 1608535 - [lint] Forward new --no-error-on-unmatched-pattern to eslint, r=Standard8 This prevents eslint from dumping an error and bailing when a path was specified that doesn't contain any lintable files. This patch fixes a bad interaction with 'mozlint' where passing a directory containing failures alongside a directory that doesn't have lintable files results in the errors being hidden and mozlint reporting that everying is OK. Differential Revision: https://phabricator.services.mozilla.com/D60686
tools/lint/eslint/__init__.py
tools/lint/test/test_eslint.py
--- a/tools/lint/eslint/__init__.py
+++ b/tools/lint/eslint/__init__.py
@@ -3,17 +3,16 @@
 # 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 absolute_import, print_function
 
 import json
 import os
-import re
 import signal
 import sys
 
 sys.path.append(os.path.join(os.path.dirname(__file__), "eslint"))
 from eslint import setup_helper
 
 from mozbuild.nodeutil import find_node_executable
 
@@ -70,16 +69,17 @@ def lint(paths, config, binary=None, fix
     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"),
                 # This keeps ext as a single argument.
                 '--ext', '[{}]'.format(','.join(config['extensions'])),
                 '--format', 'json',
+                '--no-error-on-unmatched-pattern',
                 ] + extra_args + exclude_args + paths
     log.debug("Command: {}".format(' '.join(cmd_args)))
 
     # eslint requires that --fix be set before the --ext argument.
     if fix:
         cmd_args.insert(2, '--fix')
 
     shell = False
@@ -101,20 +101,16 @@ def lint(paths, config, binary=None, fix
 
     if not proc.output:
         return []  # no output means success
 
     try:
         jsonresult = json.loads(proc.output[0])
     except ValueError:
         output = "\n".join(proc.output)
-        if re.search(r'No files matching the pattern "(.*)" were found.', output):
-            print("warning: no files to lint (eslint)")
-            return []
-
         print(ESLINT_ERROR_MESSAGE.format(output))
         return 1
 
     results = []
     for obj in jsonresult:
         errors = obj['messages']
 
         for err in errors:
--- a/tools/lint/test/test_eslint.py
+++ b/tools/lint/test/test_eslint.py
@@ -7,14 +7,19 @@ 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
 
 
 def test_no_files_to_lint(lint, config, paths):
-    ret = lint(paths('nolint'), root=build.topsrcdir)
-    assert ret == []
+    # A directory with no files to lint.
+    results = lint(paths('nolint'), root=build.topsrcdir)
+    assert results == []
+
+    # Errors still show up even when a directory with no files is passed in.
+    results = lint(paths('nolint', 'subdir/bad.js'), root=build.topsrcdir)
+    assert len(results) == 1
 
 
 if __name__ == '__main__':
     mozunit.main()