Skip to content

Commit d58d050

Browse files
committed
Update golangci version and configuration, and fix errors
This is a relatively huge commit that updates the golangci-lint version as well as configuration. ``` make golangci-lint 🐱 running golangci-lint… WARN [linters_context] copyloopvar: this linter is disabled because the Go version (1.21) of your project is lower than Go 1.22 Compilation finished at Thu Apr 4 13:44:19 ``` Signed-off-by: Vincent Demeester <[email protected]>
1 parent ee712cb commit d58d050

File tree

105 files changed

+5950
-5642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5950
-5642
lines changed

.golangci.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ linters-settings:
1616
- github.com/ghodss/yaml:
1717
recommendations:
1818
- sigs.k8s.io/yaml
19+
depguard:
20+
rules:
21+
prevent_unmaintained_packages:
22+
list-mode: lax # allow unless explicitely denied
23+
files:
24+
- $all
25+
- "!$test"
26+
allow:
27+
- $gostd
28+
deny:
29+
- pkg: io/ioutil
30+
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
31+
- pkg: github.com/ghodss/yaml
32+
desc: "use sigs.k8s.io/yaml instead, to be consistent"
1933
linters:
2034
enable:
2135
- bodyclose
@@ -174,16 +188,16 @@ issues:
174188
# Enable off-by-default rules for revive requiring that all exported elements have a properly formatted comment.
175189
- EXC0012 # https://golangci-lint.run/usage/false-positives/#exc0012
176190
- EXC0014 # https://golangci-lint.run/usage/false-positives/#exc0014
177-
run:
178-
issues-exit-code: 1
179-
build-tags:
180-
- e2e
181-
skip-files:
191+
exclude-files:
182192
- .*/zz_generated.deepcopy.go
183193
- pkg/apis/pipeline/v1beta1/openapi_generated.go
184-
skip-dirs:
194+
exclude-dirs:
185195
- vendor
186196
- pkg/client
187197
- pkg/spire/test
198+
run:
199+
issues-exit-code: 1
200+
build-tags:
201+
- e2e
188202
timeout: 20m
189203
modules-download-mode: vendor

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
99
BIN = $(CURDIR)/.bin
1010
WOKE ?= go run -modfile go.mod github.com/get-woke/woke
1111

12-
GOLANGCI_VERSION = v1.52.2
12+
GOLANGCI_VERSION = v1.57.2
1313
WOKE_VERSION = v0.19.0
1414

1515
GO = go
@@ -170,7 +170,7 @@ $(BIN)/golangci-lint: ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION))
170170

171171
.PHONY: golangci-lint
172172
golangci-lint: | $(GOLANGCILINT) ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint
173-
$Q $(GOLANGCILINT) run --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --deadline 5m
173+
$Q $(GOLANGCILINT) run --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --timeout 5m
174174

175175
.PHONY: golangci-lint-check
176176
golangci-lint-check: | $(GOLANGCILINT) ; $(info $(M) Testing if golint has been done…) @ ## Run golangci-lint for build tests CI job

cmd/entrypoint/subcommands/subcommands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Process(args []string) error {
9595
if err := decodeScript(src); err != nil {
9696
return SubcommandError{subcommand: DecodeScriptCommand, message: err.Error()}
9797
}
98-
return OK{message: fmt.Sprintf("Decoded script %s", src)}
98+
return OK{message: "Decoded script " + src}
9999
}
100100
case StepInitCommand:
101101
if err := stepInit(args[1:]); err != nil {

cmd/entrypoint/subcommands/subcommands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func TestProcessSuccessfulSubcommands(t *testing.T) {
3232
src := filepath.Join(tmp, "foo.txt")
3333
dst := filepath.Join(tmp, "bar.txt")
3434

35-
srcFile, err := os.OpenFile(src, os.O_WRONLY|os.O_CREATE, 0666)
35+
srcFile, err := os.OpenFile(src, os.O_WRONLY|os.O_CREATE, 0o666)
3636
if err != nil {
3737
t.Fatalf("error opening temp file for writing: %v", err)
3838
}
3939
defer srcFile.Close()
40-
if _, err := srcFile.Write([]byte(helloWorldBase64)); err != nil {
40+
if _, err := srcFile.WriteString(helloWorldBase64); err != nil {
4141
t.Fatalf("error writing source file: %v", err)
4242
}
4343

hack/spec-gen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
5454
})
5555
default:
56-
panic(fmt.Sprintf("Unsupported API version: %s", *apiVersion))
56+
panic("Unsupported API version: " + *apiVersion)
5757
}
5858
defs := spec.Definitions{}
5959
for defName, val := range oAPIDefs {

internal/sidecarlogresults/sidecarlogresults.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ const (
4747

4848
// SidecarLogResult holds fields for storing extracted results
4949
type SidecarLogResult struct {
50-
Name string
51-
Value string
52-
Type SidecarLogResultType
50+
Name string `json:"name"`
51+
Value string `json:"value"`
52+
Type SidecarLogResultType `json:"type"`
5353
}
5454

5555
func fileExists(filename string) (bool, error) {
@@ -91,7 +91,7 @@ func waitForStepsToFinish(runDir string) error {
9191
// in either case, existence of out.err marks that the step errored and the following steps will
9292
// not run. We want the function to break out with nil error in that case so that
9393
// the existing results can be logged.
94-
if exists, err = fileExists(fmt.Sprintf("%s.err", stepFile)); exists || err != nil {
94+
if exists, err = fileExists(stepFile + ".err"); exists || err != nil {
9595
return err
9696
}
9797
}

internal/sidecarlogresults/sidecarlogresults_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ import (
4040
func TestLookForResults_FanOutAndWait(t *testing.T) {
4141
for _, c := range []struct {
4242
desc string
43-
results []SidecarLogResult
43+
Results []SidecarLogResult `json:"result"`
4444
}{{
4545
desc: "multiple results",
46-
results: []SidecarLogResult{{
46+
Results: []SidecarLogResult{{
4747
Name: "foo",
4848
Value: "bar",
4949
Type: "task",
@@ -57,7 +57,7 @@ func TestLookForResults_FanOutAndWait(t *testing.T) {
5757
dir := t.TempDir()
5858
resultNames := []string{}
5959
wantResults := []byte{}
60-
for _, result := range c.results {
60+
for _, result := range c.Results {
6161
createResult(t, dir, result.Name, result.Value)
6262
resultNames = append(resultNames, result.Name)
6363
encodedResult, err := json.Marshal(result)
@@ -363,7 +363,7 @@ func TestParseResults_InvalidType(t *testing.T) {
363363
}
364364
for _, plog := range podLogs {
365365
_, err := parseResults([]byte(plog), 4096)
366-
wantErr := fmt.Errorf("invalid sidecar result type not task or step. Must be task or step")
366+
wantErr := errors.New("invalid sidecar result type not task or step. Must be task or step")
367367
if d := cmp.Diff(wantErr.Error(), err.Error()); d != "" {
368368
t.Fatal(diff.PrintWantGot(d))
369369
}
@@ -468,7 +468,7 @@ func TestExtractStepAndResultFromSidecarResultName(t *testing.T) {
468468
func TestExtractStepAndResultFromSidecarResultName_Error(t *testing.T) {
469469
sidecarResultName := "step-foo-resultName"
470470
_, _, err := ExtractStepAndResultFromSidecarResultName(sidecarResultName)
471-
wantErr := fmt.Errorf("invalid string step-foo-resultName : expected somtthing that looks like <stepName>.<resultName>")
471+
wantErr := errors.New("invalid string step-foo-resultName : expected somtthing that looks like <stepName>.<resultName>")
472472
if d := cmp.Diff(wantErr.Error(), err.Error()); d != "" {
473473
t.Fatal(diff.PrintWantGot(d))
474474
}
@@ -477,9 +477,9 @@ func TestExtractStepAndResultFromSidecarResultName_Error(t *testing.T) {
477477
func createStepResult(t *testing.T, dir, stepName, resultName, resultValue string) {
478478
t.Helper()
479479
resultDir := filepath.Join(dir, stepName, "results")
480-
_ = os.MkdirAll(resultDir, 0755)
480+
_ = os.MkdirAll(resultDir, 0o755)
481481
resultFile := filepath.Join(resultDir, resultName)
482-
err := os.WriteFile(resultFile, []byte(resultValue), 0644)
482+
err := os.WriteFile(resultFile, []byte(resultValue), 0o644)
483483
if err != nil {
484484
t.Fatal(err)
485485
}
@@ -488,7 +488,7 @@ func createStepResult(t *testing.T, dir, stepName, resultName, resultValue strin
488488
func createResult(t *testing.T, dir string, resultName string, resultValue string) {
489489
t.Helper()
490490
resultFile := filepath.Join(dir, resultName)
491-
err := os.WriteFile(resultFile, []byte(resultValue), 0644)
491+
err := os.WriteFile(resultFile, []byte(resultValue), 0o644)
492492
if err != nil {
493493
t.Fatal(err)
494494
}
@@ -497,12 +497,12 @@ func createResult(t *testing.T, dir string, resultName string, resultValue strin
497497
func createRun(t *testing.T, dir string, causeErr bool) {
498498
t.Helper()
499499
stepFile := filepath.Join(dir, "1")
500-
_ = os.Mkdir(stepFile, 0755)
500+
_ = os.Mkdir(stepFile, 0o755)
501501
stepFile = filepath.Join(stepFile, "out")
502502
if causeErr {
503503
stepFile += ".err"
504504
}
505-
err := os.WriteFile(stepFile, []byte(""), 0644)
505+
err := os.WriteFile(stepFile, []byte(""), 0o644)
506506
if err != nil {
507507
t.Fatal(err)
508508
}

pkg/apis/config/events.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"fmt"
20+
"errors"
2121
"os"
2222
"sort"
2323
"strings"
@@ -106,17 +106,17 @@ func (efs EventFormats) Equals(other EventFormats) bool {
106106
func ParseEventFormats(formats string) (EventFormats, error) {
107107
// An empty string is not a valid configuration
108108
if formats == "" {
109-
return EventFormats{}, fmt.Errorf("formats cannot be empty")
109+
return EventFormats{}, errors.New("formats cannot be empty")
110110
}
111111
stringFormats := strings.Split(formats, ",")
112112
var eventFormats EventFormats = make(map[EventFormat]struct{}, len(stringFormats))
113113
for _, format := range stringFormats {
114114
if !EventFormat(format).IsValid() {
115-
return EventFormats{}, fmt.Errorf("invalid format: %s", format)
115+
return EventFormats{}, errors.New("invalid format: " + format)
116116
}
117117
// If already in the map (duplicate), fail
118118
if _, ok := eventFormats[EventFormat(format)]; ok {
119-
return EventFormats{}, fmt.Errorf("duplicate format: %s", format)
119+
return EventFormats{}, errors.New("duplicate format: " + format)
120120
}
121121
eventFormats[EventFormat(format)] = struct{}{}
122122
}

pkg/apis/config/feature_flags.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ var (
146146
DefaultEnableStepActions = PerFeatureFlag{
147147
Name: EnableStepActions,
148148
Stability: AlphaAPIFields,
149-
Enabled: DefaultAlphaFeatureEnabled}
149+
Enabled: DefaultAlphaFeatureEnabled,
150+
}
150151

151152
// DefaultEnableArtifacts is the default PerFeatureFlag value for EnableStepActions
152153
DefaultEnableArtifacts = PerFeatureFlag{
153154
Name: EnableStepActions,
154155
Stability: AlphaAPIFields,
155-
Enabled: DefaultAlphaFeatureEnabled}
156+
Enabled: DefaultAlphaFeatureEnabled,
157+
}
156158

157159
// DefaultEnableParamEnum is the default PerFeatureFlag value for EnableParamEnum
158160
DefaultEnableParamEnum = PerFeatureFlag{
@@ -164,8 +166,6 @@ var (
164166

165167
// FeatureFlags holds the features configurations
166168
// +k8s:deepcopy-gen=true
167-
//
168-
//nolint:musttag
169169
type FeatureFlags struct {
170170
DisableAffinityAssistant bool
171171
DisableCredsInit bool
@@ -349,7 +349,7 @@ func setCoschedule(cfgMap map[string]string, defaultValue string, disabledAffini
349349
// setEnforceNonFalsifiability sets the "enforce-nonfalsifiability" flag based on the content of a given map.
350350
// If the feature gate is invalid, then an error is returned.
351351
func setEnforceNonFalsifiability(cfgMap map[string]string, feature *string) error {
352-
var value = DefaultEnforceNonfalsifiability
352+
value := DefaultEnforceNonfalsifiability
353353
if cfg, ok := cfgMap[enforceNonfalsifiability]; ok {
354354
value = strings.ToLower(cfg)
355355
}
@@ -393,7 +393,7 @@ func setMaxResultSize(cfgMap map[string]string, defaultValue int, feature *int)
393393
}
394394
// if max limit is > 1.5 MB (CRD limit).
395395
if value >= 1572864 {
396-
return fmt.Errorf("invalid value for feature flag %q: %q. This is exceeding the CRD limit", resultExtractionMethod, fmt.Sprint(value))
396+
return fmt.Errorf("invalid value for feature flag %q: %q. This is exceeding the CRD limit", resultExtractionMethod, strconv.Itoa(value))
397397
}
398398
*feature = value
399399
return nil

pkg/apis/config/resolver/store.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package resolver
1818

1919
import (
2020
"context"
21-
"fmt"
2221

2322
"knative.dev/pkg/configmap"
2423
)
@@ -33,7 +32,7 @@ type Config struct {
3332

3433
// ResolversNamespace takes the pipelines namespace and appends "-resolvers" to it.
3534
func ResolversNamespace(baseNS string) string {
36-
return fmt.Sprintf("%s-resolvers", baseNS)
35+
return baseNS + "-resolvers"
3736
}
3837

3938
// FromContext extracts a Config from the provided context.

0 commit comments

Comments
 (0)