-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clang-check linter for C (#4662)
* Close #976 - add clang-check to C linters * Update docs
- Loading branch information
Showing
6 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
" Author: gagbo <[email protected]> | ||
" : luibo <[email protected]> | ||
" : Jorengarenar <[email protected]> | ||
" Description: clang-check linter for C files | ||
" modified from cpp/clangcheck.vim to match for C | ||
|
||
call ale#Set('c_clangcheck_executable', 'clang-check') | ||
call ale#Set('c_clangcheck_options', '') | ||
call ale#Set('c_build_dir', '') | ||
|
||
function! ale_linters#c#clangcheck#GetCommand(buffer) abort | ||
let l:user_options = ale#Var(a:buffer, 'c_clangcheck_options') | ||
|
||
" Try to find compilation database to link automatically | ||
let l:build_dir = ale#Var(a:buffer, 'c_build_dir') | ||
|
||
if empty(l:build_dir) | ||
let [l:root, l:json_file] = ale#c#FindCompileCommands(a:buffer) | ||
let l:build_dir = ale#path#Dirname(l:json_file) | ||
endif | ||
|
||
" 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 '%e -analyze %s' | ||
\ . (empty(l:build_dir) ? ' --extra-arg=-Xclang --extra-arg=-analyzer-output=text --extra-arg=-fno-color-diagnostics': '') | ||
\ . ale#Pad(l:user_options) | ||
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '') | ||
endfunction | ||
|
||
call ale#linter#Define('c', { | ||
\ 'name': 'clangcheck', | ||
\ 'output_stream': 'stderr', | ||
\ 'executable': {b -> ale#Var(b, 'c_clangcheck_executable')}, | ||
\ 'command': function('ale_linters#c#clangcheck#GetCommand'), | ||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', | ||
\ 'lint_file': 1, | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# modified from test_cpp_cppcheck.vader | ||
|
||
Before: | ||
call ale#assert#SetUpLinterTest('c', 'clangcheck') | ||
|
||
After: | ||
call ale#assert#TearDownLinterTest() | ||
|
||
Execute(The executable should be configurable): | ||
AssertLinter 'clang-check', | ||
\ ale#Escape('clang-check') | ||
\ . ' -analyze %s --extra-arg=-Xclang --extra-arg=-analyzer-output=text --extra-arg=-fno-color-diagnostics' | ||
|
||
let b:ale_c_clangcheck_executable = 'foobar' | ||
|
||
" The extra arguments in the command are used to prevent .plist files from | ||
" being generated. | ||
AssertLinter 'foobar', | ||
\ ale#Escape('foobar') | ||
\ . ' -analyze %s --extra-arg=-Xclang --extra-arg=-analyzer-output=text --extra-arg=-fno-color-diagnostics' | ||
|
||
Execute(The options should be configurable): | ||
let b:ale_c_clangcheck_options = '--something' | ||
|
||
AssertLinter 'clang-check', | ||
\ ale#Escape('clang-check') | ||
\ . ' -analyze %s' | ||
\ . ' --extra-arg=-Xclang --extra-arg=-analyzer-output=text --extra-arg=-fno-color-diagnostics' | ||
\ . ' --something' | ||
|
||
Execute(The build directory should be used when set): | ||
let b:ale_c_clangcheck_options = '--something' | ||
let b:ale_c_build_dir = '/foo/bar' | ||
|
||
AssertLinter 'clang-check', | ||
\ ale#Escape('clang-check') | ||
\ . ' -analyze %s --something -p ' . ale#Escape('/foo/bar') |