2222
2323MYPY = False
2424if MYPY :
25- from typing import List , Union
25+ from typing import List , Union # noqa: F401
2626
2727
2828logger = logging .getLogger ('SublimeLinter.plugin.eslint' )
3737 '@angular-eslint/eslint-plugin' : 'text.html' ,
3838 '@typescript-eslint/parser' : 'source.ts, source.tsx' ,
3939 'tsdx' : 'source.ts, source.tsx' ,
40+ 'eslint-plugin-yml' : 'source.yaml' ,
41+ 'eslint-plugin-yaml' : 'source.yaml' ,
4042}
4143OPTIMISTIC_SELECTOR = ', ' .join ({STANDARD_SELECTOR } | set (PLUGINS .values ()))
4244
45+ BUFFER_FILE_STEM = '__buffer__'
46+ BUFFER_FILE_EXTENSIONS = {
47+ 'source.js' : 'js' ,
48+ 'source.jsx' : 'jsx' ,
49+ 'text.html' : 'html' ,
50+ 'text.html.vue' : 'vue' ,
51+ 'source.ts' : 'ts' ,
52+ 'source.tsx' : 'tsx' ,
53+ 'source.json' : 'json' ,
54+ 'source.yaml' : 'yaml' ,
55+ }
56+
4357
4458class ESLint (NodeLinter ):
4559 """Provides an interface to the eslint executable."""
@@ -53,7 +67,6 @@ class ESLint(NodeLinter):
5367 line_col_base = (1 , 1 )
5468 defaults = {
5569 'selector' : OPTIMISTIC_SELECTOR ,
56- '--stdin-filename' : '${file}' ,
5770 'prefer_eslint_d' : True ,
5871 }
5972
@@ -64,6 +77,11 @@ def run(self, cmd, code):
6477 code = ' '
6578
6679 self .ensure_plugin_installed ()
80+
81+ stdin_filename = self .get_stdin_filename ()
82+ if stdin_filename :
83+ cmd .append ('--stdin-filename={}' .format (stdin_filename ))
84+
6785 return super ().run (cmd , code )
6886
6987 def ensure_plugin_installed (self ) -> bool :
@@ -120,6 +138,15 @@ def ensure_plugin_installed(self) -> bool:
120138 self .notify_unassign () # Abort linting without popping error dialog
121139 raise PermanentError ()
122140
141+ def get_stdin_filename (self ) -> str :
142+ filename = self .view .file_name ()
143+ if filename is None :
144+ for selector in BUFFER_FILE_EXTENSIONS .keys ():
145+ if self .view .match_selector (0 , selector ):
146+ filename = '.' .join ([BUFFER_FILE_STEM , BUFFER_FILE_EXTENSIONS [selector ]])
147+ break
148+ return filename
149+
123150 def find_local_executable (self , start_dir , npm_name ):
124151 # type: (str, str) -> Union[None, str, List[str]]
125152 """Automatically switch to `eslint_d` if available (and wanted)."""
@@ -177,6 +204,8 @@ def find_errors(self, output):
177204 filename = entry .get ('filePath' , None )
178205 if filename == '<text>' :
179206 filename = 'stdin'
207+ elif filename .split ('/' )[- 1 ].split ('.' )[0 ] == BUFFER_FILE_STEM :
208+ filename = 'stdin'
180209
181210 for match in entry ['messages' ]:
182211 if match ['message' ].startswith ('File ignored' ):
0 commit comments