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`.
This commit is contained in:
Nicolas Pauss
2022-09-25 02:02:43 +02:00
committed by GitHub
parent a56d51ec1c
commit 78942df284
7 changed files with 73 additions and 2 deletions

View File

@@ -585,3 +585,14 @@ function! ale#c#IncludeOptions(include_paths) abort
return join(l:option_list)
endfunction
" Get the language flag depending on if the file is a header or not.
function! ale#c#GetLanguageFlag(buffer, header_exts, linter_lang) abort
let l:buf_ext = expand('#' . a:buffer . ':e')
if index(a:header_exts, l:buf_ext) >= 0
return a:linter_lang . '-header'
endif
return a:linter_lang
endfunction