diff options
author | Carl Smedstad <carl.smedstad@protonmail.com> | 2022-02-06 13:09:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 21:09:38 +0900 |
commit | c9938bc293da6c868d85627fc0f2befc037bb997 (patch) | |
tree | 41d3ca475d5fa46da93f0fbf5dc4fc74e900a0cc /ale_linters/cmake/cmake_lint.vim | |
parent | 7cbb68da6c5664a4e2aba533fe1f969373c60d5c (diff) | |
download | ale-c9938bc293da6c868d85627fc0f2befc037bb997.zip |
Add CMake linter cmake-lint (#4036)
* Add CMake linter cmake-lint
Add support for the CMake linter provided by
https://github.com/cheshirekow/cmake_format.
* Escape cmake-lint executable and add linter tests
Diffstat (limited to 'ale_linters/cmake/cmake_lint.vim')
-rw-r--r-- | ale_linters/cmake/cmake_lint.vim | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ale_linters/cmake/cmake_lint.vim b/ale_linters/cmake/cmake_lint.vim new file mode 100644 index 00000000..3c44c92f --- /dev/null +++ b/ale_linters/cmake/cmake_lint.vim @@ -0,0 +1,43 @@ +" Author: Carl Smedstad <carl.smedstad at protonmail dot com> +" Description: cmake-lint for cmake files + +let g:ale_cmake_cmake_lint_executable = +\ get(g:, 'ale_cmake_cmake_lint_executable', 'cmake-lint') + +let g:ale_cmake_cmake_lint_options = +\ get(g:, 'ale_cmake_cmake_lint_options', '') + +function! ale_linters#cmake#cmake_lint#Executable(buffer) abort + return ale#Var(a:buffer, 'cmake_cmake_lint_executable') +endfunction + +function! ale_linters#cmake#cmake_lint#Command(buffer) abort + let l:executable = ale_linters#cmake#cmake_lint#Executable(a:buffer) + let l:options = ale#Var(a:buffer, 'cmake_cmake_lint_options') + + return ale#Escape(l:executable) . ' ' . l:options . ' %t' +endfunction + +function! ale_linters#cmake#cmake_lint#Handle(buffer, lines) abort + let l:pattern = '\v^[^:]+:(\d+),?(\d+)?:\s\[([A-Z]\d+)\]\s(.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[1] + 0, + \ 'col': l:match[2] + 0, + \ 'type': 'W', + \ 'code': l:match[3], + \ 'text': l:match[4], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('cmake', { +\ 'name': 'cmake_lint', +\ 'executable': function('ale_linters#cmake#cmake_lint#Executable'), +\ 'command': function('ale_linters#cmake#cmake_lint#Command'), +\ 'callback': 'ale_linters#cmake#cmake_lint#Handle', +\}) |