@@ -59,21 +59,30 @@ class ESLint(NodeLinter):
59
59
"""Provides an interface to the eslint executable."""
60
60
61
61
missing_config_regex = re .compile (
62
- r' ^(.*?)\r?\n\w*(ESLint couldn\ 't find a configuration file.)' ,
62
+ r" ^(.*?)\r?\n\w*(ESLint couldn't find a configuration file.)" ,
63
63
re .DOTALL
64
64
)
65
65
line_col_base = (1 , 1 )
66
66
defaults = {
67
67
'selector' : OPTIMISTIC_SELECTOR ,
68
+ '--stdin-filename' : '${file:fallback_filename}' ,
68
69
'prefer_eslint_d' : True ,
69
70
}
70
71
71
72
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 .replace ('$' , '\\ $' ))
76
- return cmd
73
+ if not self .context .get ('file' ):
74
+ fallback_filename = self .compute_fallback_filename ()
75
+ if fallback_filename :
76
+ self .context ['fallback_filename' ] = fallback_filename
77
+ return ['eslint' , '--format=json' , '--stdin' ]
78
+
79
+ def compute_fallback_filename (self ):
80
+ # type: () -> Optional[str]
81
+ view_selectors = set (self .view .scope_name (0 ).split (' ' ))
82
+ for selector in BUFFER_FILE_EXTENSIONS .keys ():
83
+ if selector in view_selectors :
84
+ return '.' .join ([BUFFER_FILE_STEM , BUFFER_FILE_EXTENSIONS [selector ]])
85
+ return None
77
86
78
87
def run (self , cmd , code ):
79
88
# Workaround eslint bug https://github.com/eslint/eslint/issues/9515
@@ -138,17 +147,6 @@ def ensure_plugin_installed(self) -> bool:
138
147
self .notify_unassign () # Abort linting without popping error dialog
139
148
raise PermanentError ()
140
149
141
- def get_stdin_filename (self ):
142
- # type: () -> Optional[str]
143
- filename = self .view .file_name ()
144
- if filename is None :
145
- view_selectors = set (self .view .scope_name (0 ).split (' ' ))
146
- for selector in BUFFER_FILE_EXTENSIONS .keys ():
147
- if selector in view_selectors :
148
- filename = '.' .join ([BUFFER_FILE_STEM , BUFFER_FILE_EXTENSIONS [selector ]])
149
- break
150
- return filename
151
-
152
150
def find_local_executable (self , start_dir , npm_name ):
153
151
# type: (str, str) -> Union[None, str, List[str]]
154
152
"""Automatically switch to `eslint_d` if available (and wanted)."""
0 commit comments