diff --git a/Meta/check-newlines-at-eof.sh b/Meta/check-newlines-at-eof.sh new file mode 100755 index 0000000000..77147e6282 --- /dev/null +++ b/Meta/check-newlines-at-eof.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +cd "$script_path/.." || exit 1 + +MISSING_NEWLINE_AT_EOF_ERRORS=() +MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS=() + +while IFS= read -r f; do + [ -s "$f" ] || continue + + if [ "$(tail -n 1 "$f" | wc -l)" != 1 ]; then + MISSING_NEWLINE_AT_EOF_ERRORS+=( "$f" ) + elif [[ "$(tail -n 1 "$f")" =~ ^[[:space:]]*$ ]]; then + MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS+=( "$f" ) + fi +done < <(git ls-files -- \ + '*.cpp' \ + '*.h' \ + '*.gml' \ + '*.html' \ + '*.js' \ + '*.css' \ + '*.sh' \ + ':!:Base' \ + ':!:Kernel/FileSystem/ext2_fs.h' \ + ':!:Libraries/LibC/getopt.cpp' \ + ':!:Libraries/LibCore/puff.h' \ + ':!:Libraries/LibCore/puff.cpp' \ + ':!:Libraries/LibELF/exec_elf.h' \ +) + +exit_status=0 +if (( ${#MISSING_NEWLINE_AT_EOF_ERRORS[@]} )); then + echo "Files with no newline at the end: ${MISSING_NEWLINE_AT_EOF_ERRORS[*]}" + exit_status=1 +fi +if (( ${#MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS[@]} )); then + echo "Files that have blank lines at the end: ${MORE_THAN_ONE_NEWLINE_AT_EOF_ERRORS[*]}" + exit_status=1 +fi +exit "$exit_status" diff --git a/Meta/lint-ci.sh b/Meta/lint-ci.sh index 746b1365a3..724bcc0f15 100755 --- a/Meta/lint-ci.sh +++ b/Meta/lint-ci.sh @@ -16,6 +16,7 @@ set +e for cmd in \ Meta/check-ak-test-files.sh \ Meta/check-debug-flags.sh \ + Meta/check-newlines-at-eof.sh \ Meta/check-style.sh \ Meta/lint-executable-resources.sh \ Meta/lint-ipc-ids.sh \