Skip to content

Commit 7b8bab4

Browse files
bendorytekton-robot
authored andcommitted
Hygiene: enabled presets and various linters.
Explicitly enabled: - maintidx - makezero - mustag - nakedret - nilerr - nilnil - noctx - nolintlint - nosprintfhostport Implicitly enabled: all other default linters in the presets. - increased timeout from 10m --> 20m to allow time for additional tests - fixed `presets` configuration, which wasn't formated properly and did not in fact activate the presets - explicitly disabled some linters (enabled by `presets`) that highlight too many issues to resolve in this PR - fixed host-port issues identified by `nosprintfhostport` - fixed issues in step_output_test.go found by `exportloopref` - removed defunct `nolint:revive` pragmas - fixed format of `//nolint` directives in conformance with `nolintlint` - added needed `//nolint` directives.
1 parent 970a281 commit 7b8bab4

File tree

25 files changed

+143
-62
lines changed

25 files changed

+143
-62
lines changed

.golangci.yml

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,62 @@ linters:
3737
- gosec
3838
- gosimple
3939
- govet
40+
- maintidx
41+
- makezero
4042
- misspell
43+
- musttag
44+
- nakedret
45+
- nilerr
46+
- nilnil
47+
- noctx
48+
- nolintlint
49+
- nosprintfhostport
4150
- thelper
4251
- typecheck
4352
- unconvert
4453
- unused
4554
- usestdlibvars
4655
- whitespace
4756
disable:
57+
- cyclop
58+
- dupl
59+
- exhaustruct
60+
- forcetypeassert
61+
- funlen
62+
- gci
63+
- gochecknoglobals
64+
- gochecknoinits
65+
- gocognit
66+
- gocyclo
67+
- godot
68+
- godox
69+
- goerr113
70+
- gofumpt
71+
- gomnd
72+
- gomoddirectives
73+
- ireturn
74+
- lll
75+
- nestif
76+
- nlreturn
77+
- nonamedreturns
78+
- paralleltest
79+
- prealloc
80+
- predeclared
4881
- revive
4982
- staticcheck
50-
# Enabling presets means that new linters that we automatically adopt new
51-
# linters that augment a preset. This also opts us in for replacement linters
52-
# when a linter is deprecated.
53-
presets:
83+
- stylecheck
84+
- tagliatelle
85+
- testpackage
86+
- tparallel
87+
- unparam
88+
- varnamelen
89+
- wastedassign
90+
- wrapcheck
91+
- wsl
92+
# Enabling presets means that new linters that we automatically adopt new
93+
# linters that augment a preset. This also opts us in for replacement linters
94+
# when a linter is deprecated.
95+
presets:
5496
- bugs
5597
- comment
5698
- complexity
@@ -67,41 +109,71 @@ presets:
67109
output:
68110
uniq-by-line: false
69111
issues:
112+
# Note: path identifiers are regular expressions, hence the \.go suffixes.
70113
exclude-rules:
114+
- path: main\.go
115+
linters:
116+
- forbidigo
117+
- path: test/build_logs\.go
118+
linters:
119+
- typecheck
71120
- path: _test\.go
72121
linters:
73-
- goconst
74122
- dogsled
75123
- errcheck
124+
- goconst
76125
- gosec
77126
- ineffassign
127+
- maintidx
128+
- typecheck
78129
- path: test/pipelinerun_test\.go
79130
linters:
80131
- unused
81-
- path: pkg/apis/config/feature_flags_test.go
132+
- path: pkg/apis/config/feature_flags_test\.go
82133
linters:
83134
- containedctx
84-
- path: pkg/pipelinerunmetrics/injection.go
135+
- path: pkg/pipelinerunmetrics/injection\.go
85136
linters:
86137
- containedctx
87-
- path: pkg/pod/creds_init_test.go
138+
- path: pkg/pod/pod\.go
139+
linters:
140+
- maintidx
141+
- path: pkg/pod/creds_init_test\.go
88142
linters:
89143
- containedctx
90-
- path: pkg/taskrunmetrics/injection.go
144+
- path: pkg/reconciler/pipelinerun/pipelinerun\.go
145+
linters:
146+
- maintidx
147+
- path: pkg/taskrunmetrics/injection\.go
91148
linters:
92149
- containedctx
93-
- path: test/controller.go
150+
- path: test/controller\.go
94151
linters:
95152
- containedctx
153+
- path: internal/sidecarlogresults/sidecarlogresults\.go
154+
linters:
155+
- musttag
96156
- path: internal/sidecarlogresults/sidecarlogresults_test\.go
97157
linters:
98158
- errchkjson
159+
- path: pkg/apis/pipeline/v1.*/param_types\.go
160+
linters:
161+
- musttag
162+
- path: pkg/resolution/resolver/framework/testing/fakecontroller\.go
163+
linters:
164+
- contextcheck
165+
- path: pkg/pipelinerunmetrics/metrics\.go
166+
linters:
167+
- contextcheck
168+
- path: pkg/reconciler/pipelinerun/pipelinerun\.go
169+
linters:
170+
- contextcheck
99171
max-issues-per-linter: 0
100172
max-same-issues: 0
101173
include:
102174
# Enable off-by-default rules for revive requiring that all exported elements have a properly formatted comment.
103-
- EXC0012
104-
- EXC0014
175+
- EXC0012 # https://golangci-lint.run/usage/false-positives/#exc0012
176+
- EXC0014 # https://golangci-lint.run/usage/false-positives/#exc0014
105177
run:
106178
issues-exit-code: 1
107179
build-tags:
@@ -113,5 +185,5 @@ run:
113185
- vendor
114186
- pkg/client
115187
- pkg/spire/test
116-
timeout: 10m
188+
timeout: 20m
117189
modules-download-mode: vendor

cmd/entrypoint/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func main() {
174174

175175
if err := e.Go(); err != nil {
176176
breakpointExitPostFile := e.PostFile + breakpointExitSuffix
177-
switch t := err.(type) { // nolint -- checking for multiple types with errors.As is ugly.
177+
switch t := err.(type) { //nolint:errorlint // checking for multiple types with errors.As is ugly.
178178
case skipError:
179179
log.Print("Skipping step because a previous step failed")
180180
os.Exit(1)

cmd/webhook/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ func newConfigValidationController(name string) func(context.Context, configmap.
150150
}
151151

152152
func newConversionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
153-
// nolint: revive
154153
var (
155154
v1beta1GroupVersion = v1beta1.SchemeGroupVersion.Version
156155
v1GroupVersion = v1.SchemeGroupVersion.Version

pkg/apis/config/feature_flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const (
8181
disableCredsInitKey = "disable-creds-init"
8282
runningInEnvWithInjectedSidecarsKey = "running-in-environment-with-injected-sidecars"
8383
awaitSidecarReadinessKey = "await-sidecar-readiness"
84-
requireGitSSHSecretKnownHostsKey = "require-git-ssh-secret-known-hosts" // nolint: gosec
84+
requireGitSSHSecretKnownHostsKey = "require-git-ssh-secret-known-hosts" //nolint:gosec
8585
enableTektonOCIBundles = "enable-tekton-oci-bundles"
8686
enableAPIFields = "enable-api-fields"
8787
sendCloudEventsForRuns = "send-cloudevents-for-runs"
@@ -94,6 +94,8 @@ const (
9494

9595
// FeatureFlags holds the features configurations
9696
// +k8s:deepcopy-gen=true
97+
//
98+
//nolint:musttag
9799
type FeatureFlags struct {
98100
DisableAffinityAssistant bool
99101
DisableCredsInit bool

pkg/apis/pipeline/controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ package pipeline
1818

1919
const (
2020
// PipelineRunControllerName holds the name of the PipelineRun controller
21-
// nolint: revive
2221
PipelineRunControllerName = "PipelineRun"
2322

2423
// PipelineControllerName holds the name of the Pipeline controller
25-
// nolint: revive
2624
PipelineControllerName = "Pipeline"
2725

2826
// TaskRunControllerName holds the name of the TaskRun controller

pkg/apis/pipeline/v1/taskrun_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (tr *TaskRun) GetTimeout(ctx context.Context) time.Duration {
415415
// Use the platform default is no timeout is set
416416
if tr.Spec.Timeout == nil {
417417
defaultTimeout := time.Duration(config.FromContextOrDefaults(ctx).Defaults.DefaultTimeoutMinutes)
418-
return defaultTimeout * time.Minute
418+
return defaultTimeout * time.Minute //nolint:durationcheck
419419
}
420420
return tr.Spec.Timeout.Duration
421421
}

pkg/apis/pipeline/v1beta1/pipelineref_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (ref *PipelineRef) Validate(ctx context.Context) (errs *apis.FieldError) {
6464
}
6565
}
6666
}
67-
return
67+
return //nolint:nakedret
6868
}
6969

7070
func validateBundleFeatureFlag(ctx context.Context, featureName string, wantValue bool) *apis.FieldError {

pkg/apis/pipeline/v1beta1/taskref_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ func (ref *TaskRef) Validate(ctx context.Context) (errs *apis.FieldError) {
6262
}
6363
}
6464
}
65-
return
65+
return //nolint:nakedret
6666
}

pkg/apis/pipeline/v1beta1/taskrun_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (tr *TaskRun) GetTimeout(ctx context.Context) time.Duration {
494494
// Use the platform default is no timeout is set
495495
if tr.Spec.Timeout == nil {
496496
defaultTimeout := time.Duration(config.FromContextOrDefaults(ctx).Defaults.DefaultTimeoutMinutes)
497-
return defaultTimeout * time.Minute
497+
return defaultTimeout * time.Minute //nolint:durationcheck
498498
}
499499
return tr.Spec.Timeout.Duration
500500
}

pkg/credentials/initialize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func SortAnnotations(secrets map[string]string, annotationPrefix string) []strin
8383
// /tekton/creds directory is not considered an error.
8484
func CopyCredsToHome(credPaths []string) error {
8585
if info, err := os.Stat(pipeline.CredsDir); err != nil || !info.IsDir() {
86-
return nil
86+
return nil //nolint:nilerr // safe to ignore error; no credentials available to copy
8787
}
8888

8989
homepath, err := homedir.Dir()

0 commit comments

Comments
 (0)