summaryrefslogtreecommitdiff
path: root/ale_linters/c
diff options
context:
space:
mode:
authorJorengarenar <jorengarenar@outlook.com>2023-12-07 15:49:37 +0100
committerGitHub <noreply@github.com>2023-12-07 14:49:37 +0000
commitfc45a935bf25f7daa1965e3afcc8d9c6e525b078 (patch)
tree744501c6e5f797476ddc7e63b03c9d077b3429e3 /ale_linters/c
parent1ccd99e113324602b4eca41fd24ba6f991e8f05d (diff)
downloadale-fc45a935bf25f7daa1965e3afcc8d9c6e525b078.zip
Add clang-check linter for C (#4662)
* Close #976 - add clang-check to C linters * Update docs
Diffstat (limited to 'ale_linters/c')
-rw-r--r--ale_linters/c/clangcheck.vim38
1 files changed, 38 insertions, 0 deletions
diff --git a/ale_linters/c/clangcheck.vim b/ale_linters/c/clangcheck.vim
new file mode 100644
index 00000000..54dad47b
--- /dev/null
+++ b/ale_linters/c/clangcheck.vim
@@ -0,0 +1,38 @@
+" Author: gagbo <gagbobada@gmail.com>
+" : luibo <ng.akhoa98@gmail.com>
+" : Jorengarenar <jorengarenar@outlook.com>
+" 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,
+\})