mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-01 18:37:42 -05:00
Normalize whitespace in source files
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.
This commit is contained in:
37
.github/workflow-scripts/check-trailing-newline
vendored
Executable file
37
.github/workflow-scripts/check-trailing-newline
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/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}"
|
Reference in New Issue
Block a user