summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-26 18:11:27 +0100
committerw0rp <devw0rp@gmail.com>2017-08-26 18:11:27 +0100
commit908e94622ecb3df49a6a16fb3e47227764672be5 (patch)
tree27c0dbf9bd274b892eb7cbec13afa7f9dfea15a7
parentb9cf450684fda2a10dcc65bb09ef11b10469363f (diff)
downloadale-908e94622ecb3df49a6a16fb3e47227764672be5.zip
#868 - Prefer cmd.js files for executing standard
-rw-r--r--ale_linters/javascript/standard.vim16
-rwxr-xr-xtest/command_callback/standard-test-files/with-bin/node_modules/.bin/standard0
-rwxr-xr-xtest/command_callback/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js0
-rw-r--r--test/command_callback/test_standard_command_callback.vader98
4 files changed, 112 insertions, 2 deletions
diff --git a/ale_linters/javascript/standard.vim b/ale_linters/javascript/standard.vim
index 15e6d78f..fc534ebb 100644
--- a/ale_linters/javascript/standard.vim
+++ b/ale_linters/javascript/standard.vim
@@ -7,13 +7,25 @@ call ale#Set('javascript_standard_options', '')
function! ale_linters#javascript#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
+ \ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/.bin/standard',
\])
endfunction
function! ale_linters#javascript#standard#GetCommand(buffer) abort
- return ale#Escape(ale_linters#javascript#standard#GetExecutable(a:buffer))
- \ . ' ' . ale#Var(a:buffer, 'javascript_standard_options')
+ let l:executable = ale_linters#javascript#standard#GetExecutable(a:buffer)
+
+ if ale#Has('win32') && l:executable =~? '\.js$'
+ " .js files have to be executed with Node on Windows.
+ 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_standard_options')
+
+ return l:head
+ \ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin %s'
endfunction
diff --git a/test/command_callback/standard-test-files/with-bin/node_modules/.bin/standard b/test/command_callback/standard-test-files/with-bin/node_modules/.bin/standard
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/standard-test-files/with-bin/node_modules/.bin/standard
diff --git a/test/command_callback/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js b/test/command_callback/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js
diff --git a/test/command_callback/test_standard_command_callback.vader b/test/command_callback/test_standard_command_callback.vader
new file mode 100644
index 00000000..fa90175b
--- /dev/null
+++ b/test/command_callback/test_standard_command_callback.vader
@@ -0,0 +1,98 @@
+Before:
+ Save g:ale_javascript_standard_executable
+ Save g:ale_javascript_standard_use_global
+ Save g:ale_javascript_standard_options
+
+ unlet! b:executable
+ unlet! g:ale_javascript_standard_executable
+ unlet! b:ale_javascript_standard_executable
+ unlet! g:ale_javascript_standard_use_global
+ unlet! g:ale_javascript_standard_options
+
+ call ale#test#SetDirectory('/testplugin/test/command_callback')
+ call ale#test#SetFilename('testfile.js')
+
+ runtime ale_linters/javascript/standard.vim
+
+After:
+ Restore
+
+ unlet! b:executable
+
+ let g:ale_has_override = {}
+
+ call ale#test#SetFilename('test.txt')
+
+ call ale#test#RestoreDirectory()
+ call ale#linter#Reset()
+
+Execute(bin/cmd.js paths should be preferred):
+ call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js')
+
+ let b:executable = g:dir
+ \ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js'
+
+ AssertEqual
+ \ b:executable,
+ \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ ale#Escape(b:executable) . ' --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))
+
+Execute(.bin directories should be used too):
+ call ale#test#SetFilename('standard-test-files/with-bin/testfile.js')
+
+ let b:executable = g:dir
+ \ . '/standard-test-files/with-bin/node_modules/.bin/standard'
+
+ AssertEqual
+ \ b:executable,
+ \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ ale#Escape(b:executable) . ' --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))
+
+Execute(.js files should be executed with node on Windows):
+ let g:ale_has_override['win32'] = 1
+
+ call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js')
+
+ let b:executable = g:dir
+ \ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js'
+
+ AssertEqual
+ \ b:executable,
+ \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ 'node ' . ale#Escape(b:executable) . ' --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))
+
+Execute(The global executable should be used otherwise):
+ AssertEqual
+ \ 'standard',
+ \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ ale#Escape('standard') . ' --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))
+
+Execute(The global executable should be configurable):
+ let b:ale_javascript_standard_executable = 'foobar'
+
+ AssertEqual
+ \ 'foobar',
+ \ ale_linters#javascript#standard#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ ale#Escape('foobar') . ' --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))
+
+Execute(The options should be configurable):
+ let b:ale_javascript_standard_options = '--wat'
+
+ AssertEqual
+ \ ale#Escape('standard') . ' --wat --stdin %s',
+ \ ale_linters#javascript#standard#GetCommand(bufnr(''))