1
0
mirror of https://github.com/coreos/fedora-coreos-config.git synced 2026-02-05 09:45:30 +01:00

ci/find-whitespace: Check for missing EOL at EOF

Rework the find-whitespace CI script to check more files and also check
for missing end of line at the end of files.

See: https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file
See: https://stackoverflow.com/questions/4631068/how-do-i-find-files-that-do-not-end-with-a-newline-linefeed
This commit is contained in:
Timothée Ravier
2024-04-11 13:32:37 +02:00
parent 5ad17bebba
commit 7c364a8d70

View File

@@ -3,16 +3,62 @@
set -euo pipefail
main() {
local files_with_whitespace
files_with_whitespace="$(find manifests overlay.d tests -type f -exec grep -El " +$" {} \;)"
local files_with_whitespace=""
local files_with_missing_empty_line_at_eof=""
while IFS= read -r -d '' f; do
echo "[+] Checking ${f}"
# Looking for whitespace at end of line
if grep -Eq " +$" "${f}"; then
# List of files to ignore
if \
[[ "${f}" == "./live/isolinux/boot.msg" ]] \
; then
echo "[+] Checking ${f}: Ignoring whitespace at end of line"
else
echo "[+] Checking ${f}: Found whitespace at end of line"
files_with_whitespace+=" ${f}"
fi
fi
# Looking for missing empty line at end of file
if [[ -n $(tail -c 1 "${f}") ]]; then
# List of files to ignore
if \
[[ "${f}" == "./tests/kola/ignition/resource/authenticated-gs/data/expected/"* ]] ||\
[[ "${f}" == "./tests/kola/ignition/resource/authenticated-s3/data/expected/"* ]] ||\
[[ "${f}" == "./tests/kola/ignition/resource/remote/data/expected/"* ]] \
; then
echo "[+] Checking ${f}: Ignoring missing empty line at end of file"
else
echo "[+] Checking ${f}: Missing empty line at end of file"
files_with_missing_empty_line_at_eof+=" ${f}"
fi
fi
done< <(find . -path "./.git" -prune -o -type f -print0)
echo ""
if [[ -n "${files_with_whitespace}" ]]; then
echo "[+] Found files with whitespace at the end of line"
echo "${files_with_whitespace}"
echo "${files_with_whitespace}" | tr ' ' '\n'
else
echo "[+] No files with whitespace at the end of line"
fi
echo ""
if [[ -n "${files_with_missing_empty_line_at_eof}" ]]; then
echo "[+] Found files with missing empty line at end of file"
echo "${files_with_missing_empty_line_at_eof}" | tr ' ' '\n'
else
echo "[+] No files with missing empty line at end of file"
fi
if [[ -n "${files_with_whitespace}" ]] || [[ -n "${files_with_missing_empty_line_at_eof}" ]]; then
exit 1
fi
echo "[+] No files with whitespace at the end of line"
exit 0
}