mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
Use Makefile output with clang-tidy when useful
In the case where neither a build directory nor a compile_commands.json file is found, use the output of `make -n` to provide options to clang-tidy.
This commit is contained in:
@@ -19,14 +19,18 @@ call ale#Set('c_clangtidy_options', '')
|
|||||||
call ale#Set('c_clangtidy_extra_options', '')
|
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, output) abort
|
||||||
let l:checks = join(ale#Var(a:buffer, 'c_clangtidy_checks'), ',')
|
let l:checks = join(ale#Var(a:buffer, 'c_clangtidy_checks'), ',')
|
||||||
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
||||||
|
|
||||||
" Get the extra options if we couldn't find a build directory.
|
" Get the extra options if we couldn't find a build directory.
|
||||||
let l:options = empty(l:build_dir)
|
let l:options = ''
|
||||||
\ ? ale#Var(a:buffer, 'c_clangtidy_options')
|
|
||||||
\ : ''
|
if empty(l:build_dir)
|
||||||
|
let l:options = ale#Var(a:buffer, 'c_clangtidy_options')
|
||||||
|
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
|
||||||
|
let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
|
||||||
|
endif
|
||||||
|
|
||||||
" Get the options to pass directly to clang-tidy
|
" Get the options to pass directly to clang-tidy
|
||||||
let l:extra_options = ale#Var(a:buffer, 'c_clangtidy_extra_options')
|
let l:extra_options = ale#Var(a:buffer, 'c_clangtidy_extra_options')
|
||||||
@@ -43,7 +47,7 @@ call ale#linter#Define('c', {
|
|||||||
\ 'name': 'clangtidy',
|
\ 'name': 'clangtidy',
|
||||||
\ 'output_stream': 'stdout',
|
\ 'output_stream': 'stdout',
|
||||||
\ 'executable': {b -> ale#Var(b, 'c_clangtidy_executable')},
|
\ 'executable': {b -> ale#Var(b, 'c_clangtidy_executable')},
|
||||||
\ 'command': function('ale_linters#c#clangtidy#GetCommand'),
|
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clangtidy#GetCommand'))},
|
||||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
\})
|
\})
|
||||||
|
|||||||
@@ -13,14 +13,18 @@ call ale#Set('cpp_clangtidy_options', '')
|
|||||||
call ale#Set('cpp_clangtidy_extra_options', '')
|
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, output) abort
|
||||||
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
||||||
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
||||||
|
|
||||||
" Get the extra options if we couldn't find a build directory.
|
" Get the extra options if we couldn't find a build directory.
|
||||||
let l:options = empty(l:build_dir)
|
let l:options = ''
|
||||||
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
|
|
||||||
\ : ''
|
if empty(l:build_dir)
|
||||||
|
let l:options = ale#Var(a:buffer, 'cpp_clangtidy_options')
|
||||||
|
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
|
||||||
|
let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
|
||||||
|
endif
|
||||||
|
|
||||||
" Get the options to pass directly to clang-tidy
|
" Get the options to pass directly to clang-tidy
|
||||||
let l:extra_options = ale#Var(a:buffer, 'cpp_clangtidy_extra_options')
|
let l:extra_options = ale#Var(a:buffer, 'cpp_clangtidy_extra_options')
|
||||||
@@ -37,7 +41,7 @@ call ale#linter#Define('cpp', {
|
|||||||
\ 'name': 'clangtidy',
|
\ 'name': 'clangtidy',
|
||||||
\ 'output_stream': 'stdout',
|
\ 'output_stream': 'stdout',
|
||||||
\ 'executable': {b -> ale#Var(b, 'cpp_clangtidy_executable')},
|
\ 'executable': {b -> ale#Var(b, 'cpp_clangtidy_executable')},
|
||||||
\ 'command': function('ale_linters#cpp#clangtidy#GetCommand'),
|
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clangtidy#GetCommand'))},
|
||||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
\})
|
\})
|
||||||
|
|||||||
Reference in New Issue
Block a user