Skip to content

Commit

Permalink
vet: use staticcheck for pkg comments; remove golint (deprecated & slow)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Nov 10, 2023
1 parent 591c481 commit 6b9ab71
Showing 1 changed file with 4 additions and 36 deletions.
40 changes: 4 additions & 36 deletions vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ git grep -l -e 'grpclog.I' --or -e 'grpclog.W' --or -e 'grpclog.E' --or -e 'grpc
not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go"

# - Ensure all usages of grpc_testing package are renamed when importing.
not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go"
not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go"

# - Ensure all xds proto imports are renamed to *pb or *grpc.
git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' ':(exclude)*.pb.go' | not grep -v 'pb "\|grpc "'
Expand All @@ -110,7 +110,6 @@ for MOD_FILE in $(find . -name 'go.mod'); do
go vet -all ./... | fail_on_output
gofmt -s -d -l . 2>&1 | fail_on_output
goimports -l . 2>&1 | not grep -vE "\.pb\.go"
golint ./... 2>&1 | not grep -vE "/grpc_testing_not_regenerate/.*\.pb\.go:"

go mod tidy -compat=1.19
git status --porcelain 2>&1 | fail_on_output || \
Expand All @@ -124,9 +123,9 @@ done
# plugins.
# TODO(dfawley): enable ST1019 (duplicate imports) but allow for protobufs.
SC_OUT="$(mktemp)"
staticcheck -go 1.19 -checks 'inherit,-ST1015,-ST1019,-SA1019' ./... > "${SC_OUT}" || true
# Error if anything other than deprecation warnings are printed.
not grep -v "is deprecated:.*SA1019" "${SC_OUT}"
staticcheck -go 1.19 -checks 'inherit,ST1000,-ST1015,-ST1019,-SA1019' ./... > "${SC_OUT}" || true
# Error for anything other than package comments in generated code.
not grep -v ".pb.go:.*ST1000" "${SC_OUT}"
# Only ignore the following deprecated types/fields/functions.
not grep -Fv '.CredsBundle
.HeaderMap
Expand Down Expand Up @@ -178,35 +177,4 @@ Target is deprecated: Use the Target field in the BuildOptions instead.
xxx_messageInfo_
' "${SC_OUT}"

# - special golint on package comments.
lint_package_comment_per_package() {
# Number of files in this go package.
fileCount=$(go list -f '{{len .GoFiles}}' $1)
if [ ${fileCount} -eq 0 ]; then
return 0
fi
# Number of package errors generated by golint.
lintPackageCommentErrorsCount=$(golint --min_confidence 0 $1 | grep -c "should have a package comment")
# golint complains about every file that's missing the package comment. If the
# number of files for this package is greater than the number of errors, there's
# at least one file with package comment, good. Otherwise, fail.
if [ ${fileCount} -le ${lintPackageCommentErrorsCount} ]; then
echo "Package $1 (with ${fileCount} files) is missing package comment"
return 1
fi
}
lint_package_comment() {
set +ex

count=0
for i in $(go list ./...); do
lint_package_comment_per_package "$i"
((count += $?))
done

set -ex
return $count
}
lint_package_comment

echo SUCCESS

0 comments on commit 6b9ab71

Please sign in to comment.