summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/c/clangcheck.vim38
-rw-r--r--doc/ale-c.txt37
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/linter/test_c_clangcheck.vader37
6 files changed, 112 insertions, 3 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,
+\})
diff --git a/doc/ale-c.txt b/doc/ale-c.txt
index d3517e79..b8b448fb 100644
--- a/doc/ale-c.txt
+++ b/doc/ale-c.txt
@@ -25,10 +25,10 @@ g:ale_c_build_dir_names *g:ale_c_build_dir_names*
Type: |List|
Default: `['build', 'bin']`
- A list of directory names to be used when searching upwards from cpp files
+ A list of directory names to be used when searching upwards from C files
to discover compilation databases with. For directory named `'foo'`, ALE
will search for `'foo/compile_commands.json'` in all directories on and
- above the directory containing the cpp file to find path to compilation
+ above the directory containing the C file to find path to compilation
database. This feature is useful for the clang tools wrapped around
LibTooling (namely here, clang-tidy)
@@ -203,6 +203,37 @@ g:ale_c_ccls_init_options *g:ale_c_ccls_init_options*
===============================================================================
+clangcheck *ale-c-clangcheck*
+
+`clang-check` will be run only when files are saved to disk, so that
+`compile_commands.json` files can be used. It is recommended to use this
+linter in combination with `compile_commands.json` files.
+Therefore, `clang-check` linter reads the options |g:ale_c_build_dir| and
+|g:ale_c_build_dir_names|. Also, setting |g:ale_c_build_dir| actually
+overrides |g:ale_c_build_dir_names|.
+
+
+g:ale_c_clangcheck_executable *g:ale_c_clangcheck_executable*
+ *b:ale_c_clangcheck_executable*
+ Type: |String|
+ Default: `'clang-check'`
+
+ This variable can be changed to use a different executable for clangcheck.
+
+
+g:ale_c_clangcheck_options *g:ale_c_clangcheck_options*
+ *b:ale_c_clangcheck_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be changed to modify flags given to clang-check.
+
+ This variable should not be set to point to build subdirectory with
+ `-p path/to/build` option, as it is handled by the |g:ale_c_build_dir|
+ option.
+
+
+===============================================================================
clangd *ale-c-clangd*
g:ale_c_clangd_executable *g:ale_c_clangd_executable*
@@ -378,7 +409,7 @@ g:ale_c_cquery_executable *g:ale_c_cquery_executable*
This variable can be changed to use a different executable for cquery.
-g:ale_cpp_cquery_cache_directory *g:ale_c_cquery_cache_directory*
+g:ale_c_cquery_cache_directory *g:ale_c_cquery_cache_directory*
*b:ale_c_cquery_cache_directory*
Type: |String|
Default: `'~/.cache/cquery'`
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 939b9870..bfe34afc 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -67,6 +67,7 @@ Notes:
* `ccls`
* `clang` (`cc`)
* `clang-format`
+ * `clangcheck`!!
* `clangd`
* `clangtidy`!!
* `cppcheck`
diff --git a/doc/ale.txt b/doc/ale.txt
index a2362ddc..d11114e5 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2918,6 +2918,7 @@ documented in additional help files.
astyle................................|ale-c-astyle|
cc....................................|ale-c-cc|
ccls..................................|ale-c-ccls|
+ clangcheck............................|ale-c-clangcheck|
clangd................................|ale-c-clangd|
clang-format..........................|ale-c-clangformat|
clangtidy.............................|ale-c-clangtidy|
diff --git a/supported-tools.md b/supported-tools.md
index 01999d09..cb9bec16 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -76,6 +76,7 @@ formatting.
* [ccls](https://github.com/MaskRay/ccls)
* [clang](http://clang.llvm.org/)
* [clang-format](https://clang.llvm.org/docs/ClangFormat.html)
+ * [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) :floppy_disk:
* [clangd](https://clang.llvm.org/extra/clangd.html)
* [clangtidy](http://clang.llvm.org/extra/clang-tidy/) :floppy_disk:
* [cppcheck](http://cppcheck.sourceforge.net)
diff --git a/test/linter/test_c_clangcheck.vader b/test/linter/test_c_clangcheck.vader
new file mode 100644
index 00000000..60e1d80a
--- /dev/null
+++ b/test/linter/test_c_clangcheck.vader
@@ -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')