summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/c/cppcheck.vim17
-rw-r--r--ale_linters/cpp/cppcheck.vim17
-rw-r--r--test/command_callback/cppcheck_paths/with_build_dir/build/compile_commands.json0
-rw-r--r--test/command_callback/test_c_cppcheck_command_callbacks.vader14
-rw-r--r--test/command_callback/test_cpp_cppcheck_command_callbacks.vader16
5 files changed, 41 insertions, 23 deletions
diff --git a/ale_linters/c/cppcheck.vim b/ale_linters/c/cppcheck.vim
index 851f9f11..b2ded90f 100644
--- a/ale_linters/c/cppcheck.vim
+++ b/ale_linters/c/cppcheck.vim
@@ -9,19 +9,16 @@ function! ale_linters#c#cppcheck#GetCommand(buffer) abort
"
" If we find it, we'll `cd` to where the compile_commands.json file is,
" then use the file to set up import paths, etc.
- let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
-
- let l:cd_command = !empty(l:compile_commmands_path)
- \ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
- \ : ''
- let l:compile_commands_option = !empty(l:compile_commmands_path)
- \ ? '--project=compile_commands.json '
+ let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
+ let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
+ let l:compile_commands_option = !empty(l:json_path)
+ \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
\ : ''
return l:cd_command
- \ . '%e -q --language=c '
- \ . l:compile_commands_option
- \ . ale#Var(a:buffer, 'c_cppcheck_options')
+ \ . '%e -q --language=c'
+ \ . ale#Pad(l:compile_commands_option)
+ \ . ale#Pad(ale#Var(a:buffer, 'c_cppcheck_options'))
\ . ' %t'
endfunction
diff --git a/ale_linters/cpp/cppcheck.vim b/ale_linters/cpp/cppcheck.vim
index 5173d698..dae0774e 100644
--- a/ale_linters/cpp/cppcheck.vim
+++ b/ale_linters/cpp/cppcheck.vim
@@ -9,19 +9,16 @@ function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
"
" If we find it, we'll `cd` to where the compile_commands.json file is,
" then use the file to set up import paths, etc.
- let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
-
- let l:cd_command = !empty(l:compile_commmands_path)
- \ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
- \ : ''
- let l:compile_commands_option = !empty(l:compile_commmands_path)
- \ ? '--project=compile_commands.json '
+ let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
+ let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
+ let l:compile_commands_option = !empty(l:json_path)
+ \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
\ : ''
return l:cd_command
- \ . '%e -q --language=c++ '
- \ . l:compile_commands_option
- \ . ale#Var(a:buffer, 'cpp_cppcheck_options')
+ \ . '%e -q --language=c++'
+ \ . ale#Pad(l:compile_commands_option)
+ \ . ale#Pad(ale#Var(a:buffer, 'cpp_cppcheck_options'))
\ . ' %t'
endfunction
diff --git a/test/command_callback/cppcheck_paths/with_build_dir/build/compile_commands.json b/test/command_callback/cppcheck_paths/with_build_dir/build/compile_commands.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/cppcheck_paths/with_build_dir/build/compile_commands.json
diff --git a/test/command_callback/test_c_cppcheck_command_callbacks.vader b/test/command_callback/test_c_cppcheck_command_callbacks.vader
index 3ae4bdbe..8e11ef2d 100644
--- a/test/command_callback/test_c_cppcheck_command_callbacks.vader
+++ b/test/command_callback/test_c_cppcheck_command_callbacks.vader
@@ -21,4 +21,16 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
AssertLinter 'cppcheck',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
\ . ale#Escape('cppcheck')
- \ . ' -q --language=c --project=compile_commands.json --enable=style %t'
+ \ . ' -q --language=c'
+ \ . ' --project=' . ale#Escape('compile_commands.json')
+ \ . ' --enable=style %t'
+
+Execute(cppcheck for C++ should detect compile_commands.json files in build directories):
+ call ale#test#SetFilename('cppcheck_paths/with_build_dir/foo.cpp')
+
+ AssertLinter 'cppcheck',
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/with_build_dir'))
+ \ . ale#Escape('cppcheck')
+ \ . ' -q --language=c'
+ \ . ' --project=' . ale#Escape(ale#path#Simplify('build/compile_commands.json'))
+ \ . ' --enable=style %t'
diff --git a/test/command_callback/test_cpp_cppcheck_command_callbacks.vader b/test/command_callback/test_cpp_cppcheck_command_callbacks.vader
index 352c88d5..28e3a0b7 100644
--- a/test/command_callback/test_cpp_cppcheck_command_callbacks.vader
+++ b/test/command_callback/test_cpp_cppcheck_command_callbacks.vader
@@ -17,6 +17,18 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertLinter 'cppcheck',
- \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
\ . ale#Escape('cppcheck')
- \ . ' -q --language=c++ --project=compile_commands.json --enable=style %t'
+ \ . ' -q --language=c++'
+ \ . ' --project=' . ale#Escape('compile_commands.json')
+ \ . ' --enable=style %t'
+
+Execute(cppcheck for C++ should detect compile_commands.json files in build directories):
+ call ale#test#SetFilename('cppcheck_paths/with_build_dir/foo.cpp')
+
+ AssertLinter 'cppcheck',
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/with_build_dir'))
+ \ . ale#Escape('cppcheck')
+ \ . ' -q --language=c++'
+ \ . ' --project=' . ale#Escape('build/compile_commands.json')
+ \ . ' --enable=style %t'