n2n/scripts/indent.sh

62 lines
1.2 KiB
Bash
Raw Normal View History

Basic C Code lint checker and shell checker (#859) * Factor build packages out into a more maintainable list * Create a location for scripts to live * Provide a make target to return the source dir as close as reasonable to the original distributed state * Add a code lint step, checking the coding style * Change test harness as recommended by shellcheck * Ensure we actually have the linter tool installed * Use the correct directory for cmake to run the tests * Adjust for the older uncrustify in the current github ubuntu-latest * Make one file pass the linter * Integrate the lint with the existing test workflow * Add files with minimal changes needed to the linter * Add more files with minimal changes needed to the linter * Dont build binaries if we fail the lint test * Update the phony targets with the lint steps * Ensure the flake8 package is installed in the new lint workflow job * Use the makefile to drive the packages needed to install for linting * No need to add dependancies on lint, just rely on the workflow status to show failure * Update the scripts dir README to reflect current assumptions * Rename and briefly document the indent.sh script * Fix the ignore to ignore the right Makefile * Rename the test_harness script to make it clear it is a shell script * Provide a master lint make target and add a shell script lint tool * Elminate stray tabs * Drop include/auth.h from linter - there are inconsistant results with function definitions when using the current uncrustify rules
2021-10-23 21:36:18 +02:00
#!/bin/sh
#
# Given one or more input source files, run a re-indenter on them.
help() {
echo "Usage: scripts/indent [-i] [file...]"
echo " -i modify file in place with reindent results"
echo ""
echo "By default, will output a diff and exitcode if changed are needed"
echo "If modifying files, no exit code or diff is output"
exit 1
}
[ -z "$1" ] && help
[ "$1" = "-h" ] && help
[ "$1" = "--help" ] && help
Basic C Code lint checker and shell checker (#859) * Factor build packages out into a more maintainable list * Create a location for scripts to live * Provide a make target to return the source dir as close as reasonable to the original distributed state * Add a code lint step, checking the coding style * Change test harness as recommended by shellcheck * Ensure we actually have the linter tool installed * Use the correct directory for cmake to run the tests * Adjust for the older uncrustify in the current github ubuntu-latest * Make one file pass the linter * Integrate the lint with the existing test workflow * Add files with minimal changes needed to the linter * Add more files with minimal changes needed to the linter * Dont build binaries if we fail the lint test * Update the phony targets with the lint steps * Ensure the flake8 package is installed in the new lint workflow job * Use the makefile to drive the packages needed to install for linting * No need to add dependancies on lint, just rely on the workflow status to show failure * Update the scripts dir README to reflect current assumptions * Rename and briefly document the indent.sh script * Fix the ignore to ignore the right Makefile * Rename the test_harness script to make it clear it is a shell script * Provide a master lint make target and add a shell script lint tool * Elminate stray tabs * Drop include/auth.h from linter - there are inconsistant results with function definitions when using the current uncrustify rules
2021-10-23 21:36:18 +02:00
INPLACE=0
if [ "$1" = "-i" ]; then
shift
INPLACE=1
fi
## indentOneClang() {
## rm -f "$1.indent"
## clang-format "$1" >"$1.indent"
## if [ $? -ne 0 ]; then
## echo "Error while formatting \"$1\""
## RESULT=1
## return
## fi
## diff -u "$1" "$1.indent"
## if [ $? -ne 0 ]; then
## RESULT=1
## fi
## }
indentOne() {
IFILE="$1"
if [ "$INPLACE" -eq 0 ]; then
OFILE="$1.indent"
rm -f "$OFILE"
else
OFILE="$1"
fi
if ! uncrustify -c uncrustify.cfg -f "$IFILE" -o "$OFILE"; then
echo "Error while formatting \"$1\""
RESULT=1
return
fi
if ! diff -u "$IFILE" "$OFILE"; then
RESULT=1
fi
}
RESULT=0
while [ -n "$1" ]; do
indentOne "$1"
shift
done
exit $RESULT