mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-21 20:45:33 +03:00
cherry-pick: scripts: imp sh lint
This commit is contained in:
parent
de1a7ce48f
commit
e28186a28a
1 changed files with 52 additions and 35 deletions
|
@ -49,7 +49,7 @@ trap not_found EXIT
|
|||
|
||||
# Warnings
|
||||
|
||||
go_version="$( "$GO" version )"
|
||||
go_version="$( "${GO:-go}" version )"
|
||||
readonly go_version
|
||||
|
||||
go_min_version='go1.16'
|
||||
|
@ -62,7 +62,6 @@ for example:
|
|||
"
|
||||
readonly go_min_version go_version_msg
|
||||
|
||||
|
||||
case "$go_version"
|
||||
in
|
||||
('go version'*"$go_min_version"*)
|
||||
|
@ -80,11 +79,11 @@ esac
|
|||
# blocklist_imports is a simple check against unwanted packages. The following
|
||||
# packages are banned:
|
||||
#
|
||||
# * Package io/ioutil is soft-deprecated.
|
||||
#
|
||||
# * 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
|
||||
|
@ -94,6 +93,8 @@ esac
|
|||
#
|
||||
# * Package unsafe is… unsafe.
|
||||
#
|
||||
# * Package golang.org/x/net/context has been moved into stdlib.
|
||||
#
|
||||
blocklist_imports() {
|
||||
git grep\
|
||||
-e '[[:space:]]"errors"$'\
|
||||
|
@ -101,19 +102,34 @@ blocklist_imports() {
|
|||
-e '[[:space:]]"log"$'\
|
||||
-e '[[:space:]]"reflect"$'\
|
||||
-e '[[:space:]]"unsafe"$'\
|
||||
-- '*.go' || exit 0;
|
||||
-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 '"GET"' -e '"POST"' -- '*.go' || exit 0;
|
||||
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.
|
||||
# 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() {
|
||||
git ls-files '*_*.go' | {
|
||||
grep -F\
|
||||
underscore_files="$(
|
||||
git ls-files '*_*.go'\
|
||||
| grep -F\
|
||||
-e '_big.go'\
|
||||
-e '_bsd.go'\
|
||||
-e '_darwin.go'\
|
||||
|
@ -126,8 +142,15 @@ underscores() {
|
|||
-e '_unix.go'\
|
||||
-e '_windows.go' \
|
||||
-v\
|
||||
|| exit 0
|
||||
}
|
||||
| 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 analyser to look for `fallthrough`, `goto`, and `new`?
|
||||
|
@ -151,7 +174,7 @@ exit_on_output() (
|
|||
|
||||
output="$( "$cmd" "$@" 2>&1 )"
|
||||
exitcode="$?"
|
||||
if [ "$exitcode" != '0' ]
|
||||
if [ "$exitcode" -ne '0' ]
|
||||
then
|
||||
echo "'$cmd' failed with code $exitcode"
|
||||
fi
|
||||
|
@ -160,9 +183,9 @@ exit_on_output() (
|
|||
then
|
||||
if [ "$*" != '' ]
|
||||
then
|
||||
echo "combined output of '$cmd $*':"
|
||||
echo "combined output of linter '$cmd $*':"
|
||||
else
|
||||
echo "combined output of '$cmd':"
|
||||
echo "combined output of linter '$cmd':"
|
||||
fi
|
||||
|
||||
echo "$output"
|
||||
|
@ -178,13 +201,6 @@ exit_on_output() (
|
|||
|
||||
|
||||
|
||||
# Constants
|
||||
|
||||
go_files='./main.go ./internal/'
|
||||
readonly go_files
|
||||
|
||||
|
||||
|
||||
# Checks
|
||||
|
||||
exit_on_output blocklist_imports
|
||||
|
@ -208,8 +224,6 @@ gocyclo --over 10 ./internal/aghio/ ./internal/aghnet/ ./internal/aghos/\
|
|||
./internal/aghtest/ ./internal/stats/ ./internal/tools/\
|
||||
./internal/updater/ ./internal/version/ ./main.go
|
||||
|
||||
gosec --quiet $go_files
|
||||
|
||||
ineffassign ./...
|
||||
|
||||
unparam ./...
|
||||
|
@ -222,6 +236,9 @@ nilness ./...
|
|||
|
||||
exit_on_output shadow --strict ./...
|
||||
|
||||
# TODO(a.garipov): Enable in v0.108.0.
|
||||
# gosec --quiet ./...
|
||||
|
||||
# TODO(a.garipov): Enable --blank?
|
||||
errcheck --asserts ./...
|
||||
|
||||
|
|
Loading…
Reference in a new issue