mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 04:55:33 +03:00
c3edab4387
Merge in DNS/adguard-home from AG-20200-translation-script to master Squashed commit of the following: commit 3113b77c0312219f8134324caa232a53c42a3988 Merge: bbd784abf736d85e
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 17:41:08 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit bbd784ab817955f3342d140644a3199d558c22b8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 13:23:48 2023 +0300 scripts: imp code commit 7d379ab1fc2ae9858f8e7e3754de9be3d23153b6 Merge: 4f6278ad1daabb97
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 12:01:16 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit 4f6278adb28287205a4fc89239e7ba776a15ff7a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 17 14:27:32 2023 +0300 scripts: imp error handling commit 64e307a591cfeac1986d477a55bcc714636663bc Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 15:41:39 2023 +0300 scripts: imp code commit fe06df88f2bb3fc0de83f83deea26652485a22d4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 15:23:20 2023 +0300 scripts: add docs commit 15d65a075373586fc31a595d7c831b80752d7cf2 Merge: ddd3cacd9f7a582d
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 13:04:16 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit ddd3cacd507ca861c4d9d5f7600bdcc2c3068315 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Mar 16 13:03:11 2023 +0300 scripts: imp code commit 4e8ebdc199f0c0ff4e7c7b8ae71483cca6c4d428 Merge: 73fedefac6706445
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:25:36 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit 73fedefa4ceaf2273648afe5816f1903d96ba213 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 15 12:25:04 2023 +0300 scripts: fix chlog commit 780b0a257b6b2e684cfe8a49e4c4d22bcd4056ec Merge: ef70d192595484e0
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 14 14:58:24 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit ef70d192555a9ef2acd6dd1caeb4f05a10a1de63 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 14 14:57:36 2023 +0300 scripts: upd readme commit e28655826c8c5ce6ddf3cc904201681286a6be87 Merge: cae3b769a2053526
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 13 14:28:47 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit cae3b769dfa6906653b32104169ae4a08a2c3723 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 13 14:27:29 2023 +0300 scripts: rm translations js commit 77e2e3480b52a70b8ef9be8f1edf581cca2a1a3a Merge: 99e2382ac11a52d6
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 7 16:04:06 2023 +0300 Merge branch 'master' into AG-20200-translation-script commit 99e2382a161dee0bff30ae488d8b42565330d82e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 7 16:03:19 2023 +0300 scripts: add translations go
210 lines
4.5 KiB
Bash
210 lines
4.5 KiB
Bash
#!/bin/sh
|
|
|
|
# This comment is used to simplify checking local copies of the script. Bump
|
|
# this number every time a significant change is made to this script.
|
|
#
|
|
# AdGuard-Project-Version: 3
|
|
|
|
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
|
|
|
|
set -f -u
|
|
|
|
|
|
|
|
# Source the common helpers, including not_found and run_linter.
|
|
. ./scripts/make/helper.sh
|
|
|
|
|
|
|
|
# Warnings
|
|
|
|
go_version="$( "${GO:-go}" version )"
|
|
readonly go_version
|
|
|
|
go_min_version='go1.19.7'
|
|
go_version_msg="
|
|
warning: your go version (${go_version}) is different from the recommended minimal one (${go_min_version}).
|
|
if you have the version installed, please set the GO environment variable.
|
|
for example:
|
|
|
|
export GO='${go_min_version}'
|
|
"
|
|
readonly go_min_version go_version_msg
|
|
|
|
case "$go_version"
|
|
in
|
|
('go version'*"$go_min_version"*)
|
|
# Go on.
|
|
;;
|
|
(*)
|
|
echo "$go_version_msg" 1>&2
|
|
;;
|
|
esac
|
|
|
|
|
|
|
|
# Simple analyzers
|
|
|
|
# blocklist_imports is a simple check against unwanted packages. The following
|
|
# packages are banned:
|
|
#
|
|
# * Packages errors and log are replaced by our own packages in the
|
|
# github.com/AdguardTeam/golibs module.
|
|
#
|
|
# * Package io/ioutil is soft-deprecated.
|
|
#
|
|
# * Package reflect is often an overkill, and for deep comparisons there are
|
|
# much better functions in module github.com/google/go-cmp. Which is
|
|
# already our indirect dependency and which may or may not enter the stdlib
|
|
# at some point.
|
|
#
|
|
# See https://github.com/golang/go/issues/45200.
|
|
#
|
|
# * Package sort is replaced by golang.org/x/exp/slices.
|
|
#
|
|
# * Package unsafe is… unsafe.
|
|
#
|
|
# * Package golang.org/x/net/context has been moved into stdlib.
|
|
#
|
|
blocklist_imports() {
|
|
git grep\
|
|
-e '[[:space:]]"errors"$'\
|
|
-e '[[:space:]]"io/ioutil"$'\
|
|
-e '[[:space:]]"log"$'\
|
|
-e '[[:space:]]"reflect"$'\
|
|
-e '[[:space:]]"sort"$'\
|
|
-e '[[:space:]]"unsafe"$'\
|
|
-e '[[:space:]]"golang.org/x/net/context"$'\
|
|
-n\
|
|
-- '*.go'\
|
|
| sed -e 's/^\([^[:space:]]\+\)\(.*\)$/\1 blocked import:\2/'\
|
|
|| exit 0
|
|
}
|
|
|
|
# method_const is a simple check against the usage of some raw strings and
|
|
# numbers where one should use named constants.
|
|
method_const() {
|
|
git grep -F\
|
|
-e '"DELETE"'\
|
|
-e '"GET"'\
|
|
-e '"POST"'\
|
|
-e '"PUT"'\
|
|
-n\
|
|
-- '*.go'\
|
|
| sed -e 's/^\([^[:space:]]\+\)\(.*\)$/\1 http method literal:\2/'\
|
|
|| exit 0
|
|
}
|
|
|
|
# underscores is a simple check against Go filenames with underscores. Add new
|
|
# build tags and OS as you go. The main goal of this check is to discourage the
|
|
# use of filenames like client_manager.go.
|
|
underscores() {
|
|
underscore_files="$(
|
|
git ls-files '*_*.go'\
|
|
| grep -F\
|
|
-e '_big.go'\
|
|
-e '_bsd.go'\
|
|
-e '_darwin.go'\
|
|
-e '_freebsd.go'\
|
|
-e '_linux.go'\
|
|
-e '_little.go'\
|
|
-e '_next.go'\
|
|
-e '_openbsd.go'\
|
|
-e '_others.go'\
|
|
-e '_test.go'\
|
|
-e '_unix.go'\
|
|
-e '_windows.go' \
|
|
-v\
|
|
| sed -e 's/./\t\0/'
|
|
)"
|
|
readonly underscore_files
|
|
|
|
if [ "$underscore_files" != '' ]
|
|
then
|
|
echo 'found file names with underscores:'
|
|
echo "$underscore_files"
|
|
fi
|
|
}
|
|
|
|
# TODO(a.garipov): Add an analyzer to look for `fallthrough`, `goto`, and `new`?
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
run_linter -e blocklist_imports
|
|
|
|
run_linter -e method_const
|
|
|
|
run_linter -e underscores
|
|
|
|
run_linter -e gofumpt --extra -e -l .
|
|
|
|
# TODO(a.garipov): golint is deprecated, find a suitable replacement.
|
|
|
|
run_linter "$GO" vet ./...
|
|
|
|
run_linter govulncheck ./...
|
|
|
|
# Apply more lax standards to the code we haven't properly refactored yet.
|
|
run_linter gocyclo --over 14 ./internal/querylog/
|
|
run_linter gocyclo --over 13\
|
|
./internal/dhcpd\
|
|
./internal/home/\
|
|
;
|
|
|
|
# Apply the normal standards to new or somewhat refactored code.
|
|
run_linter gocyclo --over 10\
|
|
./internal/aghio/\
|
|
./internal/aghnet/\
|
|
./internal/aghos/\
|
|
./internal/aghtest/\
|
|
./internal/dnsforward/\
|
|
./internal/filtering/\
|
|
./internal/stats/\
|
|
./internal/tools/\
|
|
./internal/updater/\
|
|
./internal/next/\
|
|
./internal/version/\
|
|
./scripts/blocked-services/\
|
|
./scripts/vetted-filters/\
|
|
./scripts/translations/\
|
|
./main.go\
|
|
;
|
|
|
|
run_linter ineffassign ./...
|
|
|
|
run_linter unparam ./...
|
|
|
|
git ls-files -- 'Makefile' '*.go' '*.mod' '*.sh' '*.yaml' '*.yml'\
|
|
| xargs misspell --error
|
|
|
|
run_linter looppointer ./...
|
|
|
|
run_linter nilness ./...
|
|
|
|
# TODO(a.garipov): Add fieldalignment?
|
|
|
|
run_linter -e shadow --strict ./...
|
|
|
|
# TODO(a.garipov): Enable in v0.108.0.
|
|
# run_linter gosec --quiet ./...
|
|
|
|
# TODO(a.garipov): Enable --blank?
|
|
run_linter errcheck --asserts ./...
|
|
|
|
run_linter staticcheck ./...
|