mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: drop special treatment for C++ comments line length in pre-commit-hook
ENH: report line number for illegal words and for copyrights
This commit is contained in:
@ -70,10 +70,13 @@ fi
|
|||||||
fileList=$(git diff-index --name-only $against --)
|
fileList=$(git diff-index --name-only $against --)
|
||||||
unset badFiles
|
unset badFiles
|
||||||
|
|
||||||
# join badFiles with this amount of space
|
# join list of files with this amount of space
|
||||||
Indent=" "
|
Indent=" "
|
||||||
|
|
||||||
reportBadFiles()
|
#
|
||||||
|
# report bad files and die if there are any
|
||||||
|
#
|
||||||
|
dieOnBadFiles()
|
||||||
{
|
{
|
||||||
if [ -n "$badFiles" ]
|
if [ -n "$badFiles" ]
|
||||||
then
|
then
|
||||||
@ -88,14 +91,15 @@ reportBadFiles()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# check for bad characters or strings
|
# check for bad characters or strings
|
||||||
#
|
#
|
||||||
checkIllegalCode()
|
checkIllegalCode()
|
||||||
{
|
{
|
||||||
badWords=("[N]abla" $'\t')
|
badWords=("[N]abla" $'\t')
|
||||||
badMsg=("nabla" "<TAB>")
|
badMsg=("NABLA" "<TAB>")
|
||||||
nWords=${#badWords[@]};
|
nWords=${#badWords[@]}
|
||||||
|
|
||||||
for (( i = 0; i < $nWords; i++ ))
|
for (( i = 0; i < $nWords; i++ ))
|
||||||
do
|
do
|
||||||
@ -104,15 +108,17 @@ checkIllegalCode()
|
|||||||
badFiles=$(
|
badFiles=$(
|
||||||
for f in $fileList
|
for f in $fileList
|
||||||
do
|
do
|
||||||
git grep -q --cached -e "$illegal" -- "$f" && \
|
# parse line numbers from this:
|
||||||
echo "$Indent$f"
|
# path/fileName:<lineNr>: contents
|
||||||
|
lines=$(git grep --cached -n -e "$illegal" -- "$f" |
|
||||||
|
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)
|
||||||
|
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ -n "$badFiles" ]
|
dieOnBadFiles "Remove/correct bad '${badMsg[$i]}' references"
|
||||||
then
|
|
||||||
reportBadFiles "Remove/correct bad '${badMsg[$i]}' references"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,23 +133,25 @@ checkCopyright()
|
|||||||
badFiles=$(
|
badFiles=$(
|
||||||
for f in $fileList
|
for f in $fileList
|
||||||
do
|
do
|
||||||
copyright=$(git grep --cached -e Copyright -- "$f" | grep OpenCFD)
|
# parse line numbers from this:
|
||||||
if [ -n "$copyright" ]
|
# path/fileName:<lineNr>: contents
|
||||||
then
|
# for Copyright lines without the current year
|
||||||
echo "$copyright" | grep -q "$year" || echo "$Indent$f"
|
lines=$(git grep --cached -n -e Copyright -- "$f" |
|
||||||
fi
|
sed -n \
|
||||||
|
-e "/OpenCFD/{ /$year/b;" \
|
||||||
|
-e 's@^[^:]*:\([0-9]*\):.*@\1@p }' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)
|
||||||
|
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
|
||||||
reportBadFiles "Update copyright year, e.g. XXXX-$year"
|
dieOnBadFiles "Update copyright year, e.g. XXXX-$year"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# limit line length to 80-columns, except C++ comment lines
|
# limit line length to 80-columns
|
||||||
# parses
|
|
||||||
# path/fileName:<lineNr>: contents
|
|
||||||
# and extracts line numbers for non-comment lines
|
|
||||||
#
|
#
|
||||||
checkLineLength()
|
checkLineLength()
|
||||||
{
|
{
|
||||||
@ -153,7 +161,36 @@ checkLineLength()
|
|||||||
# limit to *.[CH] files
|
# limit to *.[CH] files
|
||||||
case "$f" in
|
case "$f" in
|
||||||
(*.[CH])
|
(*.[CH])
|
||||||
lines=$(git grep -n --cached -e ".\{81,\}" -- "$f" |
|
# parse line numbers from this:
|
||||||
|
# path/fileName:<lineNr>: contents
|
||||||
|
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" |
|
||||||
|
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)
|
||||||
|
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
)
|
||||||
|
|
||||||
|
dieOnBadFiles "Limit code to 80 columns before pushing"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# limit line length to 80-columns, except C++ comment lines
|
||||||
|
#
|
||||||
|
checkLineLengthNonComments()
|
||||||
|
{
|
||||||
|
badFiles=$(
|
||||||
|
for f in $fileList
|
||||||
|
do
|
||||||
|
# limit to *.[CH] files
|
||||||
|
case "$f" in
|
||||||
|
(*.[CH])
|
||||||
|
# parse line numbers from this (strip comment lines):
|
||||||
|
# path/fileName:<lineNr>: contents
|
||||||
|
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" |
|
||||||
sed -n \
|
sed -n \
|
||||||
-e '\@^[^:]*:[^:]*: *//.*@b' \
|
-e '\@^[^:]*:[^:]*: *//.*@b' \
|
||||||
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' |
|
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' |
|
||||||
@ -164,15 +201,17 @@ checkLineLength()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
reportBadFiles "Limit code to 80 columns before pushing"
|
|
||||||
|
dieOnBadFiles "Limit code to 80 columns before pushing"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# do all checks
|
# do all checks
|
||||||
#~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~
|
||||||
|
|
||||||
# builtin whitespace check to avoid trailing space, including CR-LF endings
|
# builtin whitespace check to avoid trailing space, including CR-LF endings
|
||||||
bad=$(git diff-index --check --cached $against --) || die "$bad"
|
bad=$(git diff-index --cached --check $against --) || die "$bad"
|
||||||
|
|
||||||
# check for illegal code, e.g. <TAB>, etc
|
# check for illegal code, e.g. <TAB>, etc
|
||||||
checkIllegalCode
|
checkIllegalCode
|
||||||
@ -183,4 +222,6 @@ checkCopyright
|
|||||||
# ensure code conforms to 80 columns max
|
# ensure code conforms to 80 columns max
|
||||||
checkLineLength
|
checkLineLength
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user