diff options
author | w0rp <devw0rp@gmail.com> | 2018-03-26 09:55:18 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2018-03-26 09:55:18 +0100 |
commit | 8b34a4bf6b837e1ce7e060b053ec8abedd20cdb1 (patch) | |
tree | e7c52160edf51308d968ce3dcccfded3229a1bc2 | |
parent | 45c5fe7f43d85513943202e620f9a751cfc534fc (diff) | |
download | ale-8b34a4bf6b837e1ce7e060b053ec8abedd20cdb1.zip |
Fix config and executable issues with the textlint linter
5 files changed, 95 insertions, 11 deletions
diff --git a/autoload/ale/handlers/textlint.vim b/autoload/ale/handlers/textlint.vim index 80f68e10..c06daa01 100644 --- a/autoload/ale/handlers/textlint.vim +++ b/autoload/ale/handlers/textlint.vim @@ -13,23 +13,16 @@ function! ale#handlers#textlint#GetExecutable(buffer) abort endfunction function! ale#handlers#textlint#GetCommand(buffer) abort - let l:cmd_path = ale#path#FindNearestFile(a:buffer, '.textlintrc') + let l:executable = ale#handlers#textlint#GetExecutable(a:buffer) + let l:config = ale#path#FindNearestFile(a:buffer, '.textlintrc') let l:options = ale#Var(a:buffer, 'textlint_options') - if !empty(l:cmd_path) - return 'textlint' - \ . ' -c ' - \ . l:cmd_path - \ . (!empty(l:options) ? ' ' . l:options : '') - \ . ' -f json %t' - endif - - return 'textlint' + return ale#node#Executable(a:buffer, l:executable) \ . (!empty(l:options) ? ' ' . l:options : '') + \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '') \ . ' -f json %t' endfunction - function! ale#handlers#textlint#HandleTextlintOutput(buffer, lines) abort let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {'messages': []}) let l:output = [] diff --git a/test/command_callback/test_textlint_command_callbacks.vader b/test/command_callback/test_textlint_command_callbacks.vader new file mode 100644 index 00000000..864ad8f7 --- /dev/null +++ b/test/command_callback/test_textlint_command_callbacks.vader @@ -0,0 +1,91 @@ +" Author: januswel, w0rp + +Before: + Save g:ale_textlint_executable + Save g:ale_textlint_use_global + Save g:ale_textlint_options + + unlet! g:ale_textlint_executable + unlet! b:ale_textlint_executable + unlet! g:ale_textlint_use_global + unlet! b:ale_textlint_use_global + unlet! g:ale_textlint_options + unlet! b:ale_textlint_options + + runtime autoload/ale/handlers/textlint.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + +After: + Restore + + unlet! b:command_tail + unlet! b:ale_textlint_executable + unlet! b:ale_textlint_use_global + unlet! b:ale_textlint_options + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The executable should be configurable): + AssertEqual 'textlint', ale#handlers#textlint#GetExecutable(bufnr('')) + + let b:ale_textlint_executable = 'foobar' + + AssertEqual 'foobar', ale#handlers#textlint#GetExecutable(bufnr('')) + +Execute(The executable should be used in the command): + AssertEqual + \ ale#Escape('textlint') . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + + let b:ale_textlint_executable = 'foobar' + + AssertEqual + \ ale#Escape('foobar') . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + \ + +Execute(The options should be configurable): + let b:ale_textlint_options = '--something' + + AssertEqual + \ ale#Escape('textlint') . ' --something -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + +Execute(The local executable from .bin should be used if available): + call ale#test#SetFilename('textlint_paths/with_bin_path/foo.txt') + + AssertEqual + \ ale#path#Simplify(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint'), + \ ale#handlers#textlint#GetExecutable(bufnr('')) + + AssertEqual + \ ale#Escape(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint') . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + +Execute(The local executable from textlint/bin should be used if available): + call ale#test#SetFilename('textlint_paths/with_textlint_bin_path/foo.txt') + + AssertEqual + \ ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'), + \ ale#handlers#textlint#GetExecutable(bufnr('')) + + if has('win32') + AssertEqual + \ ale#Escape('node.exe') . ' ' . ale#Escape(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js') . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + else + AssertEqual + \ ale#Escape(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js') . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) + endif + +Execute(Configuration files should be discovered): + call ale#test#SetFilename('textlint_paths/with_config_path/foo.txt') + + AssertEqual + \ ale#Escape('textlint') + \ . ' -c ' . ale#Escape(g:dir . '/textlint_paths/with_config_path/.textlintrc') + \ . ' -f json %t', + \ ale#handlers#textlint#GetCommand(bufnr('')) diff --git a/test/command_callback/textlint_paths/with_bin_path/node_modules/.bin/textlint b/test/command_callback/textlint_paths/with_bin_path/node_modules/.bin/textlint new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/textlint_paths/with_bin_path/node_modules/.bin/textlint diff --git a/test/command_callback/textlint_paths/with_config_path/.textlintrc b/test/command_callback/textlint_paths/with_config_path/.textlintrc new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/textlint_paths/with_config_path/.textlintrc diff --git a/test/command_callback/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js b/test/command_callback/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js |