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+ }
4356
4457class ESLint (NodeLinter ):
4558 """Provides an interface to the eslint executable."""
@@ -53,7 +66,6 @@ class ESLint(NodeLinter):
5366 line_col_base = (1 , 1 )
5467 defaults = {
5568 'selector' : OPTIMISTIC_SELECTOR ,
56- '--stdin-filename' : '${file}' ,
5769 'prefer_eslint_d' : True ,
5870 }
5971
@@ -64,6 +76,11 @@ def run(self, cmd, code):
6476 code = ' '
6577
6678 self .ensure_plugin_installed ()
79+
80+ stdin_filename = self .get_stdin_filename ();
81+ if stdin_filename :
82+ cmd .append ('--stdin-filename={}' .format (stdin_filename ))
83+
6784 return super ().run (cmd , code )
6885
6986 def ensure_plugin_installed (self ) -> bool :
@@ -120,6 +137,15 @@ def ensure_plugin_installed(self) -> bool:
120137 self .notify_unassign () # Abort linting without popping error dialog
121138 raise PermanentError ()
122139
140+ def get_stdin_filename (self ) -> str :
141+ filename = self .view .file_name ()
142+ if filename == None :
143+ for selector in BUFFER_FILE_EXTENSIONS .keys ():
144+ if self .view .match_selector (0 , selector ):
145+ filename = '.' .join ([BUFFER_FILE_STEM , BUFFER_FILE_EXTENSIONS [selector ]])
146+ break
147+ return filename ;
148+
123149 def find_local_executable (self , start_dir , npm_name ):
124150 # type: (str, str) -> Union[None, str, List[str]]
125151 """Automatically switch to `eslint_d` if available (and wanted)."""
@@ -177,6 +203,8 @@ def find_errors(self, output):
177203 filename = entry .get ('filePath' , None )
178204 if filename == '<text>' :
179205 filename = 'stdin'
206+ elif filename .split ('/' )[- 1 ].split ('.' )[0 ] == BUFFER_FILE_STEM :
207+ filename = 'stdin'
180208
181209 for match in entry ['messages' ]:
182210 if match ['message' ].startswith ('File ignored' ):
0 commit comments