diff options
author | w0rp <devw0rp@gmail.com> | 2017-07-16 23:35:10 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-07-16 23:35:10 +0100 |
commit | fe70742bb930a196b08180da9b251e141d95707c (patch) | |
tree | db14111b7707cdd1014da9c75260c123850ed975 | |
parent | 9e8387890044726538a7b5f108efdf6a82d59b00 (diff) | |
download | ale-fe70742bb930a196b08180da9b251e141d95707c.zip |
#711 - Make the clangcheck executable configurable
-rw-r--r-- | ale_linters/cpp/clangcheck.vim | 32 | ||||
-rw-r--r-- | doc/ale-cpp.txt | 8 | ||||
-rw-r--r-- | test/command_callback/test_cpp_clangcheck_command_callbacks.vader | 54 |
3 files changed, 77 insertions, 17 deletions
diff --git a/ale_linters/cpp/clangcheck.vim b/ale_linters/cpp/clangcheck.vim index 11184cb8..936204d8 100644 --- a/ale_linters/cpp/clangcheck.vim +++ b/ale_linters/cpp/clangcheck.vim @@ -1,36 +1,34 @@ " Author: gagbo <gagbobada@gmail.com> " Description: clang-check linter for cpp files -" Set this option to manually set some options for clang-check. -let g:ale_cpp_clangcheck_options = get(g:, 'ale_cpp_clangcheck_options', '') +call ale#Set('cpp_clangcheck_executable', 'clang-check') +call ale#Set('cpp_clangcheck_options', '') +call ale#Set('c_build_dir', '') -" Set this option to manually point to the build directory for clang-tidy. -" This will disable all the other clangtidy_options, since compilation -" flags are contained in the json -let g:ale_c_build_dir = get(g:, 'ale_c_build_dir', '') +function! ale_linters#cpp#clangcheck#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'cpp_clangcheck_executable') +endfunction function! ale_linters#cpp#clangcheck#GetCommand(buffer) abort let l:user_options = ale#Var(a:buffer, 'cpp_clangcheck_options') - let l:extra_options = !empty(l:user_options) - \ ? l:user_options - \ : '' " Try to find compilation database to link automatically - let l:user_build_dir = ale#Var(a:buffer, 'c_build_dir') - if empty(l:user_build_dir) - let l:user_build_dir = ale#c#FindCompileCommands(a:buffer) + let l:build_dir = ale#Var(a:buffer, 'c_build_dir') + + if empty(l:build_dir) + let l:build_dir = ale#c#FindCompileCommands(a:buffer) endif - let l:build_options = !empty(l:user_build_dir) - \ ? ' -p ' . ale#Escape(l:user_build_dir) - \ : '' - return 'clang-check -analyze ' . '%s' . l:extra_options . l:build_options + return ale#Escape(ale_linters#cpp#clangcheck#GetExecutable(a:buffer)) + \ . ' -analyze %s' + \ . (!empty(l:user_options) ? ' ' . l:user_options : '') + \ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '') endfunction call ale#linter#Define('cpp', { \ 'name': 'clangcheck', \ 'output_stream': 'stderr', -\ 'executable': 'clang-check', +\ 'executable_callback': 'ale_linters#cpp#clangcheck#GetExecutable', \ 'command_callback': 'ale_linters#cpp#clangcheck#GetCommand', \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'lint_file': 1, diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index b84b5e2e..74833394 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -63,6 +63,14 @@ Therefore, `clang-check` linter reads the options |g:ale_c_build_dir| and overrides |g:ale_c_build_dir_names|. +g:ale_cpp_clangcheck_executable *g:ale_cpp_clangcheck_executable* + *b:ale_cpp_clangcheck_executable* + Type: |String| + Default: `'clang-check'` + + This variable can be changed to use a different executable for clangcheck. + + g:ale_cpp_clangcheck_options *g:ale_cpp_clangcheck_options* *b:ale_cpp_clangcheck_options* Type: |String| diff --git a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader new file mode 100644 index 00000000..e51ba3d2 --- /dev/null +++ b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader @@ -0,0 +1,54 @@ +Before: + Save g:ale_cpp_clangcheck_executable + Save g:ale_cpp_clangcheck_options + + unlet! g:ale_cpp_clangcheck_executable + unlet! b:ale_cpp_clangcheck_executable + unlet! g:ale_cpp_clangcheck_options + unlet! b:ale_cpp_clangcheck_options + + runtime ale_linters/cpp/clangcheck.vim + +After: + Restore + unlet! b:command_tail + unlet! b:ale_cpp_clangcheck_executable + unlet! b:ale_cpp_clangcheck_options + unlet! b:ale_c_build_dir + call ale#linter#Reset() + +Execute(The executable should be configurable): + AssertEqual 'clang-check', ale_linters#cpp#clangcheck#GetExecutable(bufnr('')) + + let b:ale_cpp_clangcheck_executable = 'foobar' + + AssertEqual 'foobar', ale_linters#cpp#clangcheck#GetExecutable(bufnr('')) + +Execute(The executable should be used in the command): + AssertEqual + \ ale#Escape('clang-check') . ' -analyze %s', + \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) + + let b:ale_cpp_clangcheck_executable = 'foobar' + + AssertEqual + \ ale#Escape('foobar') . ' -analyze %s', + \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) + +Execute(The options should be configurable): + let b:ale_cpp_clangcheck_options = '--something' + + AssertEqual + \ ale#Escape('clang-check') . ' -analyze %s --something', + \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) + +Execute(The build directory should be used when set): + let b:ale_cpp_clangcheck_options = '--something' + let b:ale_c_build_dir = '/foo/bar' + + AssertEqual + \ ale#Escape('clang-check') + \ . ' -analyze %s ' + \ . '--something -p ' + \ . ale#Escape('/foo/bar'), + \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) |