mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Meta: Add a script that makes sure files end in a newline.
This script checks .html, .css, .js, .cpp, .h, .gml and .sh files. It also makes sure that there are no black lines at the end of the files checked.
This commit is contained in:
parent
c49899b0b6
commit
f9f571aa7f
42
Meta/check-newlines-at-eof.sh
Executable file
42
Meta/check-newlines-at-eof.sh
Executable file
|
@ -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"
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in a new issue