2222
2323MYPY = False
2424if MYPY :
25- from typing import List , Union # noqa: F401
25+ from typing import List , Union
2626
2727
2828logger = logging .getLogger ('SublimeLinter.plugin.eslint' )
5858class ESLint (NodeLinter ):
5959 """Provides an interface to the eslint executable."""
6060
61- cmd = 'eslint --format json --stdin'
62-
6361 missing_config_regex = re .compile (
6462 r'^(.*?)\r?\n\w*(ESLint couldn\'t find a configuration file.)' ,
6563 re .DOTALL
@@ -70,18 +68,20 @@ class ESLint(NodeLinter):
7068 'prefer_eslint_d' : True ,
7169 }
7270
71+ def cmd (self ):
72+ cmd = ['eslint' , '--format=json' , '--stdin' ]
73+ stdin_filename = self .get_stdin_filename ()
74+ if stdin_filename :
75+ cmd .append ('--stdin-filename=' + stdin_filename )
76+ return cmd
77+
7378 def run (self , cmd , code ):
7479 # Workaround eslint bug https://github.com/eslint/eslint/issues/9515
7580 # Fixed in eslint 4.10.0
7681 if code == '' :
7782 code = ' '
7883
7984 self .ensure_plugin_installed ()
80-
81- stdin_filename = self .get_stdin_filename ()
82- if stdin_filename :
83- cmd .append ('--stdin-filename=' + stdin_filename )
84-
8585 return super ().run (cmd , code )
8686
8787 def ensure_plugin_installed (self ) -> bool :
@@ -138,11 +138,12 @@ def ensure_plugin_installed(self) -> bool:
138138 self .notify_unassign () # Abort linting without popping error dialog
139139 raise PermanentError ()
140140
141- def get_stdin_filename (self ) -> str :
141+ def get_stdin_filename (self ) -> str | None :
142142 filename = self .view .file_name ()
143143 if filename is None :
144+ view_selectors = set (self .view .scope_name (0 ).split (' ' ))
144145 for selector in BUFFER_FILE_EXTENSIONS .keys ():
145- if self . view . match_selector ( 0 , selector ) :
146+ if selector in view_selectors :
146147 filename = '.' .join ([BUFFER_FILE_STEM , BUFFER_FILE_EXTENSIONS [selector ]])
147148 break
148149 return filename
@@ -204,7 +205,7 @@ def find_errors(self, output):
204205 filename = entry .get ('filePath' , None )
205206 if filename == '<text>' :
206207 filename = 'stdin'
207- elif filename . split ( os .path .sep )[ - 1 ]. split ( '.' )[ 0 ] == BUFFER_FILE_STEM :
208+ elif filename and os .path .basename ( filename ). startswith ( BUFFER_FILE_STEM + '.' ):
208209 filename = 'stdin'
209210
210211 for match in entry ['messages' ]:
0 commit comments