mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00

Ensure that no source files have trailing whitespace at end of lines and ensure that all files end with a single trailing newline. This also adds Github Actions to enforce whitespace conventions.
38 lines
604 B
Bash
Executable File
38 lines
604 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Verify that all text files end in a trailing newline.
|
|
|
|
# Exit on first failing command.
|
|
set -e
|
|
|
|
# Exit on unset variable.
|
|
set -u
|
|
|
|
success=0
|
|
|
|
function is_plaintext_file() {
|
|
local file="$1"
|
|
if [[ $file == *.svg ]]; then
|
|
echo ""
|
|
return
|
|
fi
|
|
file --brief "${file}" | grep text
|
|
}
|
|
|
|
# Split strings on newlines.
|
|
IFS='
|
|
'
|
|
for file in $(git ls-files)
|
|
do
|
|
if [[ -z $(is_plaintext_file "${file}") ]]; then
|
|
continue
|
|
fi
|
|
|
|
if ! [[ -z "$(tail -c 1 "${file}")" ]]; then
|
|
printf "File must end in a trailing newline: %s\n" "${file}" >&2
|
|
success=255
|
|
fi
|
|
done
|
|
|
|
exit "${success}"
|