Add additional option setting for clangtidy linter

The existing option setting handles setting additional compile flags to
pass to clang-tidy. The new option setting added here allows setting
additional clang-tidy specific flags to be passed as well.
Fixes #2324
This commit is contained in:
Jonathan Vander Mey 2019-06-08 15:12:43 -04:00
parent 7b78f2b846
commit 3c799abb44
6 changed files with 46 additions and 4 deletions

View File

@ -11,9 +11,12 @@ call ale#Set('c_clangtidy_executable', 'clang-tidy')
" http://clang.llvm.org/extra/clang-tidy/checks/list.html " http://clang.llvm.org/extra/clang-tidy/checks/list.html
call ale#Set('c_clangtidy_checks', []) call ale#Set('c_clangtidy_checks', [])
" Set this option to manually set some options for clang-tidy. " Set this option to manually set some options for clang-tidy to use as compile
" flags.
" This will disable compile_commands.json detection. " This will disable compile_commands.json detection.
call ale#Set('c_clangtidy_options', '') call ale#Set('c_clangtidy_options', '')
" Set this option to manually set options for clang-tidy directly.
call ale#Set('c_clangtidy_extra_options', '')
call ale#Set('c_build_dir', '') call ale#Set('c_build_dir', '')
function! ale_linters#c#clangtidy#GetCommand(buffer) abort function! ale_linters#c#clangtidy#GetCommand(buffer) abort
@ -25,8 +28,12 @@ function! ale_linters#c#clangtidy#GetCommand(buffer) abort
\ ? ale#Var(a:buffer, 'c_clangtidy_options') \ ? ale#Var(a:buffer, 'c_clangtidy_options')
\ : '' \ : ''
" Get the options to pass directly to clang-tidy
let l:extra_options = ale#Var(a:buffer, 'c_clangtidy_extra_options')
return '%e' return '%e'
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '') \ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
\ . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
\ . ' %s' \ . ' %s'
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '') \ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
\ . (!empty(l:options) ? ' -- ' . l:options : '') \ . (!empty(l:options) ? ' -- ' . l:options : '')

View File

@ -5,9 +5,12 @@
call ale#Set('cpp_clangtidy_executable', 'clang-tidy') call ale#Set('cpp_clangtidy_executable', 'clang-tidy')
" Set this option to check the checks clang-tidy will apply. " Set this option to check the checks clang-tidy will apply.
call ale#Set('cpp_clangtidy_checks', []) call ale#Set('cpp_clangtidy_checks', [])
" Set this option to manually set some options for clang-tidy. " Set this option to manually set some options for clang-tidy to use as compile
" flags.
" This will disable compile_commands.json detection. " This will disable compile_commands.json detection.
call ale#Set('cpp_clangtidy_options', '') call ale#Set('cpp_clangtidy_options', '')
" Set this option to manually set options for clang-tidy directly.
call ale#Set('cpp_clangtidy_extra_options', '')
call ale#Set('c_build_dir', '') call ale#Set('c_build_dir', '')
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
@ -19,8 +22,12 @@ function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options') \ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
\ : '' \ : ''
" Get the options to pass directly to clang-tidy
let l:extra_options = ale#Var(a:buffer, 'cpp_clangtidy_extra_options')
return '%e' return '%e'
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '') \ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
\ . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
\ . ' %s' \ . ' %s'
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '') \ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
\ . (!empty(l:options) ? ' -- ' . l:options : '') \ . (!empty(l:options) ? ' -- ' . l:options : '')

View File

@ -156,7 +156,7 @@ g:ale_c_clangtidy_options *g:ale_c_clangtidy_options*
Type: |String| Type: |String|
Default: `''` Default: `''`
This variable can be changed to modify flags given to clang-tidy. This variable can be changed to modify compiler flags given to clang-tidy.
- Setting this variable to a non-empty string, - Setting this variable to a non-empty string,
- and working in a buffer where no compilation database is found using - and working in a buffer where no compilation database is found using
@ -169,6 +169,14 @@ g:ale_c_clangtidy_options *g:ale_c_clangtidy_options*
of the |g:ale_c_build_dir_names| directories of the project tree. of the |g:ale_c_build_dir_names| directories of the project tree.
g:ale_c_clangtidy_extra_options *g:ale_c_clangtidy_extra_options*
*b:ale_c_clangtidy_extra_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to clang-tidy.
=============================================================================== ===============================================================================
cppcheck *ale-c-cppcheck* cppcheck *ale-c-cppcheck*

View File

@ -125,7 +125,7 @@ g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
Type: |String| Type: |String|
Default: `''` Default: `''`
This variable can be changed to modify flags given to clang-tidy. This variable can be changed to modify compiler flags given to clang-tidy.
- Setting this variable to a non-empty string, - Setting this variable to a non-empty string,
- and working in a buffer where no compilation database is found using - and working in a buffer where no compilation database is found using
@ -138,6 +138,14 @@ g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
of the |g:ale_c_build_dir_names| directories of the project tree. of the |g:ale_c_build_dir_names| directories of the project tree.
g:ale_cpp_clangtidy_extra_options *g:ale_cpp_clangtidy_extra_options*
*b:ale_cpp_clangtidy_extra_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to clang-tidy.
=============================================================================== ===============================================================================
clazy *ale-cpp-clazy* clazy *ale-cpp-clazy*

View File

@ -29,6 +29,12 @@ Execute(You should be able to manually set compiler flags for clang-tidy):
AssertLinter 'clang-tidy', AssertLinter 'clang-tidy',
\ ale#Escape('clang-tidy') . ' -checks=' . ale#Escape('*') . ' %s -- -Wall' \ ale#Escape('clang-tidy') . ' -checks=' . ale#Escape('*') . ' %s -- -Wall'
Execute(You should be able to manually set flags for clang-tidy):
let b:ale_c_clangtidy_extra_options = '-config='
AssertLinter 'clang-tidy',
\ ale#Escape('clang-tidy') . ' ' . ale#Escape('-config=') . ' %s'
Execute(The build directory should be configurable): Execute(The build directory should be configurable):
let b:ale_c_clangtidy_checks = ['*'] let b:ale_c_clangtidy_checks = ['*']
let b:ale_c_build_dir = '/foo/bar' let b:ale_c_build_dir = '/foo/bar'

View File

@ -29,6 +29,12 @@ Execute(You should be able to manually set compiler flags for clang-tidy):
AssertLinter 'clang-tidy', AssertLinter 'clang-tidy',
\ ale#Escape('clang-tidy') . ' -checks=' . ale#Escape('*') . ' %s -- -Wall' \ ale#Escape('clang-tidy') . ' -checks=' . ale#Escape('*') . ' %s -- -Wall'
Execute(You should be able to manually set flags for clang-tidy):
let b:ale_cpp_clangtidy_extra_options = '-config='
AssertLinter 'clang-tidy',
\ ale#Escape('clang-tidy') . ' ' . ale#Escape('-config=') . ' %s'
Execute(The build directory should be configurable): Execute(The build directory should be configurable):
let b:ale_cpp_clangtidy_checks = ['*'] let b:ale_cpp_clangtidy_checks = ['*']
let b:ale_c_build_dir = '/foo/bar' let b:ale_c_build_dir = '/foo/bar'