From 1ec28f7117b7d703a2645b0776b8ba121f889c46 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 7 Aug 2014 13:11:35 +0200 Subject: [PATCH] improved Vim coding guidelines checker * Avoids highlighting some matches when inside C++ comments * Add operators << and >> * Automatic initialization when opening Vim in the Haiku source directory (if you use the same directory layout as me) * Matches are highlighted in red, rather than reusing the "Search" match group. You can pick another color by editing the "highlight Style" definition. Improvements are still welcome. --- 3rdparty/pulkomandy/checkstyle.vim | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 3rdparty/pulkomandy/checkstyle.vim diff --git a/3rdparty/pulkomandy/checkstyle.vim b/3rdparty/pulkomandy/checkstyle.vim new file mode 100644 index 0000000000..7d50f4335b --- /dev/null +++ b/3rdparty/pulkomandy/checkstyle.vim @@ -0,0 +1,53 @@ +" Coding guidelines check for Haiku. +" Copyright 2010-2014 Haiku, Inc. +" Distributed under the terms of the MIT licence. +" +" Insert this into your vimrc or as some autoloaded file. It will register +" several matchadd regular expressions to try to catch common style violations: +" lines longer than 80 chars, missing space around operators or after keywords, +" indentation with spaces instead of tabs, and so on. Potential problems are +" highlighted with a beautiful red background. +" +" This regex-based method is not perfect: there may be some false positive and +" some cases are not checked. Feel free to improve on this. +" +" The matches are only enabled when starting vim from /Donnees/Dev/Haiku/haiku +" or a subdirectory of it. This way it doesn't get in the way when working on +" other projects. FuncHaikuCheck() can also be called manually to enable the +" matches in other directories. + +:highlight Style ctermbg=red guibg=red +:fu FuncHaikuCheck() + call matchadd('Style', '\%>80v.\+', -1) " line over 80 char + call matchadd('Style', '^\s* \s*', -1) " spaces instead of tabs + call matchadd('Style', '\(for\|if\|select\|while\)(', -1) + "missing space after control statement + call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*//\S', -1) + " Missing space at comment start + + call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w[,=>+\-*;]\w', -1) + call matchadd('Style', '^\(\(?!\/\/\|\/\*\).\)*\w\(<<\|>>\)\w', -1) + "operator without space around it (without false positive on + "templated) + call matchadd('Style', '^[^#]^\(\(?!\/\/\|\/\*\).\)*[^<]\zs\w*/\w', -1) + "operator without space around it (without false positive on + "#include ) + call matchadd('Style', '^[^/]\{2}.*\zs[^*][=/+\-< ]$', -1) + "operator at end of line (without false positives on /* and */, nor + "char*\nClass::method()) + call matchadd('Style', '^[^#].*\zs[^<]>$', -1) + " > operator at EOL (without false positive on #include ) + call matchadd('Style', '){', -1) " Missing space after method header + call matchadd('Style', '}\n\s*else', -1) " Malformed else + call matchadd('Style', '\s$', -1) "Spaces at end of line + call matchadd('Style', ',\S', -1) " Missing space after comma + call matchadd('Style', '^}\n\{1,2}\S', -1) + " Less than 2 lines between functions + call matchadd('Style', '^}\n\{4,}\S', -1) + " More than 2 lines between functions +:endfu + +if stridx(getcwd(), '/Donnees/Dev/Haiku/haiku') == 0 + " Webkit indentation rules + call FuncHaikuCheck() +endif