2021-05-19 18:31:20 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-02-21 13:38:22 +00: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.
|
|
|
|
#
|
2024-11-08 14:18:16 +00:00
|
|
|
# AdGuard-Project-Version: 8
|
2023-02-21 13:38:22 +00:00
|
|
|
|
2021-05-19 18:31:20 +01:00
|
|
|
verbose="${VERBOSE:-0}"
|
|
|
|
readonly verbose
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
if [ "$verbose" -gt '0' ]; then
|
2021-05-19 18:31:20 +01:00
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set $EXIT_ON_ERROR to zero to see all errors.
|
2024-11-08 14:18:16 +00:00
|
|
|
if [ "${EXIT_ON_ERROR:-1}" -eq '0' ]; then
|
2021-05-19 18:31:20 +01:00
|
|
|
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-02-21 13:38:22 +00:00
|
|
|
# Source the common helpers, including not_found.
|
|
|
|
. ./scripts/make/helper.sh
|
2021-05-19 18:31:20 +01:00
|
|
|
|
2023-04-06 12:21:46 +01: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 13:05:21 +01:00
|
|
|
trailing_newlines() (
|
2024-11-08 14:18:16 +00:00
|
|
|
nl="$(printf '\n')"
|
2023-04-06 12:21:46 +01:00
|
|
|
readonly nl
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
find . \
|
|
|
|
-type 'f' \
|
|
|
|
'!' '(' \
|
|
|
|
-name '*.db' \
|
|
|
|
-o -name '*.exe' \
|
|
|
|
-o -name '*.out' \
|
|
|
|
-o -name '*.png' \
|
|
|
|
-o -name '*.svg' \
|
|
|
|
-o -name '*.tar.gz' \
|
|
|
|
-o -name '*.test' \
|
|
|
|
-o -name '*.zip' \
|
|
|
|
-o -name 'AdGuardHome' \
|
|
|
|
-o -name 'adguard-home' \
|
|
|
|
-o -path '*/node_modules/*' \
|
|
|
|
-o -path './.git/*' \
|
|
|
|
-o -path './bin/*' \
|
|
|
|
-o -path './build/*' \
|
|
|
|
')' \
|
|
|
|
| while read -r f; do
|
|
|
|
final_byte="$(tail -c -1 "$f")"
|
|
|
|
if [ "$final_byte" != "$nl" ]; then
|
2023-04-06 12:21:46 +01:00
|
|
|
printf '%s: must have a trailing newline\n' "$f"
|
|
|
|
fi
|
|
|
|
done
|
2023-09-07 13:05:21 +01:00
|
|
|
)
|
2023-04-06 12:21:46 +01:00
|
|
|
|
2023-08-23 18:10:54 +01:00
|
|
|
# trailing_whitespace is a simple check that makes sure that there are no
|
|
|
|
# trailing whitespace in plain-text files.
|
|
|
|
trailing_whitespace() {
|
2024-11-08 14:18:16 +00:00
|
|
|
find . \
|
|
|
|
-type 'f' \
|
|
|
|
'!' '(' \
|
|
|
|
-name '*.db' \
|
|
|
|
-o -name '*.exe' \
|
|
|
|
-o -name '*.out' \
|
|
|
|
-o -name '*.png' \
|
|
|
|
-o -name '*.svg' \
|
|
|
|
-o -name '*.tar.gz' \
|
|
|
|
-o -name '*.test' \
|
|
|
|
-o -name '*.zip' \
|
|
|
|
-o -name 'AdGuardHome' \
|
|
|
|
-o -name 'adguard-home' \
|
|
|
|
-o -path '*/node_modules/*' \
|
|
|
|
-o -path './.git/*' \
|
|
|
|
-o -path './bin/*' \
|
|
|
|
-o -path './build/*' \
|
|
|
|
')' \
|
|
|
|
| while read -r f; do
|
|
|
|
grep -e '[[:space:]]$' -n -- "$f" \
|
2023-08-23 18:10:54 +01:00
|
|
|
| sed -e "s:^:${f}\::" -e 's/ \+$/>>>&<<</'
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-04-06 12:21:46 +01:00
|
|
|
run_linter -e trailing_newlines
|
|
|
|
|
2023-08-23 18:10:54 +01:00
|
|
|
run_linter -e trailing_whitespace
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
find . \
|
|
|
|
-type 'f' \
|
|
|
|
'!' '(' \
|
|
|
|
-path '*/node_modules/*' \
|
|
|
|
-o -path './data/filters/*' \
|
|
|
|
')' \
|
|
|
|
'(' \
|
|
|
|
-name 'Makefile' \
|
|
|
|
-o -name '*.conf' \
|
|
|
|
-o -name '*.md' \
|
|
|
|
-o -name '*.txt' \
|
|
|
|
-o -name '*.yaml' \
|
|
|
|
-o -name '*.yml' \
|
|
|
|
')' \
|
|
|
|
-exec 'misspell' '--error' '{}' '+'
|