From f8d3a2a0a6ab4b634af73e1854ccaa46fe0d0c0a Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 25 Sep 2016 18:43:50 +0100 Subject: [PATCH] pre-commit-hook: Added checks for multi-level template parameters and 'NULL' Patch contributed by Bruno Santos Resolves bug-report http://bugs.openfoam.org/view.php?id=2267 1. Spaced ending of multi-level template parameters are not allowed, such as: List > which instead should be: List> 2. The use of the 'NULL' macro should be replaced by 'nullptr' --- bin/tools/pre-commit-hook | 55 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/bin/tools/pre-commit-hook b/bin/tools/pre-commit-hook index d3bf374e0..f3a0b57a1 100755 --- a/bin/tools/pre-commit-hook +++ b/bin/tools/pre-commit-hook @@ -3,7 +3,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation +# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\/ M anipulation | #------------------------------------------------------------------------------ # License @@ -48,11 +48,14 @@ # test the specified files/directories for standards conformance. # #------------------------------------------------------------------------------ + hookName="pre-commit" +headerSeparator="-----------------------------------" + die() { echo "$hookName hook failure" 1>&2 - echo '-----------------------------------' 1>&2 + echo $headerSeparator 1>&2 echo '' 1>&2 echo "$@" 1>&2 echo '' 1>&2 @@ -105,7 +108,7 @@ dieOnBadFiles() if [ -n "$badFiles" ] then echo "$hookName hook failure" 1>&2 - echo '-----------------------------------' 1>&2 + echo $headerSeparator 1>&2 echo "$@" 1>&2 echo '' 1>&2 echo "File(s):" 1>&2 @@ -267,6 +270,49 @@ checkLineLengthNonDirective() } +# +# check for non-standard code patterns +# +checkNonStandardCodePatterns() +{ + echo "$hookName: checking for non-standard code ..." 1>&2 + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # Directly report the incorrect markers + git grep -n --color \ + -e '> >' -e 'NULL' \ + $scope"$f" + ;; + esac + done + ) + + dieOnBadFiles "$(cat< > + + which instead should be: + + List> + + 2. The use of the 'NULL' macro should be replaced by 'nullptr' + +$headerSeparator +MESSAGE + )" +} + + # # check that OpenFOAM Foundation copyright is current # @@ -322,6 +368,9 @@ checkIllegalCode # ensure code conforms to 80 columns max checkLineLengthNonDirective +# check for non-standard code patterns +checkNonStandardCodePatterns + checkCopyright exit 0