Skip to content

Commit

Permalink
Merge pull request #332 from SublimeLinter/do-it-right
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Nov 11, 2023
2 parents 9771add + b8b4d1d commit 2d54479
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,30 @@ class ESLint(NodeLinter):
"""Provides an interface to the eslint executable."""

missing_config_regex = re.compile(
r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)',
r"^(.*?)\r?\n\w*(ESLint couldn't find a configuration file.)",
re.DOTALL
)
line_col_base = (1, 1)
defaults = {
'selector': OPTIMISTIC_SELECTOR,
'--stdin-filename': '${file:fallback_filename}',
'prefer_eslint_d': True,
}

def cmd(self):
cmd = ['eslint', '--format=json', '--stdin']
stdin_filename = self.get_stdin_filename()
if stdin_filename:
cmd.append('--stdin-filename=' + stdin_filename.replace('$', '\\$'))
return cmd
if not self.context.get('file'):
fallback_filename = self.compute_fallback_filename()
if fallback_filename:
self.context['fallback_filename'] = fallback_filename
return ['eslint', '--format=json', '--stdin']

def compute_fallback_filename(self):
# type: () -> Optional[str]
view_selectors = set(self.view.scope_name(0).split(' '))
for selector in BUFFER_FILE_EXTENSIONS.keys():
if selector in view_selectors:
return '.'.join([BUFFER_FILE_STEM, BUFFER_FILE_EXTENSIONS[selector]])
return None

def run(self, cmd, code):
# Workaround eslint bug https://github.com/eslint/eslint/issues/9515
Expand Down Expand Up @@ -138,17 +147,6 @@ def ensure_plugin_installed(self) -> bool:
self.notify_unassign() # Abort linting without popping error dialog
raise PermanentError()

def get_stdin_filename(self):
# type: () -> Optional[str]
filename = self.view.file_name()
if filename is None:
view_selectors = set(self.view.scope_name(0).split(' '))
for selector in BUFFER_FILE_EXTENSIONS.keys():
if selector in view_selectors:
filename = '.'.join([BUFFER_FILE_STEM, BUFFER_FILE_EXTENSIONS[selector]])
break
return filename

def find_local_executable(self, start_dir, npm_name):
# type: (str, str) -> Union[None, str, List[str]]
"""Automatically switch to `eslint_d` if available (and wanted)."""
Expand Down

0 comments on commit 2d54479

Please sign in to comment.