From 208faa42061351add1e96f49d5f6c1a68288c65e Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Tue, 30 Sep 2014 10:02:21 +0200 Subject: [PATCH 1/6] added variable that configure the extensions for cpplint --- README.mdown | 15 +++++++++++++++ ftplugin/cpp_cpplint.vim | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.mdown b/README.mdown index e89f5dd..64994cc 100644 --- a/README.mdown +++ b/README.mdown @@ -3,6 +3,8 @@ vim-cpplint `vim-cpplint` is a Vim plugin that runs the currently open file through cpplint.py, a static syntax and style checker for C++ source code. +The code will be checked according to [Google C++ Style Guide ](http://google-styleguide.googlecode.com/svn/trunk/cppguide.html) + Installation ------------ @@ -29,6 +31,14 @@ the `` key if so. For example, to remap it to `` instead, use: autocmd FileType cpp map :call Cpplint() +By default the plugin support following file extensions: +*.cc, *.h, *.cpp, *.cu, *.cuh + +You can change it by setting in .vimrc the variable: + let g:cpplint_extensions = "cpp,hpp,h,c,cc,cu,cuh" + + + Tips ---- A tip might be to run the cpplint.py check every time you write a C++ file, to @@ -36,3 +46,8 @@ enable this, add the following line to your `.vimrc` file (thanks [Godefroid](http://github.com/gotcha)!): autocmd BufWritePost *.h,*.cpp call Cpplint() + +False positives can be ignored by putting + + // NOLINT at the end of the line or + // NOLINTNEXTLINE in the previous line. diff --git a/ftplugin/cpp_cpplint.vim b/ftplugin/cpp_cpplint.vim index 20d28b6..7a19345 100644 --- a/ftplugin/cpp_cpplint.vim +++ b/ftplugin/cpp_cpplint.vim @@ -3,11 +3,14 @@ " Language: C++ (ft=cpp) " Maintainer: Thomas Chen " Version: Vim 7 (may work with lower Vim versions, but not tested) -" URL: http://example.com/ " " Code is borrowed from vim-flake8 and slightly modified. " " Only do this when not done yet for this buffer +" +" Running the Google cpplint.py code to validate the style according to: +" http://google-styleguide.googlecode.com/svn/trunk/cppguide.html +" if exists("b:loaded_cpplint_ftplugin") finish endif @@ -15,6 +18,14 @@ let b:loaded_cpplint_ftplugin=1 let s:cpplint_cmd="cpplint.py" +" extensions + +let s:cpplint_extensions="cc,h,cpp,cu,cuh" + +if exists("g:cpplint_extensions") + let s:cpplint_extensions=g:cpplint_extensions +endif + if !exists("*Cpplint()") function Cpplint() if !executable(s:cpplint_cmd) @@ -36,7 +47,7 @@ if !exists("*Cpplint()") " perform the grep itself let &grepformat="%f:%l: %m" - let &grepprg=s:cpplint_cmd + let &grepprg=s:cpplint_cmd . ' --extensions=' . s:cpplint_extensions . ' ' silent! grep! % " restore grep settings From 397dfc7690b891e76477a683ab51c7ccf75c63d4 Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Tue, 30 Sep 2014 10:03:51 +0200 Subject: [PATCH 2/6] fix readme --- README.mdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.mdown b/README.mdown index 64994cc..da64db2 100644 --- a/README.mdown +++ b/README.mdown @@ -35,6 +35,7 @@ By default the plugin support following file extensions: *.cc, *.h, *.cpp, *.cu, *.cuh You can change it by setting in .vimrc the variable: + let g:cpplint_extensions = "cpp,hpp,h,c,cc,cu,cuh" From ce8996c90a41d5036266d31acbc57c986026fa8c Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Tue, 30 Sep 2014 10:51:09 +0200 Subject: [PATCH 3/6] checks if there are some errors, if not then the window error will not be shown --- ftplugin/cpp_cpplint.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ftplugin/cpp_cpplint.vim b/ftplugin/cpp_cpplint.vim index 7a19345..b8cdc83 100644 --- a/ftplugin/cpp_cpplint.vim +++ b/ftplugin/cpp_cpplint.vim @@ -26,6 +26,12 @@ if exists("g:cpplint_extensions") let s:cpplint_extensions=g:cpplint_extensions endif +let s:cpplint_cmd_opts = ' --extensions=' . s:cpplint_extensions . ' ' + +if exists('g:cpplint_line_length') + let s:cpplint_cmd_opts = s:cpplint_cmd_opts . ' --linelength=' . g:cpplint_line_length . ' ' +endif + if !exists("*Cpplint()") function Cpplint() if !executable(s:cpplint_cmd) @@ -47,15 +53,21 @@ if !exists("*Cpplint()") " perform the grep itself let &grepformat="%f:%l: %m" - let &grepprg=s:cpplint_cmd . ' --extensions=' . s:cpplint_extensions . ' ' + let &grepprg=s:cpplint_cmd . s:cpplint_cmd_opts . ' ' silent! grep! % + let has_results=1 + for va in getqflist() + if va.text =~ "Total errors found: 0" + let has_results=0 + break + endif + endfor " restore grep settings let &grepformat=l:old_gfm let &grepprg=l:old_gp " open cwindow - let has_results=getqflist() != [] if has_results execute 'belowright copen' setlocal wrap @@ -70,7 +82,7 @@ if !exists("*Cpplint()") " Show OK status hi Green ctermfg=green echohl Green - echon "cpplint.py check OK" + echon "cpplint.py check OK (status: " . has_results . ')' echohl endif endfunction From b9ff41405be099f198fd39d2ab5633d255f959f0 Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Tue, 30 Sep 2014 10:53:30 +0200 Subject: [PATCH 4/6] Update README.mdown --- README.mdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.mdown b/README.mdown index da64db2..bec812d 100644 --- a/README.mdown +++ b/README.mdown @@ -37,6 +37,11 @@ By default the plugin support following file extensions: You can change it by setting in .vimrc the variable: let g:cpplint_extensions = "cpp,hpp,h,c,cc,cu,cuh" + +The line width, by default it is 80 characters but you can change it by + + let g:cpplint_line_width = + From 40f12c72e0d2b37f559d5225f6ad0c86857044cf Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Tue, 30 Sep 2014 10:54:03 +0200 Subject: [PATCH 5/6] Update README.mdown --- README.mdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.mdown b/README.mdown index bec812d..dc968b7 100644 --- a/README.mdown +++ b/README.mdown @@ -38,9 +38,9 @@ You can change it by setting in .vimrc the variable: let g:cpplint_extensions = "cpp,hpp,h,c,cc,cu,cuh" -The line width, by default it is 80 characters but you can change it by +The line length, by default it is 80 characters but you can change it by - let g:cpplint_line_width = + let g:cpplint_line_length = From 9c2c80c53507994926e460dd161f9984f17195ed Mon Sep 17 00:00:00 2001 From: Jakub Krajniak Date: Fri, 31 Oct 2014 09:20:08 +0100 Subject: [PATCH 6/6] support for --filter --- ftplugin/cpp_cpplint.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ftplugin/cpp_cpplint.vim b/ftplugin/cpp_cpplint.vim index b8cdc83..1a4a854 100644 --- a/ftplugin/cpp_cpplint.vim +++ b/ftplugin/cpp_cpplint.vim @@ -19,7 +19,6 @@ let b:loaded_cpplint_ftplugin=1 let s:cpplint_cmd="cpplint.py" " extensions - let s:cpplint_extensions="cc,h,cpp,cu,cuh" if exists("g:cpplint_extensions") @@ -28,10 +27,16 @@ endif let s:cpplint_cmd_opts = ' --extensions=' . s:cpplint_extensions . ' ' +" line length if exists('g:cpplint_line_length') let s:cpplint_cmd_opts = s:cpplint_cmd_opts . ' --linelength=' . g:cpplint_line_length . ' ' endif +" filters +if exists('g:cpplint_filter') + let s:cpplint_cmd_opts = s:cpplint_cmd_opts . ' --filter=' . g:cpplint_filter . ' ' +endif + if !exists("*Cpplint()") function Cpplint() if !executable(s:cpplint_cmd)