AdGuardHome/scripts/make/txt-lint.sh

81 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/sh
2023-03-09 15:39:35 +03:00
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a remarkable change is made to this script.
#
2023-09-07 17:13:48 +03:00
# AdGuard-Project-Version: 5
2023-03-09 15:39:35 +03:00
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '0' ]
then
set -x
fi
# Set $EXIT_ON_ERROR to zero to see all errors.
if [ "${EXIT_ON_ERROR:-1}" -eq '0' ]
then
set +e
else
set -e
fi
# We don't need glob expansions and we want to see errors about unset variables.
set -f -u
2023-03-09 15:39:35 +03:00
# Source the common helpers, including not_found.
. ./scripts/make/helper.sh
2023-04-12 14:48:42 +03:00
# Simple analyzers
# trailing_newlines is a simple check that makes sure that all plain-text files
# have a trailing newlines to make sure that all tools work correctly with them.
2023-09-07 17:13:48 +03:00
trailing_newlines() (
2023-04-12 14:48:42 +03:00
nl="$( printf "\n" )"
readonly nl
2023-04-18 16:07:11 +03:00
# NOTE: Adjust for your project.
2023-04-12 14:48:42 +03:00
git ls-files\
':!*.png'\
':!*.tar.gz'\
':!*.zip'\
| while read -r f
do
2023-09-07 17:13:48 +03:00
final_byte="$( tail -c -1 "$f" )"
if [ "$final_byte" != "$nl" ]
2023-04-12 14:48:42 +03:00
then
printf '%s: must have a trailing newline\n' "$f"
fi
done
2023-09-07 17:13:48 +03:00
)
# trailing_whitespace is a simple check that makes sure that there are no
# trailing whitespace in plain-text files.
trailing_whitespace() {
# NOTE: Adjust for your project.
git ls-files\
':!*.bmp'\
':!*.jpg'\
':!*.mmdb'\
':!*.png'\
':!*.svg'\
':!*.tar.gz'\
':!*.webp'\
':!*.zip'\
| while read -r f
do
grep -e '[[:space:]]$' -n -- "$f"\
| sed -e "s:^:${f}\::" -e 's/ \+$/>>>&<<</'
done
2023-04-12 14:48:42 +03:00
}
run_linter -e trailing_newlines
2023-09-07 17:13:48 +03:00
run_linter -e trailing_whitespace
git ls-files -- '*.conf' '*.md' '*.txt' '*.yaml' '*.yml'\
'client/src/__locales/en.json'\
2023-03-09 15:39:35 +03:00
| xargs misspell --error\
| sed -e 's/^/misspell: /'