scripts: Rewrite lint scripts

Rewrite lint scripts to report what they do and if they pass. In the
case they fail list the files that caused the failure, except for
clang-format, which will be slow to run of every file individually
(should just run `make fmt` anyway). Also add a script to run all the
lints in order with a single command.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-01-09 10:38:48 -07:00
committed by Jeremy Soller
parent b03c960b4f
commit 1aadc68257
8 changed files with 127 additions and 51 deletions

34
scripts/lint/02-clang-format.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# Check if any C files or headers need to be formatted.
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
. "$LINT_DIR/util.sh"
echo -n "Checking C style..."
if ! command -v clang-format > /dev/null; then
skipped "clang-format not found"
exit 0
fi
readarray -t FILES < <(git ls-files '*.c' '*.h')
FMT_OPTS=(
"-style=file"
"--fallback-style=none"
"--dry-run"
"--Werror"
)
# NOTE: It is too slow to run clang-format on every file individually to report
# which ones fail. Leave it up to the user to apply formatting via `make fmt`.
_output=$(clang-format "${FMT_OPTS[@]}" "${FILES[@]}" 2>&1)
if [[ $_output != "" ]]; then
failed
exit 1
fi
passed