summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorNicolas Pauss <nicolas.pauss@intersec.com>2022-09-25 02:02:43 +0200
committerGitHub <noreply@github.com>2022-09-25 09:02:43 +0900
commit78942df284a4a00c59a6edcc187684cdbc333fb9 (patch)
tree67594b221cf453a3dec45ee6d6b280af1f722799 /ale_linters
parenta56d51ec1cd40172e94a6cb017049c0a7fed08e5 (diff)
downloadale-78942df284a4a00c59a6edcc187684cdbc333fb9.zip
cc: use '-x c*-header' for header files for C and C++ linters. (#4318)
When linting an header file in C or C++, `-x c-header` or `-x c++-header` should be used instead of `-x c` or `-x c++`. Using `-x c` or `-x c++` for headers files can lead to unused variables and functions marked as static inlined as seen in #4096. Using `-x c-header` or `-x c++-header` solve these issues. The list of file extensions that are considered as header files can be configured with the variables `g:ale_c_cc_header_exts` and `g:ale_cpp_cc_header_exts`.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/c/cc.vim5
-rw-r--r--ale_linters/cpp/cc.vim5
2 files changed, 8 insertions, 2 deletions
diff --git a/ale_linters/c/cc.vim b/ale_linters/c/cc.vim
index 5655fbf7..d0215041 100644
--- a/ale_linters/c/cc.vim
+++ b/ale_linters/c/cc.vim
@@ -3,6 +3,7 @@
call ale#Set('c_cc_executable', '<auto>')
call ale#Set('c_cc_options', '-std=c11 -Wall')
+call ale#Set('c_cc_header_exts', ['h'])
function! ale_linters#c#cc#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'c_cc_executable')
@@ -22,6 +23,8 @@ endfunction
function! ale_linters#c#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'c_cc_options')
+ let l:header_exts = ale#Var(a:buffer, 'c_cc_header_exts')
+ let l:lang_flag = ale#c#GetLanguageFlag(a:buffer, l:header_exts, 'c')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
@@ -36,7 +39,7 @@ function! ale_linters#c#cc#GetCommand(buffer, output) abort
"
" `-o /dev/null` or `-o null` is needed to catch all errors,
" -fsyntax-only doesn't catch everything.
- return '%e -S -x c'
+ return '%e -S -x ' . l:lang_flag
\ . ' -o ' . g:ale#util#nul_file
\ . ' -iquote %s:h'
\ . ale#Pad(l:cflags)
diff --git a/ale_linters/cpp/cc.vim b/ale_linters/cpp/cc.vim
index ffb8f068..f8021531 100644
--- a/ale_linters/cpp/cc.vim
+++ b/ale_linters/cpp/cc.vim
@@ -3,6 +3,7 @@
call ale#Set('cpp_cc_executable', '<auto>')
call ale#Set('cpp_cc_options', '-std=c++14 -Wall')
+call ale#Set('cpp_cc_header_exts', ['h', 'hpp'])
function! ale_linters#cpp#cc#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'cpp_cc_executable')
@@ -22,6 +23,8 @@ endfunction
function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'cpp_cc_options')
+ let l:header_exts = ale#Var(a:buffer, 'cpp_cc_header_exts')
+ let l:lang_flag = ale#c#GetLanguageFlag(a:buffer, l:header_exts, 'c++')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
@@ -36,7 +39,7 @@ function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
"
" `-o /dev/null` or `-o null` is needed to catch all errors,
" -fsyntax-only doesn't catch everything.
- return '%e -S -x c++'
+ return '%e -S -x ' . l:lang_flag
\ . ' -o ' . g:ale#util#nul_file
\ . ' -iquote %s:h'
\ . ale#Pad(l:cflags)