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<List<scalar> >

     which instead should be:

       List<List<scalar>>

   2. The use of the 'NULL' macro should be replaced by 'nullptr'
This commit is contained in:
Henry Weller
2016-09-25 18:43:50 +01:00
parent a96b1c2325
commit f8d3a2a0a6

View File

@ -3,7 +3,7 @@
# ========= | # ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
@ -48,11 +48,14 @@
# test the specified files/directories for standards conformance. # test the specified files/directories for standards conformance.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
hookName="pre-commit" hookName="pre-commit"
headerSeparator="-----------------------------------"
die() die()
{ {
echo "$hookName hook failure" 1>&2 echo "$hookName hook failure" 1>&2
echo '-----------------------------------' 1>&2 echo $headerSeparator 1>&2
echo '' 1>&2 echo '' 1>&2
echo "$@" 1>&2 echo "$@" 1>&2
echo '' 1>&2 echo '' 1>&2
@ -105,7 +108,7 @@ dieOnBadFiles()
if [ -n "$badFiles" ] if [ -n "$badFiles" ]
then then
echo "$hookName hook failure" 1>&2 echo "$hookName hook failure" 1>&2
echo '-----------------------------------' 1>&2 echo $headerSeparator 1>&2
echo "$@" 1>&2 echo "$@" 1>&2
echo '' 1>&2 echo '' 1>&2
echo "File(s):" 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<<MESSAGE
Please revise the files reported below for the following non-standard code:
1. Spaced ending of multi-level template parameters are not allowed, such as:
List<List<scalar> >
which instead should be:
List<List<scalar>>
2. The use of the 'NULL' macro should be replaced by 'nullptr'
$headerSeparator
MESSAGE
)"
}
# #
# check that OpenFOAM Foundation copyright is current # check that OpenFOAM Foundation copyright is current
# #
@ -322,6 +368,9 @@ checkIllegalCode
# ensure code conforms to 80 columns max # ensure code conforms to 80 columns max
checkLineLengthNonDirective checkLineLengthNonDirective
# check for non-standard code patterns
checkNonStandardCodePatterns
checkCopyright checkCopyright
exit 0 exit 0