diff --git a/linter.py b/linter.py index f13135e..59f3cd2 100644 --- a/linter.py +++ b/linter.py @@ -13,7 +13,7 @@ import json import logging import re -from SublimeLinter.lint import NodeLinter +from SublimeLinter.lint import NodeLinter, LintMatch logger = logging.getLogger('SublimeLinter.plugin.eslint') @@ -22,8 +22,7 @@ class ESLint(NodeLinter): """Provides an interface to the eslint executable.""" - npm_name = 'eslint' - cmd = 'eslint --format json --stdin --stdin-filename ${file}' + cmd = 'eslint --format json --stdin' missing_config_regex = re.compile( r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)', @@ -31,7 +30,8 @@ class ESLint(NodeLinter): ) line_col_base = (1, 1) defaults = { - 'selector': 'source.js - meta.attribute-with-value' + 'selector': 'source.js - meta.attribute-with-value', + '--stdin-filename': '${file}' } def on_stderr(self, stderr): @@ -73,24 +73,27 @@ def find_errors(self, output): '{} output:\n{}'.format(self.name, pprint.pformat(content))) for entry in content: + filename = entry.get('filePath', None) + if filename == '': + filename = 'stdin' + for match in entry['messages']: if match['message'].startswith('File ignored'): continue column = match.get('column', None) - ruleId = match.get('ruleId', '') if column is not None: # apply line_col_base manually column = column - 1 - yield ( - match, - match['line'] - 1, # apply line_col_base manually - column, - ruleId if match['severity'] == 2 else '', - ruleId if match['severity'] == 1 else '', - match['message'], - None # near + yield LintMatch( + match=match, + filename=filename, + line=match['line'] - 1, # apply line_col_base manually + col=column, + error_type='error' if match['severity'] == 2 else 'warning', + code=match.get('ruleId', ''), + message=match['message'], ) def reposition_match(self, line, col, m, vv):