diff options
-rw-r--r-- | ale_linters/json/jsonlint.vim | 23 | ||||
-rw-r--r-- | doc/ale-json.txt | 16 | ||||
-rw-r--r-- | test/jsonlint-test-files/app-without-jsonlint/src/app.json | 0 | ||||
-rw-r--r-- | test/jsonlint-test-files/app/node_modules/.bin/jsonlint | 0 | ||||
-rw-r--r-- | test/jsonlint-test-files/app/src/app.json | 0 | ||||
-rw-r--r-- | test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js | 0 | ||||
-rw-r--r-- | test/test_jsonlint_executable_detection.vader | 46 |
7 files changed, 81 insertions, 4 deletions
diff --git a/ale_linters/json/jsonlint.vim b/ale_linters/json/jsonlint.vim index f01553d6..f677b488 100644 --- a/ale_linters/json/jsonlint.vim +++ b/ale_linters/json/jsonlint.vim @@ -1,4 +1,21 @@ -" Author: KabbAmine <amine.kabb@gmail.com> +" Author: KabbAmine <amine.kabb@gmail.com>, David Sierra <https://github.com/davidsierradz> + +call ale#Set('json_jsonlint_executable', 'jsonlint') +call ale#Set('json_jsonlint_use_global', get(g:, 'ale_use_global_executables', 0)) + +function! ale_linters#json#jsonlint#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'json_jsonlint', [ + \ 'node_modules/.bin/jsonlint', + \ 'node_modules/jsonlint/lib/cli.js', + \]) +endfunction + +function! ale_linters#json#jsonlint#GetCommand(buffer) abort + let l:executable = ale_linters#json#jsonlint#GetExecutable(a:buffer) + + return ale#node#Executable(a:buffer, l:executable) + \ . ' --compact -' +endfunction function! ale_linters#json#jsonlint#Handle(buffer, lines) abort " Matches patterns like the following: @@ -19,8 +36,8 @@ endfunction call ale#linter#Define('json', { \ 'name': 'jsonlint', -\ 'executable': 'jsonlint', +\ 'executable': function('ale_linters#json#jsonlint#GetExecutable'), \ 'output_stream': 'stderr', -\ 'command': 'jsonlint --compact -', +\ 'command': function('ale_linters#json#jsonlint#GetCommand'), \ 'callback': 'ale_linters#json#jsonlint#Handle', \}) diff --git a/doc/ale-json.txt b/doc/ale-json.txt index 6a0a9fae..96499a04 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -52,7 +52,21 @@ g:ale_json_fixjson_use_global *g:ale_json_fixjson_use_global* =============================================================================== jsonlint *ale-json-jsonlint* -There are no options available. +g:ale_json_jsonlint_executable *g:ale_json_jsonlint_executable* + *b:ale_json_jsonlint_executable* + + Type: |String| + Default: `'jsonlint'` + + The executable that will be run for jsonlint. + +g:ale_json_jsonlint_use_global *g:ale_json_jsonlint_use_global* + *b:ale_json_jsonlint_use_global* + + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| =============================================================================== diff --git a/test/jsonlint-test-files/app-without-jsonlint/src/app.json b/test/jsonlint-test-files/app-without-jsonlint/src/app.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app-without-jsonlint/src/app.json diff --git a/test/jsonlint-test-files/app/node_modules/.bin/jsonlint b/test/jsonlint-test-files/app/node_modules/.bin/jsonlint new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app/node_modules/.bin/jsonlint diff --git a/test/jsonlint-test-files/app/src/app.json b/test/jsonlint-test-files/app/src/app.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app/src/app.json diff --git a/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js b/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js diff --git a/test/test_jsonlint_executable_detection.vader b/test/test_jsonlint_executable_detection.vader new file mode 100644 index 00000000..bd391b47 --- /dev/null +++ b/test/test_jsonlint_executable_detection.vader @@ -0,0 +1,46 @@ +Before: + call ale#test#SetDirectory('/testplugin/test') + + runtime ale_linters/json/jsonlint.vim + +After: + let g:ale_has_override = {} + let g:ale_json_jsonlint_executable = 'jsonlint' + let g:ale_json_jsonlint_use_global = 0 + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(local executable should be detected correctly): + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ ale#path#Simplify(g:dir . '/jsonlint-test-files/app/node_modules/.bin/jsonlint'), + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(recursively executable should be detected correctly): + call ale#test#SetFilename('jsonlint-test-files/app-without-jsonlint/src/app.json') + + AssertEqual + \ ale#path#Simplify(g:dir . '/jsonlint-test-files/node_modules/jsonlint/lib/cli.js'), + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(use_global should override project executable): + let g:ale_json_jsonlint_use_global = 1 + + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ 'jsonlint', + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(manually defined should override default executable): + let g:ale_json_jsonlint_use_global = 1 + let g:ale_json_jsonlint_executable = 'custom_jsonlint' + + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ 'custom_jsonlint', + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + |