Skip to content

Commit 6c03e3b

Browse files
authored
chore: Update to golangci-lint v2.3.1 (#999)
1 parent 5c0f89a commit 6c03e3b

File tree

3 files changed

+86
-49
lines changed

3 files changed

+86
-49
lines changed

.github/workflows/lint.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ jobs:
3333
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3434
with:
3535
go-version: "1.24"
36-
- name: go mod tidy
36+
- name: lint
3737
run: |
38-
go mod tidy && git diff --exit-code
39-
- name: golangci-lint
40-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
41-
with:
42-
version: latest
43-
args: --timeout 3m
38+
./build.sh lint_ci
39+

.golangci.yml

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC.
1+
# Copyright 2022 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,40 +11,53 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
# .golangci.yml
14+
15+
version: "2"
1516
linters:
16-
disable-all: true
17+
default: none
1718
enable:
18-
- goimports
1919
- revive
20-
issues:
21-
exclude-use-default: false
22-
linters-settings:
23-
revive:
24-
rules:
25-
- name: blank-imports
26-
- name: context-as-argument
27-
- name: context-keys-type
28-
- name: dot-imports
29-
- name: error-return
30-
- name: error-strings
31-
- name: error-naming
32-
- name: exported
33-
- name: if-return
34-
- name: increment-decrement
35-
- name: var-naming
36-
- name: var-declaration
37-
- name: range
38-
- name: receiver-naming
39-
- name: time-naming
40-
- name: unexported-return
41-
- name: indent-error-flow
42-
- name: errorf
43-
- name: empty-block
44-
- name: superfluous-else
45-
- name: unused-parameter
46-
- name: unreachable-code
47-
- name: redefines-builtin-id
48-
- name: range-val-in-closure
49-
- name: range-val-address
50-
- name: import-shadowing
20+
settings:
21+
revive:
22+
rules:
23+
- name: blank-imports
24+
- name: context-as-argument
25+
- name: context-keys-type
26+
- name: dot-imports
27+
- name: error-return
28+
- name: error-strings
29+
- name: error-naming
30+
- name: exported
31+
- name: if-return
32+
- name: increment-decrement
33+
- name: var-naming
34+
- name: var-declaration
35+
- name: range
36+
- name: receiver-naming
37+
- name: time-naming
38+
- name: unexported-return
39+
- name: indent-error-flow
40+
- name: errorf
41+
- name: empty-block
42+
- name: superfluous-else
43+
- name: unused-parameter
44+
- name: unreachable-code
45+
- name: redefines-builtin-id
46+
- name: range-val-in-closure
47+
- name: range-val-address
48+
- name: import-shadowing
49+
exclusions:
50+
generated: lax
51+
paths:
52+
- third_party$
53+
- builtin$
54+
- examples$
55+
formatters:
56+
enable:
57+
- goimports
58+
exclusions:
59+
generated: lax
60+
paths:
61+
- third_party$
62+
- builtin$
63+
- examples$

build.sh

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,47 @@ function e2e() {
5050
e2e_ci
5151
}
5252

53+
# e2e_ci - Run end-to-end integration tests in the CI system.
54+
# This assumes that the secrets in the env vars are already set.
5355
function e2e_ci() {
5456
go test -v -race -cover ./e2e_mysql_test.go ./e2e_postgres_test.go ./e2e_sqlserver_test.go | tee test_results.txt
5557
}
5658

59+
# Download a tool using `go install`
60+
function get_golang_tool() {
61+
name="$1"
62+
github_repo="$2"
63+
package=$3
64+
65+
# Download goimports tool
66+
version=$(curl -s "https://api.github.com/repos/$github_repo/tags" | jq -r '.[].name' | head -n 1)
67+
mkdir -p "$SCRIPT_DIR/.tools"
68+
cmd="$SCRIPT_DIR/.tools/$name"
69+
versioned_cmd="$SCRIPT_DIR/.tools/$name-$version"
70+
if [[ ! -f "$versioned_cmd" ]] ; then
71+
GOBIN="$SCRIPT_DIR/.tools" go install "$package@$version"
72+
mv "$cmd" "$versioned_cmd"
73+
if [[ -f "$cmd" ]] ; then
74+
unlink "$cmd"
75+
fi
76+
ln -s "$versioned_cmd" "$cmd"
77+
fi
78+
}
79+
5780
## fix - Fixes code format.
5881
function fix() {
82+
# run code formatting
83+
get_golang_tool 'goimports' 'golang/tools' 'golang.org/x/tools/cmd/goimports'
84+
".tools/goimports" -w .
5985
go mod tidy
6086
go fmt ./...
6187
}
6288

6389
## lint - runs the linters
6490
function lint() {
65-
# run golangci-lint
66-
mkdir -p "$SCRIPT_DIR/.tools"
67-
if [[ ! -f "$SCRIPT_DIR/.tools/golangci-lint" ]] ; then
68-
GOBIN="$SCRIPT_DIR/.tools" go install github.com/golangci/golangci-lint/cmd/[email protected]
69-
fi
70-
"$SCRIPT_DIR/.tools/golangci-lint" run --timeout 3m
91+
# run lint checks
92+
get_golang_tool 'golangci-lint' 'golangci/golangci-lint' 'github.com/golangci/golangci-lint/v2/cmd/golangci-lint'
93+
".tools/golangci-lint" run --timeout 3m
7194

7295
# Check the commit includes a go.mod that is fully
7396
# up to date.
@@ -77,10 +100,15 @@ function lint() {
77100
fi
78101
}
79102

103+
# lint_ci runs lint in the CI build job
104+
function lint_ci() {
105+
fix # run code format cleanup
106+
git diff --exit-code # fail if anything changed
107+
lint # run lint
108+
}
80109

81110
# write_e2e_env - Loads secrets from the gcloud project and writes
82111
# them to target/e2e.env to run e2e tests.
83-
#
84112
function write_e2e_env(){
85113
# All secrets used by the e2e tests in the form <env_name>=<secret_name>
86114
secret_vars=(

0 commit comments

Comments
 (0)