Skip to content

Commit 172c4ae

Browse files
authored
Migrate golangci-lint to v2 (#6178)
* chore: exec golangci-lint migrate Signed-off-by: Junya Okabe <okabe.junya.qj@alumni.tsukuba.ac.jp> * bump some tools Signed-off-by: Junya Okabe <okabe.junya.qj@alumni.tsukuba.ac.jp> * fix: linter qf errors Signed-off-by: Junya Okabe <okabe.junya.qj@alumni.tsukuba.ac.jp> * fix: golangci.yaml Signed-off-by: Junya Okabe <okabe.junya.qj@alumni.tsukuba.ac.jp> --------- Signed-off-by: Junya Okabe <okabe.junya.qj@alumni.tsukuba.ac.jp> Signed-off-by: Junya Okabe <86868255+Okabe-Junya@users.noreply.github.com>
1 parent 8371931 commit 172c4ae

4 files changed

Lines changed: 91 additions & 77 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77
pull_request:
88
branches:
99
- master
10-
- 'release-v*'
11-
- 'feat/*'
10+
- "release-v*"
11+
- "feat/*"
1212

1313
env:
1414
GO_VERSION: 1.24.1
1515
NODE_VERSION: 18.12.0
16-
GOLANGCI_LINT_VERSION: v1.64.7
16+
GOLANGCI_LINT_VERSION: v2.4.0
1717
HELM_VERSION: 3.17.3
1818

1919
jobs:
@@ -38,13 +38,13 @@ jobs:
3838
steps:
3939
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4040
- name: golangci-lint
41-
uses: reviewdog/action-golangci-lint@f3dc5fadcaff5d8da3574b129a58db433171b1a8 #v2.1.3
41+
uses: reviewdog/action-golangci-lint@f9bba13753278f6a73b27a56a3ffb1bfda90ed71 #v2.8.0
4242
with:
4343
workdir: ${{ matrix.module }}
4444
go_version: ${{ env.GO_VERSION }}
4545
golangci_lint_version: ${{ env.GOLANGCI_LINT_VERSION }}
4646
golangci_lint_flags: --config ${{ github.workspace }}/.golangci.yml
47-
fail_on_error: true # this option is deprecated on v2.7.0, but we use v2.1.3, so it's still available
47+
fail_level: error
4848

4949
# This job is used to check if the go linting is completed successfully
5050
# It is used to set as required check for the branch protection rules

.golangci.yml

Lines changed: 81 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,100 @@
1-
run:
2-
timeout: 15m
3-
1+
version: "2"
42
linters:
5-
disable-all: true
3+
default: none
64
enable:
7-
- gofmt
85
- depguard
96
- gocritic
107
- goheader
11-
- goimports
12-
- gosimple
138
- ineffassign
149
- misspell
1510
- prealloc
1611
- staticcheck
17-
- stylecheck
18-
- typecheck
1912
- unconvert
2013
- unparam
2114
# TODO: Enable these linters
2215
# - errcheck
2316
# - goerr113
2417
# - gosec
2518

26-
issues:
27-
exclude-files:
28-
- ^.*\.(pb|y)\.go$
29-
exclude-dirs:
30-
- "vendor$"
31-
- "pkg/app/piped/executor/analysis/mannwhitney"
32-
# Relative path of "pkg/app/pipedv1/plugin/analysis/executestage/mannwhitney"
33-
- "executestage/mannwhitney"
34-
exclude-rules:
35-
- linters:
36-
- staticcheck
37-
text: "SA1019"
38-
39-
output:
40-
sort-results: true
41-
42-
linters-settings:
43-
depguard:
44-
rules:
45-
main:
46-
deny:
47-
- pkg: "sync/atomic"
48-
desc: "Use go.uber.org/atomic instead of sync/atomic."
49-
- pkg: "io/ioutil"
50-
desc: "Use corresponding 'os' or 'io' functions instead."
51-
pipedv1:
52-
files:
53-
- "**/pkg/app/pipedv1/**/*.go"
54-
deny:
55-
- pkg: "github.com/pipe-cd/pipecd/pkg/config$"
56-
desc: "Use github.com/pipe-cd/pipecd/pkg/configv1 instead."
57-
plugin:
58-
files:
59-
- "**/pkg/app/pipedv1/plugin/**/*.go"
60-
deny:
61-
- pkg: "^github.com/pipe-cd/pipecd/(?!pkg/app/pipedv1/plugin).*"
62-
desc: "Use github.com/pipe-cd/piped-plugin-sdk-go instead."
63-
gocritic:
64-
disabled-checks:
65-
- appendAssign
66-
goimports:
67-
local-prefixes: github.com/pipe-cd/pipecd
68-
goheader:
69-
values:
70-
regexp:
71-
any-year: \d{4} # the year of copyright means the first published year, so it can be any year.
72-
# template does not contains the comment indicator '//' or '/*' '*/'
73-
template: |-
74-
Copyright {{any-year}} The PipeCD Authors.
19+
settings:
20+
depguard:
21+
rules:
22+
main:
23+
deny:
24+
- pkg: "sync/atomic"
25+
desc: "Use go.uber.org/atomic instead of sync/atomic."
26+
- pkg: "io/ioutil"
27+
desc: "Use corresponding 'os' or 'io' functions instead."
28+
pipedv1:
29+
files:
30+
- "**/pkg/app/pipedv1/**/*.go"
31+
deny:
32+
- pkg: "github.com/pipe-cd/pipecd/pkg/config$"
33+
desc: "Use github.com/pipe-cd/pipecd/pkg/configv1 instead."
34+
plugin:
35+
files:
36+
- "**/pkg/app/pipedv1/plugin/**/*.go"
37+
deny:
38+
- pkg: "^github.com/pipe-cd/pipecd/(?!pkg/app/pipedv1/plugin).*"
39+
desc: "Use github.com/pipe-cd/piped-plugin-sdk-go instead."
40+
gocritic:
41+
disabled-checks:
42+
- appendAssign
43+
goheader:
44+
values:
45+
regexp:
46+
any-year: \d{4} # the year of copyright means the first published year, so it can be any year.
47+
# template does not contains the comment indicator '//' or '/*' '*/'
48+
template: |-
49+
Copyright {{any-year}} The PipeCD Authors.
7550
76-
Licensed under the Apache License, Version 2.0 (the "License");
77-
you may not use this file except in compliance with the License.
78-
You may obtain a copy of the License at
51+
Licensed under the Apache License, Version 2.0 (the "License");
52+
you may not use this file except in compliance with the License.
53+
You may obtain a copy of the License at
7954
80-
http://www.apache.org/licenses/LICENSE-2.0
55+
http://www.apache.org/licenses/LICENSE-2.0
8156
82-
Unless required by applicable law or agreed to in writing, software
83-
distributed under the License is distributed on an "AS IS" BASIS,
84-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
85-
See the License for the specific language governing permissions and
86-
limitations under the License.
57+
Unless required by applicable law or agreed to in writing, software
58+
distributed under the License is distributed on an "AS IS" BASIS,
59+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60+
See the License for the specific language governing permissions and
61+
limitations under the License.
62+
exclusions:
63+
generated: lax
64+
presets:
65+
- comments
66+
- common-false-positives
67+
- legacy
68+
- std-error-handling
69+
rules:
70+
- linters:
71+
- staticcheck
72+
text: SA1019
73+
paths:
74+
- ^.*\.(pb|y)\.go$
75+
- vendor$
76+
- pkg/app/piped/executor/analysis/mannwhitney
77+
# Relative path of "pkg/app/pipedv1/plugin/analysis/executestage/mannwhitney"
78+
- executestage/mannwhitney
79+
- third_party$
80+
- builtin$
81+
- examples$
82+
formatters:
83+
enable:
84+
- gofmt
85+
- goimports
86+
settings:
87+
goimports:
88+
local-prefixes:
89+
- github.com/pipe-cd/pipecd
90+
exclusions:
91+
generated: lax
92+
paths:
93+
- ^.*\.(pb|y)\.go$
94+
- vendor$
95+
- pkg/app/piped/executor/analysis/mannwhitney
96+
# Relative path of "pkg/app/pipedv1/plugin/analysis/executestage/mannwhitney"
97+
- executestage/mannwhitney
98+
- third_party$
99+
- builtin$
100+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ lint: lint/go lint/web lint/helm
200200

201201
.PHONY: lint/go
202202
lint/go: FIX ?= false
203-
lint/go: VERSION ?= sha256:c2f5e6aaa7f89e7ab49f6bd45d8ce4ee5a030b132a5fbcac68b7959914a5a890 # golangci/golangci-lint:v1.64.7
203+
lint/go: VERSION ?= sha256:91460846c43b3de53eb77e968b17363e8747e6f3fc190575b52be60c49446e23 # golangci/golangci-lint:v2.4.0
204204
lint/go: FLAGS ?= --rm -e GOCACHE=/repo/.cache/go-build -e GOLANGCI_LINT_CACHE=/repo/.cache/golangci-lint -v ${PWD}:/repo -it
205205
lint/go: MODULES ?= $(shell find . -name go.mod | while read -r dir; do dirname "$$dir"; done | paste -sd, -) # comma separated list of modules. eg: MODULES=.,pkg/plugin/sdk
206206
lint/go:

pkg/plugin/sdk/deployment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig, ApplicationCo
104104
Logger: s.logger,
105105
}
106106

107-
versions, err := s.base.DetermineVersions(ctx, s.commonFields.pluginConfig, input)
107+
versions, err := s.base.DetermineVersions(ctx, s.pluginConfig, input)
108108
if err != nil {
109109
return nil, status.Errorf(codes.Internal, "failed to determine versions: %v", err)
110110
}
@@ -131,7 +131,7 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig, ApplicationCo
131131
Logger: s.logger,
132132
}
133133

134-
response, err := s.base.DetermineStrategy(ctx, s.commonFields.pluginConfig, input)
134+
response, err := s.base.DetermineStrategy(ctx, s.pluginConfig, input)
135135
if err != nil {
136136
return nil, status.Errorf(codes.Internal, "failed to determine strategy: %v", err)
137137
}
@@ -150,7 +150,7 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig, ApplicationCo
150150
base: s.client,
151151
pluginName: s.name,
152152
}
153-
return buildPipelineSyncStages(ctx, s.base, s.commonFields.pluginConfig, client, request, s.logger)
153+
return buildPipelineSyncStages(ctx, s.base, s.pluginConfig, client, request, s.logger)
154154
}
155155
func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig, ApplicationConfigSpec]) BuildQuickSyncStages(ctx context.Context, request *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) {
156156
input := &BuildQuickSyncStagesInput{
@@ -234,7 +234,7 @@ func (s *StagePluginServiceServer[Config, DeployTargetConfig, ApplicationConfigS
234234
pluginName: s.name,
235235
}
236236

237-
return buildPipelineSyncStages(ctx, s.base, s.commonFields.pluginConfig, client, request, s.logger)
237+
return buildPipelineSyncStages(ctx, s.base, s.pluginConfig, client, request, s.logger)
238238
}
239239
func (s *StagePluginServiceServer[Config, DeployTargetConfig, ApplicationConfigSpec]) BuildQuickSyncStages(context.Context, *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) {
240240
// Return an empty response in case the plugin does not support the QuickSync strategy.

0 commit comments

Comments
 (0)