Add clangcheck Linter to cpp (#686)

Add a clangcheck linter
This commit is contained in:
Gagbo 2017-06-24 17:10:04 +02:00 committed by w0rp
parent e98560a349
commit dc647fcc7f
4 changed files with 71 additions and 6 deletions

View File

@ -62,7 +62,7 @@ name. That seems to be the fairest way to arrange this table.
| Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/) | | Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/) |
| Bourne Shell | [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) | | Bourne Shell | [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) |
| C | [cppcheck](http://cppcheck.sourceforge.net), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/)| | C | [cppcheck](http://cppcheck.sourceforge.net), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/)|
| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/)| | C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/)|
| C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) | | C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) |
| Chef | [foodcritic](http://www.foodcritic.io/) | | Chef | [foodcritic](http://www.foodcritic.io/) |
| CMake | [cmakelint](https://github.com/richq/cmake-lint) | | CMake | [cmakelint](https://github.com/richq/cmake-lint) |

View File

@ -0,0 +1,37 @@
" Author: gagbo <gagbobada@gmail.com>
" Description: clang-check linter for cpp files
" Set this option to manually set some options for clang-check.
let g:ale_cpp_clangcheck_options = get(g:, 'ale_cpp_clangcheck_options', '')
" Set this option to manually point to the build directory for clang-tidy.
" This will disable all the other clangtidy_options, since compilation
" flags are contained in the json
let g:ale_c_build_dir = get(g:, 'ale_c_build_dir', '')
function! ale_linters#cpp#clangcheck#GetCommand(buffer) abort
let l:user_options = ale#Var(a:buffer, 'cpp_clangcheck_options')
let l:extra_options = !empty(l:user_options)
\ ? l:user_options
\ : ''
" Try to find compilation database to link automatically
let l:user_build_dir = ale#Var(a:buffer, 'c_build_dir')
if empty(l:user_build_dir)
let l:user_build_dir = ale#c#FindCompileCommands(a:buffer)
endif
let l:build_options = !empty(l:user_build_dir)
\ ? ' -p ' . ale#Escape(l:user_build_dir)
\ : ''
return 'clang-check -analyze ' . '%s' . l:extra_options . l:build_options
endfunction
call ale#linter#Define('cpp', {
\ 'name': 'clangcheck',
\ 'output_stream': 'stderr',
\ 'executable': 'clang-check',
\ 'command_callback': 'ale_linters#cpp#clangcheck#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\ 'lint_file': 1,
\})

View File

@ -44,6 +44,29 @@ g:ale_cpp_clang_options *g:ale_cpp_clang_options*
This variable can be changed to modify flags given to clang. This variable can be changed to modify flags given to clang.
-------------------------------------------------------------------------------
clangcheck *ale-cpp-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_cpp_clangcheck_options *g:ale_cpp_clangcheck_options*
*b:ale_cpp_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.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
clangtidy *ale-cpp-clangtidy* clangtidy *ale-cpp-clangtidy*
@ -73,11 +96,15 @@ g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
This variable can be changed to modify flags given to clang-tidy. This variable can be changed to modify flags given to clang-tidy.
Setting this variable to a non-empty string will cause the `--` argument - Setting this variable to a non-empty string,
to be passed to `clang-tidy`, which will mean that detection of - and working in a buffer where no compilation database is found using
`compile_commands.json` files for compile command databases will be |g:ale_c_build_dir_names| or |g:ale_c_build_dir|,
disabled. Only set this option if you want to control compiler flags will cause the `--` argument to be passed to `clang-tidy`, which will mean
entirely manually. that detection of `compile_commands.json` files for compile command
databases will be disabled.
Only set this option if you want to control compiler flags
entirely manually, and no `compile_commands.json` file is in one
of the |g:ale_c_build_dir_names| directories of the project tree.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -21,6 +21,7 @@ CONTENTS *ale-contents*
foodcritic..........................|ale-chef-foodcritic| foodcritic..........................|ale-chef-foodcritic|
cpp...................................|ale-cpp-options| cpp...................................|ale-cpp-options|
clang...............................|ale-cpp-clang| clang...............................|ale-cpp-clang|
clangcheck..........................|ale-cpp-clangcheck|
clangtidy...........................|ale-cpp-clangtidy| clangtidy...........................|ale-cpp-clangtidy|
cppcheck............................|ale-cpp-cppcheck| cppcheck............................|ale-cpp-cppcheck|
cpplint.............................|ale-cpp-cpplint| cpplint.............................|ale-cpp-cpplint|