AdGuardHome/scripts/make/go-lint.sh
Dimitry Kolyshev ea8d634f65 Pull request: dhcpd imp code
Merge in DNS/adguard-home from dhcpd-imp-code to master

Squashed commit of the following:

commit 413403c169bd3f6b5f2ed63b783d078dbb15e054
Merge: eed183850 0fec990bc
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Fri May 26 12:46:25 2023 +0300

    Merge remote-tracking branch 'origin/master' into dhcpd-imp-code

commit eed1838502add1e16e5d3ada03778f21913fd5e5
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Fri May 26 12:16:46 2023 +0300

    dhcpd: imp docs

commit fa4fe036f7b1f2b49201bf0b5b904f99989082f0
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu May 25 11:32:34 2023 +0300

    all: lint script

commit a4022b3d4bbfa709e5096397bbe64ea406c8a366
Merge: e08ff3a26 cbc7985e7
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu May 25 11:29:57 2023 +0300

    Merge remote-tracking branch 'origin/master' into dhcpd-imp-code

    # Conflicts:
    #	scripts/make/go-lint.sh

commit e08ff3a26414e201d6e75608363db941fa2f5b39
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed May 24 15:43:11 2023 +0300

    dhcpd: imp code

commit 970b538f8ea94d3732d77bfb648e402a1d28ab06
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed May 24 15:40:36 2023 +0300

    dhcpd: imp code

commit 0e5916ddd7514af983e8557080d55d6aeb6fbbc0
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed May 24 15:37:17 2023 +0300

    dhcpd: imp code

commit e06a6c6031b232e76ae2be3e3b8fe1a2ffa715e0
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 16:40:09 2023 +0300

    dhcpd: imp code

commit eed4ff10ff1b29c71d70fb7978706efde89afee1
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 15:45:06 2023 +0300

    all: lint script

commit 87f84ace5f6f34dbc28befa8257d1d2492c5e0a4
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 15:44:23 2023 +0300

    dhcpd: imp code

commit a54c9929d51de1f1e6807d650fd08dd80ddbf147
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 14:29:42 2023 +0300

    dhcpd: imp code

commit 1bbea342f7f55587724aa9a29d9657e5ce75f5d8
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 14:12:09 2023 +0300

    dhcpd: imp code

commit 48fb4eff73683e799ddb3076afdcf7b067ca24b6
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 13:57:59 2023 +0300

    dhcpd: imp code

commit f6cd7fcb8d4c1c815a20875d777ea1eca2c8ea89
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 13:17:54 2023 +0300

    dhcpd: imp code

commit 2b91dc25bbaa16dba6d9389a4e2224cf91eb4554
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue May 23 12:57:46 2023 +0300

    dhcpd: imp code

commit 34f5dd58764080f6202fc9a1abd751a15dbf7090
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon May 22 15:31:39 2023 +0300

    dhcpd: imp code

commit 12ef0d225064a1b78adf7b2cfca21a8dba92ca8e
Merge: 6b62a7665 24b41100c
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon May 22 13:03:41 2023 +0300

    Merge remote-tracking branch 'origin/master' into dhcpd-imp-code

commit 6b62a7665720b85398d65a1926518a63e6bb6403
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon May 22 12:55:43 2023 +0300

    dhcpd: imp code

commit 18c5cdf0480fac7711282027a64d58704c75af5f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon May 22 12:48:30 2023 +0300

    dhcpd: imp code

commit e7c1f4324cba3fe86cf56df6b971791a5a8790de
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon May 22 12:37:15 2023 +0300

    dhcpd: imp code

... and 1 more commit
2023-05-26 12:50:03 +03:00

186 lines
3.9 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.8'
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 ./...
run_linter gocyclo --over 10 .
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 ./...