Files
yait/tools/Cleanup
2025-07-21 20:55:20 -04:00

44 lines
965 B
Bash
Executable File

#!/bin/env bash
# Usage: ./Cleanup [FILE]...
make dist-clean
lint_file() {
local output
output=$(clang-tidy "$1" 2>&1 | grep -v -E 'Error while trying to load a compilation database|No compilation database found|fixed-compilation-database:|json-compilation-database:|Running without flags.')
if [[ -n "$output" ]]; then
echo "[LINT] $1:"
echo "$output"
fi
}
whitespace_cleanup() {
sed -i 's/[ \t]*$//' "$1"
awk 'BEGIN{ORS=""} {print $0 "\n"} END{}' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
}
comment_check() {
if grep -n -E 'TODO|FIXME' "$1"; then
echo "[WARN] $1 contains TODO/FIXME comments."
fi
}
process_file() {
clang-format -i "$1"
tools/check_header_footer "$1"
lint_file "$1"
whitespace_cleanup "$1"
comment_check "$1"
}
if [[ $# -gt 0 ]]; then
for file in "$@"; do
process_file "$file"
done
else
for file in $(find yait core -type f \( -name "*.c" -o -name "*.h" \)); do
process_file "$file"
done
fi