summaryrefslogtreecommitdiff
path: root/ale_linters/cpp
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-08-02 23:44:12 +0100
committerw0rp <devw0rp@gmail.com>2018-08-02 23:44:12 +0100
commit217284360d35711b751859ed27a7a3c3da300e85 (patch)
tree4b26a84b397e3ac15a8b13a572b1f9a50312dbab /ale_linters/cpp
parent9ef266d050d698c3ed3be3456ce6a5da5755d5ef (diff)
downloadale-217284360d35711b751859ed27a7a3c3da300e85.zip
Simplify the code for most linters and tests with closures
Diffstat (limited to 'ale_linters/cpp')
-rw-r--r--ale_linters/cpp/clang.vim9
-rw-r--r--ale_linters/cpp/clangcheck.vim11
-rw-r--r--ale_linters/cpp/clangtidy.vim8
-rw-r--r--ale_linters/cpp/cppcheck.vim9
-rw-r--r--ale_linters/cpp/cpplint.vim10
-rw-r--r--ale_linters/cpp/cquery.vim13
-rw-r--r--ale_linters/cpp/flawfinder.vim10
-rw-r--r--ale_linters/cpp/gcc.vim9
8 files changed, 17 insertions, 62 deletions
diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim
index 72793a71..649c5993 100644
--- a/ale_linters/cpp/clang.vim
+++ b/ale_linters/cpp/clang.vim
@@ -4,17 +4,12 @@
call ale#Set('cpp_clang_executable', 'clang++')
call ale#Set('cpp_clang_options', '-std=c++14 -Wall')
-function! ale_linters#cpp#clang#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_clang_executable')
-endfunction
-
function! ale_linters#cpp#clang#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
- return ale#Escape(ale_linters#cpp#clang#GetExecutable(a:buffer))
- \ . ' -S -x c++ -fsyntax-only'
+ return '%e -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(ale#Var(a:buffer, 'cpp_clang_options')) . ' -'
@@ -23,7 +18,7 @@ endfunction
call ale#linter#Define('cpp', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
-\ 'executable_callback': 'ale_linters#cpp#clang#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_clang_executable'),
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#clang#GetCommand'},
diff --git a/ale_linters/cpp/clangcheck.vim b/ale_linters/cpp/clangcheck.vim
index 687991bd..c66d6702 100644
--- a/ale_linters/cpp/clangcheck.vim
+++ b/ale_linters/cpp/clangcheck.vim
@@ -5,10 +5,6 @@ call ale#Set('cpp_clangcheck_executable', 'clang-check')
call ale#Set('cpp_clangcheck_options', '')
call ale#Set('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')
@@ -22,17 +18,16 @@ function! ale_linters#cpp#clangcheck#GetCommand(buffer) abort
" The extra arguments in the command are used to prevent .plist files from
" being generated. These are only added if no build directory can be
" detected.
- return ale#Escape(ale_linters#cpp#clangcheck#GetExecutable(a:buffer))
- \ . ' -analyze %s'
+ return '%e -analyze %s'
\ . (empty(l:build_dir) ? ' -extra-arg -Xclang -extra-arg -analyzer-output=text' : '')
- \ . (!empty(l:user_options) ? ' ' . l:user_options : '')
+ \ . ale#Pad(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_callback': 'ale_linters#cpp#clangcheck#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_clangcheck_executable'),
\ 'command_callback': 'ale_linters#cpp#clangcheck#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\ 'lint_file': 1,
diff --git a/ale_linters/cpp/clangtidy.vim b/ale_linters/cpp/clangtidy.vim
index d683327f..930087a8 100644
--- a/ale_linters/cpp/clangtidy.vim
+++ b/ale_linters/cpp/clangtidy.vim
@@ -10,10 +10,6 @@ call ale#Set('cpp_clangtidy_checks', ['*'])
call ale#Set('cpp_clangtidy_options', '')
call ale#Set('c_build_dir', '')
-function! ale_linters#cpp#clangtidy#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_clangtidy_executable')
-endfunction
-
function! s:GetBuildDirectory(buffer) abort
" Don't include build directory for header files, as compile_commands.json
" files don't consider headers to be translation units, and provide no
@@ -41,7 +37,7 @@ function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
\ : ''
- return ale#Escape(ale_linters#cpp#clangtidy#GetExecutable(a:buffer))
+ return '%e'
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
\ . ' %s'
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
@@ -51,7 +47,7 @@ endfunction
call ale#linter#Define('cpp', {
\ 'name': 'clangtidy',
\ 'output_stream': 'stdout',
-\ 'executable_callback': 'ale_linters#cpp#clangtidy#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_clangtidy_executable'),
\ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\ 'lint_file': 1,
diff --git a/ale_linters/cpp/cppcheck.vim b/ale_linters/cpp/cppcheck.vim
index 8b2aa802..229d6133 100644
--- a/ale_linters/cpp/cppcheck.vim
+++ b/ale_linters/cpp/cppcheck.vim
@@ -4,10 +4,6 @@
call ale#Set('cpp_cppcheck_executable', 'cppcheck')
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
" Search upwards from the file for compile_commands.json.
"
@@ -23,8 +19,7 @@ function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
\ : ''
return l:cd_command
- \ . ale#Escape(ale_linters#cpp#cppcheck#GetExecutable(a:buffer))
- \ . ' -q --language=c++ '
+ \ . '%e -q --language=c++ '
\ . l:compile_commands_option
\ . ale#Var(a:buffer, 'cpp_cppcheck_options')
\ . ' %t'
@@ -33,7 +28,7 @@ endfunction
call ale#linter#Define('cpp', {
\ 'name': 'cppcheck',
\ 'output_stream': 'both',
-\ 'executable_callback': 'ale_linters#cpp#cppcheck#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_cppcheck_executable'),
\ 'command_callback': 'ale_linters#cpp#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\})
diff --git a/ale_linters/cpp/cpplint.vim b/ale_linters/cpp/cpplint.vim
index 346ac815..d135fa79 100644
--- a/ale_linters/cpp/cpplint.vim
+++ b/ale_linters/cpp/cpplint.vim
@@ -4,22 +4,16 @@
call ale#Set('cpp_cpplint_executable', 'cpplint')
call ale#Set('cpp_cpplint_options', '')
-function! ale_linters#cpp#cpplint#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_cpplint_executable')
-endfunction
-
function! ale_linters#cpp#cpplint#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'cpp_cpplint_options')
- return ale#Escape(ale_linters#cpp#cpplint#GetExecutable(a:buffer))
- \ . (!empty(l:options) ? ' ' . l:options : '')
- \ . ' %s'
+ return '%e' . ale#Pad(l:options) . ' %s'
endfunction
call ale#linter#Define('cpp', {
\ 'name': 'cpplint',
\ 'output_stream': 'stderr',
-\ 'executable_callback': 'ale_linters#cpp#cpplint#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_cpplint_executable'),
\ 'command_callback': 'ale_linters#cpp#cpplint#GetCommand',
\ 'callback': 'ale#handlers#cpplint#HandleCppLintFormat',
\ 'lint_file': 1,
diff --git a/ale_linters/cpp/cquery.vim b/ale_linters/cpp/cquery.vim
index 7997c843..39eebce3 100644
--- a/ale_linters/cpp/cquery.vim
+++ b/ale_linters/cpp/cquery.vim
@@ -10,15 +10,6 @@ function! ale_linters#cpp#cquery#GetProjectRoot(buffer) abort
return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : ''
endfunction
-function! ale_linters#cpp#cquery#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_cquery_executable')
-endfunction
-
-function! ale_linters#cpp#cquery#GetCommand(buffer) abort
- let l:executable = ale_linters#cpp#cquery#GetExecutable(a:buffer)
- return ale#Escape(l:executable)
-endfunction
-
function! ale_linters#cpp#cquery#GetInitializationOptions(buffer) abort
return {'cacheDirectory': ale#Var(a:buffer, 'cpp_cquery_cache_directory')}
endfunction
@@ -26,8 +17,8 @@ endfunction
call ale#linter#Define('cpp', {
\ 'name': 'cquery',
\ 'lsp': 'stdio',
-\ 'executable_callback': 'ale_linters#cpp#cquery#GetExecutable',
-\ 'command_callback': 'ale_linters#cpp#cquery#GetCommand',
+\ 'executable_callback': ale#VarFunc('cpp_cquery_executable'),
+\ 'command': '%e',
\ 'project_root_callback': 'ale_linters#cpp#cquery#GetProjectRoot',
\ 'initialization_options_callback': 'ale_linters#cpp#cquery#GetInitializationOptions',
\})
diff --git a/ale_linters/cpp/flawfinder.vim b/ale_linters/cpp/flawfinder.vim
index 5a7092cf..4f669bff 100644
--- a/ale_linters/cpp/flawfinder.vim
+++ b/ale_linters/cpp/flawfinder.vim
@@ -6,17 +6,11 @@ call ale#Set('cpp_flawfinder_options', '')
call ale#Set('cpp_flawfinder_minlevel', 1)
call ale#Set('c_flawfinder_error_severity', 6)
-function! ale_linters#cpp#flawfinder#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_flawfinder_executable')
-endfunction
-
function! ale_linters#cpp#flawfinder#GetCommand(buffer) abort
-
" Set the minimum vulnerability level for flawfinder to bother with
let l:minlevel = ' --minlevel=' . ale#Var(a:buffer, 'cpp_flawfinder_minlevel')
- return ale#Escape(ale_linters#cpp#flawfinder#GetExecutable(a:buffer))
- \ . ' -CDQS'
+ return '%e -CDQS'
\ . ale#Var(a:buffer, 'cpp_flawfinder_options')
\ . l:minlevel
\ . ' %t'
@@ -25,7 +19,7 @@ endfunction
call ale#linter#Define('cpp', {
\ 'name': 'flawfinder',
\ 'output_stream': 'stdout',
-\ 'executable_callback': 'ale_linters#cpp#flawfinder#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_flawfinder_executable'),
\ 'command_callback': 'ale_linters#cpp#flawfinder#GetCommand',
\ 'callback': 'ale#handlers#flawfinder#HandleFlawfinderFormat',
\})
diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim
index 17f5acf5..9935b0bb 100644
--- a/ale_linters/cpp/gcc.vim
+++ b/ale_linters/cpp/gcc.vim
@@ -4,17 +4,12 @@
call ale#Set('cpp_gcc_executable', 'gcc')
call ale#Set('cpp_gcc_options', '-std=c++14 -Wall')
-function! ale_linters#cpp#gcc#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'cpp_gcc_executable')
-endfunction
-
function! ale_linters#cpp#gcc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
- return ale#Escape(ale_linters#cpp#gcc#GetExecutable(a:buffer))
- \ . ' -S -x c++ -fsyntax-only'
+ return '%e -S -x c++ -fsyntax-only'
\ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
\ . ale#Pad(l:cflags)
\ . ale#Pad(ale#Var(a:buffer, 'cpp_gcc_options')) . ' -'
@@ -24,7 +19,7 @@ call ale#linter#Define('cpp', {
\ 'name': 'gcc',
\ 'aliases': ['g++'],
\ 'output_stream': 'stderr',
-\ 'executable_callback': 'ale_linters#cpp#gcc#GetExecutable',
+\ 'executable_callback': ale#VarFunc('cpp_gcc_executable'),
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#gcc#GetCommand'},