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>
35 lines
769 B
Bash
Executable File
35 lines
769 B
Bash
Executable File
#!/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
|