summaryrefslogtreecommitdiff
path: root/autoload
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 /autoload
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 'autoload')
-rw-r--r--autoload/ale/c.vim11
1 files changed, 11 insertions, 0 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index e729aec8..4a9b80fb 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -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