Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -22,16 +22,16 @@
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.)',
re.DOTALL
)
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):
Expand Down Expand Up @@ -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 == '<text>':
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):
Expand Down