|
13 | 13 | import json |
14 | 14 | import logging |
15 | 15 | import re |
16 | | -from SublimeLinter.lint import NodeLinter |
| 16 | +from SublimeLinter.lint import NodeLinter, LintMatch |
17 | 17 |
|
18 | 18 |
|
19 | 19 | logger = logging.getLogger('SublimeLinter.plugin.eslint') |
|
22 | 22 | class ESLint(NodeLinter): |
23 | 23 | """Provides an interface to the eslint executable.""" |
24 | 24 |
|
25 | | - npm_name = 'eslint' |
26 | | - cmd = 'eslint --format json --stdin --stdin-filename ${file}' |
| 25 | + cmd = 'eslint --format json --stdin' |
27 | 26 |
|
28 | 27 | missing_config_regex = re.compile( |
29 | 28 | r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)', |
30 | 29 | re.DOTALL |
31 | 30 | ) |
32 | 31 | line_col_base = (1, 1) |
33 | 32 | defaults = { |
34 | | - 'selector': 'source.js - meta.attribute-with-value' |
| 33 | + 'selector': 'source.js - meta.attribute-with-value', |
| 34 | + '--stdin-filename': '${file}' |
35 | 35 | } |
36 | 36 |
|
37 | 37 | def on_stderr(self, stderr): |
@@ -73,24 +73,27 @@ def find_errors(self, output): |
73 | 73 | '{} output:\n{}'.format(self.name, pprint.pformat(content))) |
74 | 74 |
|
75 | 75 | for entry in content: |
| 76 | + filename = entry.get('filePath', None) |
| 77 | + if filename == '<text>': |
| 78 | + filename = 'stdin' |
| 79 | + |
76 | 80 | for match in entry['messages']: |
77 | 81 | if match['message'].startswith('File ignored'): |
78 | 82 | continue |
79 | 83 |
|
80 | 84 | column = match.get('column', None) |
81 | | - ruleId = match.get('ruleId', '') |
82 | 85 | if column is not None: |
83 | 86 | # apply line_col_base manually |
84 | 87 | column = column - 1 |
85 | 88 |
|
86 | | - yield ( |
87 | | - match, |
88 | | - match['line'] - 1, # apply line_col_base manually |
89 | | - column, |
90 | | - ruleId if match['severity'] == 2 else '', |
91 | | - ruleId if match['severity'] == 1 else '', |
92 | | - match['message'], |
93 | | - None # near |
| 89 | + yield LintMatch( |
| 90 | + match=match, |
| 91 | + filename=filename, |
| 92 | + line=match['line'] - 1, # apply line_col_base manually |
| 93 | + col=column, |
| 94 | + error_type='error' if match['severity'] == 2 else 'warning', |
| 95 | + code=match.get('ruleId', ''), |
| 96 | + message=match['message'], |
94 | 97 | ) |
95 | 98 |
|
96 | 99 | def reposition_match(self, line, col, m, vv): |
|
0 commit comments