summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/javascript/eslint.vim16
-rw-r--r--test/test_eslint_executable_detection.vader12
2 files changed, 26 insertions, 2 deletions
diff --git a/ale_linters/javascript/eslint.vim b/ale_linters/javascript/eslint.vim
index acf17a4d..9f3bdcef 100644
--- a/ale_linters/javascript/eslint.vim
+++ b/ale_linters/javascript/eslint.vim
@@ -5,8 +5,20 @@ let g:ale_javascript_eslint_options =
\ get(g:, 'ale_javascript_eslint_options', '')
function! ale_linters#javascript#eslint#GetCommand(buffer) abort
- return ale#handlers#eslint#GetExecutable(a:buffer)
- \ . ' ' . ale#Var(a:buffer, 'javascript_eslint_options')
+ let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
+
+ if ale#Has('win32') && l:executable =~? 'eslint\.js$'
+ " For Windows, if we detect an eslint.js script, we need to execute
+ " it with node, or the file can be opened with a text editor.
+ let l:head = 'node ' . ale#Escape(l:executable)
+ else
+ let l:head = ale#Escape(l:executable)
+ endif
+
+ let l:options = ale#Var(a:buffer, 'javascript_eslint_options')
+
+ return l:head
+ \ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -f unix --stdin --stdin-filename %s'
endfunction
diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader
index 254150a9..c8c4cc1d 100644
--- a/test/test_eslint_executable_detection.vader
+++ b/test/test_eslint_executable_detection.vader
@@ -7,6 +7,7 @@ Before:
runtime ale_linters/javascript/eslint.vim
After:
+ let g:ale_has_override = {}
let g:ale_javascript_eslint_executable = 'eslint'
let g:ale_javascript_eslint_use_global = 0
@@ -63,3 +64,14 @@ Execute(eslint_d should be detected correctly):
\ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
+
+Execute(eslint.js executables should be run with node on Windows):
+ silent noautocmd new eslint-test-files/react-app/subdir/testfile.js
+ let g:ale_has_override['win32'] = 1
+
+ " We have to execute the file with node.
+ AssertEqual
+ \ 'node '''
+ \ . g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'
+ \ . ''' -f unix --stdin --stdin-filename %s',
+ \ ale_linters#javascript#eslint#GetCommand(bufnr(''))