Skip to content

Commit 84d3635

Browse files
authored
Merge pull request #240 from SublimeLinter/nicer-failures
Use `on_stderr` and `notify_failure()`
2 parents e724c43 + 606e83a commit 84d3635

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

linter.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class ESLint(NodeLinter):
2525
npm_name = 'eslint'
2626
cmd = 'eslint --format json --stdin --stdin-filename ${file}'
2727

28+
missing_config_regex = re.compile(
29+
r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)',
30+
re.DOTALL
31+
)
2832
crash_regex = re.compile(
2933
r'^(.*?)\r?\n\w*(Oops! Something went wrong!)',
3034
re.DOTALL
@@ -34,24 +38,24 @@ class ESLint(NodeLinter):
3438
'selector': 'source.js - meta.attribute-with-value'
3539
}
3640

37-
def find_errors(self, output):
38-
"""Parse errors from linter's output.
39-
40-
Log errors when eslint crashes or can't find its configuration.
41-
"""
42-
match = self.crash_regex.match(output)
43-
if match:
44-
logger.error(output)
45-
return
46-
47-
# SL core concats STDOUT and STDERR. The json we're after is
48-
# on STDOUT. `lstrip` here is defensive.
49-
stdout = output.lstrip().splitlines()[0]
41+
def on_stderr(self, stderr):
42+
# Demote 'annoying' config is missing error to a warning.
43+
if self.missing_config_regex.match(stderr):
44+
logger.warning(stderr)
45+
self.notify_failure()
46+
elif 'in the next version' in stderr: # is that a proper deprecation?
47+
logger.warning(stderr)
48+
else:
49+
logger.error(stderr)
50+
self.notify_failure()
5051

52+
def find_errors(self, output):
53+
"""Parse errors from linter's output."""
5154
try:
52-
content = json.loads(stdout)
55+
content = json.loads(output)
5356
except ValueError:
54-
logger.error(output) # still log complete output!
57+
logger.error('{} output:\n{}'.format(self.name, output))
58+
self.notify_failure()
5559
return
5660

5761
if logger.isEnabledFor(logging.INFO):

0 commit comments

Comments
 (0)