Add cpplint linter

This commit is contained in:
Dawid Kurek 2017-05-10 19:41:58 +02:00
parent 8712aee5dc
commit 9185a0d2e5
6 changed files with 76 additions and 2 deletions

View File

@ -58,7 +58,7 @@ name. That seems to be the fairest way to arrange this table.
| Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/) | | Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/) |
| Bourne Shell | [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) | | Bourne Shell | [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) |
| C | [cppcheck](http://cppcheck.sourceforge.net), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/)| | C | [cppcheck](http://cppcheck.sourceforge.net), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/)|
| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.sourceforge.net), [gcc](https://gcc.gnu.org/)| | C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/)|
| C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) | | C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) |
| Chef | [foodcritic](http://www.foodcritic.io/) | | Chef | [foodcritic](http://www.foodcritic.io/) |
| CMake | [cmakelint](https://github.com/richq/cmake-lint) | | CMake | [cmakelint](https://github.com/richq/cmake-lint) |

View File

@ -0,0 +1,15 @@
" Author: Dawid Kurek https://github.com/dawikur
" Description: cpplint for cpp files
if !exists('g:ale_cpp_cpplint_options')
let g:ale_cpp_cpplint_options = ''
endif
call ale#linter#Define('cpp', {
\ 'name': 'cpplint',
\ 'output_stream': 'stderr',
\ 'executable': 'cpplint',
\ 'command': 'cpplint %s',
\ 'callback': 'ale#handlers#cpplint#HandleCppLintFormat',
\ 'lint_file': 1,
\})

View File

@ -0,0 +1,20 @@
" Author: Dawid Kurek https://github.com/dawikur
" Description: Handle errors for cpplint.
function! ale#handlers#cpplint#HandleCppLintFormat(buffer, lines) abort
" Look for lines like the following.
" test.cpp:5: Estra space after ( in function call [whitespace/parents] [4]
let l:pattern = '^.\{-}:\(\d\+\): \(.\+\)'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': 0,
\ 'text': l:match[2],
\ 'type': 'W',
\})
endfor
return l:output
endfunction

View File

@ -58,6 +58,17 @@ g:ale_cpp_cppcheck_options *g:ale_cpp_cppcheck_options*
This variable can be changed to modify flags given to cppcheck. This variable can be changed to modify flags given to cppcheck.
-------------------------------------------------------------------------------
cpplint *ale-cpp-cpplint*
g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options*
*b:ale_cpp_cpplint_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to cpplint.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
gcc *ale-cpp-gcc* gcc *ale-cpp-gcc*

View File

@ -22,6 +22,7 @@ CONTENTS *ale-contents*
clang...............................|ale-cpp-clang| clang...............................|ale-cpp-clang|
clangtidy...........................|ale-cpp-clangtidy| clangtidy...........................|ale-cpp-clangtidy|
cppcheck............................|ale-cpp-cppcheck| cppcheck............................|ale-cpp-cppcheck|
cpplint.............................|ale-cpp-cpplint|
gcc.................................|ale-cpp-gcc| gcc.................................|ale-cpp-gcc|
css...................................|ale-css-options| css...................................|ale-css-options|
stylelint...........................|ale-css-stylelint| stylelint...........................|ale-css-stylelint|
@ -120,7 +121,7 @@ The following languages and tools are supported.
* Bash: 'shell' (-n flag), 'shellcheck' * Bash: 'shell' (-n flag), 'shellcheck'
* Bourne Shell: 'shell' (-n flag), 'shellcheck' * Bourne Shell: 'shell' (-n flag), 'shellcheck'
* C: 'cppcheck', 'gcc', 'clang' * C: 'cppcheck', 'gcc', 'clang'
* C++ (filetype cpp): 'clang', 'clangtidy', 'cppcheck', 'gcc' * C++ (filetype cpp): 'clang', 'clangtidy', 'cppcheck', 'cpplint', 'gcc'
* C#: 'mcs' * C#: 'mcs'
* Chef: 'foodcritic' * Chef: 'foodcritic'
* CMake: 'cmakelint' * CMake: 'cmakelint'

View File

@ -0,0 +1,27 @@
Before:
runtime ale_linters/cpp/cpplint.vim
Execute(cpplint warnings from included files should be parsed correctly):
AssertEqual
\ [
\ {
\ 'lnum': 5,
\ 'col': 0,
\ 'text': ' Estra space after ( in function call [whitespace/parents] [4]',
\ 'type': 'W',
\ },
\ {
\ 'lnum': 120,
\ 'col': 0,
\ 'text': ' At least two spaces is best between code and comments [whitespace/comments] [2]',
\ 'type': 'W',
\ },
\ ],
\ ale#handlers#cpplint#HandleCppLintFormat(347, [
\ 'test.cpp:5: Estra space after ( in function call [whitespace/parents] [4]',
\ 'keymap_keys.hpp:120: At least two spaces is best between code and comments [whitespace/comments] [2]',
\ ])
After:
call ale#linter#Reset()