Skip to content

Commit 4c1a0e5

Browse files
authored
Merge pull request #274 from SublimeLinter/use-lintmatch
Use new `LintMatch`
2 parents e24d764 + 4f71a7a commit 4c1a0e5

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

linter.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import json
1414
import logging
1515
import re
16-
from SublimeLinter.lint import NodeLinter
16+
from SublimeLinter.lint import NodeLinter, LintMatch
1717

1818

1919
logger = logging.getLogger('SublimeLinter.plugin.eslint')
@@ -22,16 +22,16 @@
2222
class ESLint(NodeLinter):
2323
"""Provides an interface to the eslint executable."""
2424

25-
npm_name = 'eslint'
26-
cmd = 'eslint --format json --stdin --stdin-filename ${file}'
25+
cmd = 'eslint --format json --stdin'
2726

2827
missing_config_regex = re.compile(
2928
r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)',
3029
re.DOTALL
3130
)
3231
line_col_base = (1, 1)
3332
defaults = {
34-
'selector': 'source.js - meta.attribute-with-value'
33+
'selector': 'source.js - meta.attribute-with-value',
34+
'--stdin-filename': '${file}'
3535
}
3636

3737
def on_stderr(self, stderr):
@@ -73,24 +73,27 @@ def find_errors(self, output):
7373
'{} output:\n{}'.format(self.name, pprint.pformat(content)))
7474

7575
for entry in content:
76+
filename = entry.get('filePath', None)
77+
if filename == '<text>':
78+
filename = 'stdin'
79+
7680
for match in entry['messages']:
7781
if match['message'].startswith('File ignored'):
7882
continue
7983

8084
column = match.get('column', None)
81-
ruleId = match.get('ruleId', '')
8285
if column is not None:
8386
# apply line_col_base manually
8487
column = column - 1
8588

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'],
9497
)
9598

9699
def reposition_match(self, line, col, m, vv):

0 commit comments

Comments
 (0)