Bug 1303725 - Make mach eslint output more helpful in case of an error. r?miker
MozReview-Commit-ID: KvTrBfnPjtn
--- a/tools/lint/eslint.lint
+++ b/tools/lint/eslint.lint
@@ -13,16 +13,21 @@ import subprocess
import sys
from distutils.version import LooseVersion
import which
from mozprocess import ProcessHandler
from mozlint import result
+ESLINT_ERROR_MESSAGE = """
+An error occurred running eslint. Please check the following error messages:
+
+{}
+""".strip()
ESLINT_NOT_FOUND_MESSAGE = """
Could not find eslint! We looked at the --binary option, at the ESLINT
environment variable, and then at your local node_modules path. Please Install
eslint and needed plugins with:
mach eslint --setup
@@ -320,18 +325,24 @@ def lint(paths, binary=None, fix=None, s
signal.signal(signal.SIGINT, orig)
try:
proc.wait()
except KeyboardInterrupt:
proc.kill()
return []
+ try:
+ jsonresult = json.loads(proc.output[0] or '[]')
+ except ValueError:
+ print(ESLINT_ERROR_MESSAGE.format("\n".join(proc.output)))
+ return 1
+
results = []
- for obj in json.loads(proc.output[0] or '[]'):
+ for obj in jsonresult:
errors = obj['messages']
for err in errors:
err.update({
'hint': err.get('fix'),
'level': 'error' if err['severity'] == 2 else 'warning',
'lineno': err.get('line'),
'path': obj['filePath'],