Skip to content

Commit 219f3e6

Browse files
committed
Update golangci-lint to 2.0
- Update golangci-lint configuration with enabled linters and exclusion paths - Adjust struct field accesses from status.Status.Conditions to status.Conditions - Simplify PipelineRun name references using ObjectMeta.Name shortcut - Fix invalid URL test data and control character handling assertions - Correct pagination header check in Gitea provider - Update test assertions for PipelineRun GenerateName fields - Add unknown status handling in GitHub retest verification Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent d723fee commit 219f3e6

File tree

9 files changed

+66
-89
lines changed

9 files changed

+66
-89
lines changed

.golangci.yml

Lines changed: 49 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,105 @@
1-
issues:
2-
exclude-dirs:
3-
- vendor
4-
- pkg/provider/gitea/structs
5-
exclude-rules:
6-
# Exclude some linters from running on tests files.
7-
- path: _test\.go
8-
linters:
9-
- gosec
10-
# hopefully we can remove this when https://github.com/golangci/golangci-lint/issues/4697 is fixed
11-
- path: pkg/resolve/resolve.go
12-
text: "don't use `init` function"
1+
version: "2"
132
run:
143
build-tags:
154
- e2e
16-
linters-settings:
17-
gocritic:
18-
disabled-checks:
19-
- unlambda
20-
errcheck:
21-
exclude-functions:
22-
- (*github.com/tektoncd/pipeline/vendor/go.uber.org/zap.SugaredLogger).Sync
23-
- flag.Set
24-
- logger.Sync
25-
- fmt.Fprintf
26-
- fmt.Fprintln
27-
- (io.Closer).Close
28-
- updateConfigMap
29-
gofumpt:
30-
extra-rules: true
315
linters:
326
enable:
337
- asasalint
348
- asciicheck
359
- bidichk
3610
- bodyclose
37-
#- containedctx
38-
#- contextcheck
39-
#- cyclop
11+
- copyloopvar
4012
- decorder
41-
#- depguard
4213
- dogsled
4314
- dupl
4415
- dupword
4516
- durationcheck
46-
- errcheck
4717
- errchkjson
4818
- errname
4919
- errorlint
50-
# - execinquery
5120
- exhaustive
52-
#- exhaustruct
53-
- copyloopvar
5421
- forbidigo
5522
- forcetypeassert
56-
#- funlen
57-
#- gci
5823
- ginkgolinter
5924
- gocheckcompilerdirectives
60-
#- gochecknoglobals
6125
- gochecknoinits
6226
- gochecksumtype
63-
#- gocognit
64-
#- goconst
6527
- gocritic
66-
#- gocyclo
6728
- godot
68-
#- godox
69-
#- goerr113
70-
#- gofmt
71-
- gofumpt
7229
- goheader
73-
- goimports
74-
#- gomnd
75-
#- gomoddirectives
7630
- gomodguard
7731
- goprintffuncname
7832
- gosec
79-
- gosimple
8033
- gosmopolitan
81-
- govet
8234
- grouper
8335
- importas
84-
#- inamedparam
85-
#- interfacebloat
86-
#- ireturn
87-
#- lll
8836
- loggercheck
89-
#- maintidx
9037
- makezero
9138
- mirror
9239
- misspell
93-
#- musttag
9440
- nakedret
95-
#- nestif
9641
- nilerr
97-
#- nilnil
98-
#- nlreturn
9942
- noctx
100-
#- nolintlint
101-
#- nonamedreturns
10243
- nosprintfhostport
103-
#- paralleltest
104-
#- perfsprint
10544
- prealloc
10645
- predeclared
10746
- promlinter
10847
- protogetter
10948
- reassign
11049
- revive
111-
#- rowserrcheck
11250
- sloglint
113-
#- sqlclosecheck
11451
- staticcheck
115-
- stylecheck
11652
- tagalign
117-
#- tagliatelle
11853
- testableexamples
119-
# - testifylint
120-
#- testpackage
121-
#- thelper
12254
- tparallel
123-
#- unconvert
12455
- unparam
125-
- unused
12656
- usestdlibvars
127-
#- varnamelen
128-
#- wastedassign
12957
- whitespace
130-
#- wrapcheck
131-
#- wsl
13258
- zerologlint
59+
settings:
60+
errcheck:
61+
exclude-functions:
62+
- (*github.com/tektoncd/pipeline/vendor/go.uber.org/zap.SugaredLogger).Sync
63+
- flag.Set
64+
- logger.Sync
65+
- fmt.Fprintf
66+
- fmt.Fprintln
67+
- (io.Closer).Close
68+
- updateConfigMap
69+
gocritic:
70+
disabled-checks:
71+
- unlambda
72+
exclusions:
73+
generated: lax
74+
presets:
75+
- comments
76+
- common-false-positives
77+
- legacy
78+
- std-error-handling
79+
rules:
80+
- linters:
81+
- gosec
82+
path: _test\.go
83+
- path: pkg/resolve/resolve.go
84+
text: don't use `init` function
85+
paths:
86+
- vendor
87+
- pkg/provider/gitea/structs
88+
- third_party$
89+
- builtin$
90+
- examples$
91+
formatters:
92+
enable:
93+
- gofumpt
94+
- goimports
95+
settings:
96+
gofumpt:
97+
extra-rules: true
98+
exclusions:
99+
generated: lax
100+
paths:
101+
- vendor
102+
- pkg/provider/gitea/structs
103+
- third_party$
104+
- builtin$
105+
- examples$

pkg/cmd/tknpac/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func formatStatus(status *v1alpha1.RepositoryRunStatus, cs *cli.ColorScheme, c c
123123
}
124124

125125
reason := "UNKNOWN"
126-
if len(status.Status.Conditions) > 0 {
127-
reason = status.Status.Conditions[0].Reason
126+
if len(status.Conditions) > 0 {
127+
reason = status.Conditions[0].Reason
128128
}
129129
return fmt.Sprintf("%s\t%s", s, cs.HyperLink(cs.ColorStatus(reason), *status.LogURL))
130130
}

pkg/cmd/tknpac/logs/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func getPipelineRunsToRepo(ctx context.Context, lopt *logOption, repoName string
191191
if lopt.limit > -1 && i > lopt.limit {
192192
continue
193193
}
194-
ret = append(ret, fmt.Sprintf("%s %s %s", run.ObjectMeta.Name, label, formatting.Age(date, lopt.cw)))
194+
ret = append(ret, fmt.Sprintf("%s %s %s", run.Name, label, formatting.Age(date, lopt.cw)))
195195
}
196196
return ret, nil
197197
}

pkg/provider/bitbucketdatacenter/parse_payload_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,8 @@ func TestParsePayload(t *testing.T) {
598598
Sender: "sender",
599599
Organization: "PROJ",
600600
Repository: "repo",
601-
//nolint: stylecheck
602-
URL: "💢",
603-
SHA: "abcd",
601+
URL: "\x03💢\x16",
602+
SHA: "abcd",
604603
}, ""),
605604
wantErrSubstr: "invalid control character",
606605
},

pkg/provider/gitea/gitea.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error
318318
}
319319

320320
func ShouldGetNextPage(resp *gitea.Response, currentPage int) (bool, int) {
321-
val, exists := resp.Response.Header[http.CanonicalHeaderKey("x-pagecount")]
321+
val, exists := resp.Header[http.CanonicalHeaderKey("x-pagecount")]
322322
if !exists {
323323
return false, 0
324324
}

pkg/provider/gitlab/gitlab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (v *Provider) getObject(fname, branch string, pid int) ([]byte, *gitlab.Res
327327
if err != nil {
328328
return []byte{}, resp, fmt.Errorf("failed to get filename from api %s dir: %w", fname, err)
329329
}
330-
if resp != nil && resp.Response.StatusCode == http.StatusNotFound {
330+
if resp != nil && resp.StatusCode == http.StatusNotFound {
331331
return []byte{}, resp, nil
332332
}
333333
return file, resp, nil

pkg/resolve/resolve_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ func TestPipelineRunPipelineMiddle(t *testing.T) {
8585
func TestGenerateName(t *testing.T) {
8686
resolved, _, err := readTDfile(t, "pipelinerun-pipeline-task", true, true)
8787
assert.NilError(t, err)
88-
assert.Assert(t, resolved.ObjectMeta.GenerateName != "")
88+
assert.Assert(t, resolved.GenerateName != "")
8989

9090
resolved, _, err = readTDfile(t, "with-generatename", true, true)
9191
assert.NilError(t, err)
92-
assert.Assert(t, resolved.ObjectMeta.GenerateName != "")
92+
assert.Assert(t, resolved.GenerateName != "")
9393
}
9494

9595
// TestPipelineBundlesSkipped effectively test conversion from beta1 to v1.

pkg/test/clients/clients.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Data struct {
5151

5252
// SeedTestData returns Clients and Informers populated with the
5353
// given Data.
54-
func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers) { //nolint: golint, revive
54+
func SeedTestData(t *testing.T, ctx context.Context, d Data) (Clients, Informers) { //nolint: revive
5555
c := Clients{
5656
PipelineAsCode: fakepacclient.Get(ctx),
5757
Kube: fakekubeclient.Get(ctx),

test/github_pullrequest_retest_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,22 @@ func TestGithubSecondPullRequestGitopsCommentCancel(t *testing.T) {
125125
// go over all pruns check that at least one is canceled and the other two are succeeded
126126
canceledCount := 0
127127
succeededCount := 0
128+
unknownCount := 0
128129
for _, prun := range pruns.Items {
129130
for _, condition := range prun.Status.Conditions {
130131
if condition.Type == "Succeeded" {
131-
if condition.Status == corev1.ConditionFalse {
132+
switch condition.Status {
133+
case corev1.ConditionFalse:
132134
canceledCount++
133-
} else if condition.Status == corev1.ConditionTrue {
135+
case corev1.ConditionTrue:
134136
succeededCount++
137+
case corev1.ConditionUnknown:
138+
unknownCount++
135139
}
136140
}
137141
}
138142
}
139143
assert.Equal(t, canceledCount, 1, "should have one canceled PipelineRun")
140144
assert.Equal(t, succeededCount, 2, "should have two succeeded PipelineRuns")
145+
assert.Equal(t, unknownCount, 0, "should have zero unknown PipelineRuns: %+v", pruns.Items)
141146
}

0 commit comments

Comments
 (0)