#711 - Make the cppcheck executables configurable

This commit is contained in:
w0rp 2017-07-16 22:11:43 +01:00
parent 54ff573174
commit 58717e05a3
7 changed files with 132 additions and 55 deletions

View File

@ -1,8 +1,12 @@
" Author: Bart Libert <bart.libert@gmail.com> " Author: Bart Libert <bart.libert@gmail.com>
" Description: cppcheck linter for c files " Description: cppcheck linter for c files
" Set this option to change the cppcheck options call ale#Set('c_cppcheck_executable', 'cppcheck')
let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style') call ale#Set('c_cppcheck_options', '--enable=style')
function! ale_linters#c#cppcheck#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'c_cppcheck_executable')
endfunction
function! ale_linters#c#cppcheck#GetCommand(buffer) abort function! ale_linters#c#cppcheck#GetCommand(buffer) abort
" Search upwards from the file for compile_commands.json. " Search upwards from the file for compile_commands.json.
@ -19,7 +23,8 @@ function! ale_linters#c#cppcheck#GetCommand(buffer) abort
\ : '' \ : ''
return l:cd_command return l:cd_command
\ . 'cppcheck -q --language=c ' \ . ale#Escape(ale_linters#c#cppcheck#GetExecutable(a:buffer))
\ . ' -q --language=c '
\ . l:compile_commands_option \ . l:compile_commands_option
\ . ale#Var(a:buffer, 'c_cppcheck_options') \ . ale#Var(a:buffer, 'c_cppcheck_options')
\ . ' %t' \ . ' %t'
@ -28,7 +33,7 @@ endfunction
call ale#linter#Define('c', { call ale#linter#Define('c', {
\ 'name': 'cppcheck', \ 'name': 'cppcheck',
\ 'output_stream': 'both', \ 'output_stream': 'both',
\ 'executable': 'cppcheck', \ 'executable_callback': 'ale_linters#c#cppcheck#GetExecutable',
\ 'command_callback': 'ale_linters#c#cppcheck#GetCommand', \ 'command_callback': 'ale_linters#c#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat', \ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\}) \})

View File

@ -1,8 +1,12 @@
" Author: Bart Libert <bart.libert@gmail.com> " Author: Bart Libert <bart.libert@gmail.com>
" Description: cppcheck linter for cpp files " Description: cppcheck linter for cpp files
" Set this option to change the cppcheck options call ale#Set('cpp_cppcheck_executable', 'cppcheck')
let g:ale_cpp_cppcheck_options = get(g:, 'ale_cpp_cppcheck_options', '--enable=style') call ale#Set('cpp_cppcheck_options', '--enable=style')
function! ale_linters#cpp#cppcheck#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'cpp_cppcheck_executable')
endfunction
function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
" Search upwards from the file for compile_commands.json. " Search upwards from the file for compile_commands.json.
@ -19,7 +23,8 @@ function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
\ : '' \ : ''
return l:cd_command return l:cd_command
\ . 'cppcheck -q --language=c++ ' \ . ale#Escape(ale_linters#cpp#cppcheck#GetExecutable(a:buffer))
\ . ' -q --language=c++ '
\ . l:compile_commands_option \ . l:compile_commands_option
\ . ale#Var(a:buffer, 'cpp_cppcheck_options') \ . ale#Var(a:buffer, 'cpp_cppcheck_options')
\ . ' %t' \ . ' %t'
@ -28,7 +33,7 @@ endfunction
call ale#linter#Define('cpp', { call ale#linter#Define('cpp', {
\ 'name': 'cppcheck', \ 'name': 'cppcheck',
\ 'output_stream': 'both', \ 'output_stream': 'both',
\ 'executable': 'cppcheck', \ 'executable_callback': 'ale_linters#cpp#cppcheck#GetExecutable',
\ 'command_callback': 'ale_linters#cpp#cppcheck#GetCommand', \ 'command_callback': 'ale_linters#cpp#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat', \ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\}) \})

View File

@ -24,6 +24,14 @@ g:ale_c_clang_options *g:ale_c_clang_options*
=============================================================================== ===============================================================================
cppcheck *ale-c-cppcheck* cppcheck *ale-c-cppcheck*
g:ale_c_cppcheck_executable *g:ale_c_cppcheck_executable*
*b:ale_c_cppcheck_executable*
Type: |String|
Default: `'cppcheck'`
This variable can be changed to use a different executable for cppcheck.
g:ale_c_cppcheck_options *g:ale_c_cppcheck_options* g:ale_c_cppcheck_options *g:ale_c_cppcheck_options*
*b:ale_c_cppcheck_options* *b:ale_c_cppcheck_options*
Type: |String| Type: |String|

View File

@ -118,6 +118,14 @@ g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
=============================================================================== ===============================================================================
cppcheck *ale-cpp-cppcheck* cppcheck *ale-cpp-cppcheck*
g:ale_cpp_cppcheck_executable *g:ale_cpp_cppcheck_executable*
*b:ale_cpp_cppcheck_executable*
Type: |String|
Default: `'cppcheck'`
This variable can be changed to use a different executable for cppcheck.
g:ale_cpp_cppcheck_options *g:ale_cpp_cppcheck_options* g:ale_cpp_cppcheck_options *g:ale_cpp_cppcheck_options*
*b:ale_cpp_cppcheck_options* *b:ale_cpp_cppcheck_options*
Type: |String| Type: |String|

View File

@ -0,0 +1,49 @@
Before:
Save g:ale_c_cppcheck_executable
Save g:ale_c_cppcheck_options
unlet! g:ale_c_cppcheck_executable
unlet! b:ale_c_cppcheck_executable
unlet! g:ale_c_cppcheck_options
unlet! b:ale_c_cppcheck_options
runtime ale_linters/c/cppcheck.vim
let b:command_tail = ' -q --language=c --enable=style %t'
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
Restore
unlet! b:command_tail
unlet! b:ale_c_cppcheck_executable
unlet! b:ale_c_cppcheck_options
call ale#linter#Reset()
call ale#test#RestoreDirectory()
Execute(The executable should be configurable):
AssertEqual 'cppcheck', ale_linters#c#cppcheck#GetExecutable(bufnr(''))
let b:ale_c_cppcheck_executable = 'foobar'
AssertEqual 'foobar', ale_linters#c#cppcheck#GetExecutable(bufnr(''))
Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('cppcheck') . b:command_tail,
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
let b:ale_c_cppcheck_executable = 'foobar'
AssertEqual
\ ale#Escape('foobar') . b:command_tail,
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C++ should detect compile_commands.json files):
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
\ 'cd ' . ale#Escape(g:dir . '/cppcheck_paths/one') . ' && '
\ . ale#Escape('cppcheck')
\ . ' -q --language=c --project=compile_commands.json --enable=style %t',
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))

View File

@ -0,0 +1,49 @@
Before:
Save g:ale_cpp_cppcheck_executable
Save g:ale_cpp_cppcheck_options
unlet! g:ale_cpp_cppcheck_executable
unlet! b:ale_cpp_cppcheck_executable
unlet! g:ale_cpp_cppcheck_options
unlet! b:ale_cpp_cppcheck_options
runtime ale_linters/cpp/cppcheck.vim
let b:command_tail = ' -q --language=c++ --enable=style %t'
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
Restore
unlet! b:command_tail
unlet! b:ale_cpp_cppcheck_executable
unlet! b:ale_cpp_cppcheck_options
call ale#linter#Reset()
call ale#test#RestoreDirectory()
Execute(The executable should be configurable):
AssertEqual 'cppcheck', ale_linters#cpp#cppcheck#GetExecutable(bufnr(''))
let b:ale_cpp_cppcheck_executable = 'foobar'
AssertEqual 'foobar', ale_linters#cpp#cppcheck#GetExecutable(bufnr(''))
Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('cppcheck') . b:command_tail,
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
let b:ale_cpp_cppcheck_executable = 'foobar'
AssertEqual
\ ale#Escape('foobar') . b:command_tail,
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C++ should detect compile_commands.json files):
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
\ 'cd ' . ale#Escape(g:dir . '/cppcheck_paths/one') . ' && '
\ . ale#Escape('cppcheck')
\ . ' -q --language=c++ --project=compile_commands.json --enable=style %t',
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))

View File

@ -1,47 +0,0 @@
Before:
silent! cd /testplugin/test/command_callback
let b:dir = getcwd()
After:
silent execute 'cd ' . fnameescape(b:dir)
unlet! b:dir
call ale#linter#Reset()
Execute(The default C cppcheck command should be correct):
runtime ale_linters/c/cppcheck.vim
call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
AssertEqual
\ 'cppcheck -q --language=c --enable=style %t',
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C should detect compile_commands.json files):
runtime ale_linters/c/cppcheck.vim
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
\ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
\ . 'cppcheck -q --language=c --project=compile_commands.json --enable=style %t',
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
Execute(The default C++ cppcheck command should be correct):
runtime ale_linters/cpp/cppcheck.vim
call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
AssertEqual
\ 'cppcheck -q --language=c++ --enable=style %t',
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C++ should detect compile_commands.json files):
runtime ale_linters/cpp/cppcheck.vim
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
\ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
\ . 'cppcheck -q --language=c++ --project=compile_commands.json --enable=style %t',
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))