Skip to content

Commit 4f70f3a

Browse files
committed
Golangci-lint update to 1.24 and migration from version 1 -> 2
1 parent 4008cd4 commit 4f70f3a

File tree

111 files changed

+425
-429
lines changed

Some content is hidden

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

111 files changed

+425
-429
lines changed

.golangci.yml

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1-
run:
2-
timeout: 10m
3-
1+
version: "2"
42
linters:
3+
default: none
54
enable:
6-
- unused
7-
- gosimple
8-
- gofmt
9-
- govet
10-
- staticcheck
11-
- unparam
12-
- unconvert
5+
- bodyclose
136
- errcheck
7+
- errorlint
8+
- govet
149
- ineffassign
1510
- misspell
16-
- bodyclose
17-
- errorlint
18-
disable-all: true
19-
20-
linters-settings:
21-
errorlint:
22-
errorf: true
23-
errorf-multi: false
24-
asserts: false
25-
comparison: false
26-
misspell:
27-
ignore-words:
28-
- creater
29-
30-
issues:
31-
exclude-rules:
32-
- linters:
33-
- unparam
34-
text: \(\*leaseStep\)\.Provides\$1 - result 1 \(error\) is always nil
35-
- linters:
3611
- staticcheck
37-
# Code has a "Deprecated:" comment
38-
text: "SA1019:"
12+
- unconvert
13+
- unparam
14+
- unused
15+
settings:
16+
errorlint:
17+
errorf: true
18+
errorf-multi: false
19+
asserts: false
20+
comparison: false
21+
misspell:
22+
ignore-rules:
23+
- creater
24+
exclusions:
25+
generated: lax
26+
presets:
27+
- comments
28+
- common-false-positives
29+
- legacy
30+
- std-error-handling
31+
rules:
32+
- linters:
33+
- unparam
34+
text: \(\*leaseStep\)\.Provides\$1 - result 1 \(error\) is always nil
35+
- linters:
36+
- staticcheck
37+
text: 'SA1019:'
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- gofmt
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$

cmd/applyconfig/applyconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ func makeOcApply(kubeConfig, context, path, user string, dry dryRunMethod, apply
188188
cmd.Args = append(cmd.Args, "--dry-run=server", "--validate=true")
189189
case dryClient:
190190
cmd.Args = append(cmd.Args, "--dry-run=client")
191-
default:
192-
panic(fmt.Sprintf("BUG: Unknown dry run method '%s' received, this should never happen", string(dry)))
193191
case dryNone:
194192
// No additional args needed
193+
default:
194+
panic(fmt.Sprintf("BUG: Unknown dry run method '%s' received, this should never happen", string(dry)))
195195
}
196196

197197
fileName := filepath.Base(path)

cmd/autoconfigbrancher/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type options struct {
5151
func parseOptions() options {
5252
var o options
5353
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
54-
o.FutureOptions.Bind(fs)
54+
o.Bind(fs)
5555
fs.StringVar(&o.githubLogin, "github-login", githubLogin, "The GitHub username to use.")
5656
fs.StringVar(&o.gitName, "git-name", "", "The name to use on the git commit. Requires --git-email. If not specified, uses the system default.")
5757
fs.StringVar(&o.gitEmail, "git-email", "", "The email to use on the git commit. Requires --git-name. If not specified, uses the system default.")
@@ -135,11 +135,11 @@ func main() {
135135
logrus.WithError(fmt.Errorf("version %s split by dot doesn't have two elements", o.CurrentRelease)).Fatal("Failed to parse the current version")
136136
}
137137

138-
if err := secret.Add(o.GitHubOptions.TokenPath); err != nil {
138+
if err := secret.Add(o.TokenPath); err != nil {
139139
logrus.WithError(err).Fatal("Failed to start secrets agent")
140140
}
141141

142-
gc, err := o.GitHubOptions.GitHubClient(!o.Confirm)
142+
gc, err := o.GitHubClient(!o.Confirm)
143143
if err != nil {
144144
logrus.WithError(err).Fatal("error getting GitHub client")
145145
}
@@ -292,7 +292,7 @@ func main() {
292292
func runSteps(steps []step, author string, stdout, stderr io.Writer) (needsPushing bool, err error) {
293293
startCommitOut, err := exec.Command("git", "rev-parse", "HEAD").CombinedOutput()
294294
if err != nil {
295-
return false, fmt.Errorf("failed to execute `git rev-parse HEAD`: %w\noutput:%s\n", err, string(startCommitOut))
295+
return false, fmt.Errorf("failed to execute `git rev-parse HEAD`: %w\noutput:%s", err, string(startCommitOut))
296296
}
297297
startCommitSHA := strings.TrimSpace(string(startCommitOut))
298298

@@ -313,7 +313,7 @@ func runSteps(steps []step, author string, stdout, stderr io.Writer) (needsPushi
313313

314314
overallDiff, err := exec.Command("git", "diff", startCommitSHA).CombinedOutput()
315315
if err != nil {
316-
return false, fmt.Errorf("failed to check the overall diff: %w, out:\n%s\n", err, string(overallDiff))
316+
return false, fmt.Errorf("failed to check the overall diff: %w, out:\n%s", err, string(overallDiff))
317317
}
318318
if strings.TrimSpace(string(overallDiff)) == "" {
319319
logrus.Info("Empty overall diff")

cmd/autoperibolossync/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func validateOptions(o options) error {
9191
if o.peribolosConfig == "" {
9292
return errors.New("--peribolos-config is not specified")
9393
}
94-
return o.GitHubOptions.Validate(o.dryRun)
94+
return o.Validate(o.dryRun)
9595
}
9696

9797
func main() {
@@ -100,11 +100,11 @@ func main() {
100100
logrus.WithError(err).Fatal("Invalid arguments.")
101101
}
102102

103-
if err := secret.Add(o.GitHubOptions.TokenPath); err != nil {
103+
if err := secret.Add(o.TokenPath); err != nil {
104104
logrus.WithError(err).Fatal("Failed to start secrets agent")
105105
}
106106

107-
gc, err := o.GitHubOptions.GitHubClient(o.dryRun)
107+
gc, err := o.GitHubClient(o.dryRun)
108108
if err != nil {
109109
logrus.WithError(err).Fatal("error getting GitHub client")
110110
}
@@ -150,7 +150,7 @@ func main() {
150150
}
151151

152152
title := fmt.Sprintf("%s %s", matchTitle, time.Now().Format(time.RFC1123))
153-
if err := bumper.GitCommitAndPush(fmt.Sprintf("https://%s:%[email protected]/%s/%s.git", o.githubLogin, string(secret.GetTokenGenerator(o.GitHubOptions.TokenPath)()), o.githubLogin, githubRepo), remoteBranch, o.gitName, o.gitEmail, title, stdout, stderr, o.dryRun); err != nil {
153+
if err := bumper.GitCommitAndPush(fmt.Sprintf("https://%s:%[email protected]/%s/%s.git", o.githubLogin, string(secret.GetTokenGenerator(o.TokenPath)()), o.githubLogin, githubRepo), remoteBranch, o.gitName, o.gitEmail, title, stdout, stderr, o.dryRun); err != nil {
154154
logrus.WithError(err).Fatal("Failed to push changes.")
155155
}
156156

cmd/autopublicizeconfig/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func parseOptions() options {
6060
fs.StringVar(&o.releaseRepoPath, "release-repo-path", "", "Path to a openshift/release repository directory")
6161

6262
o.AddFlags(fs)
63-
o.WhitelistOptions.Bind(fs)
63+
o.Bind(fs)
6464

6565
if err := fs.Parse(os.Args[1:]); err != nil {
6666
logrus.WithError(err).Errorf("cannot parse args: '%s'", os.Args[1:])
@@ -97,17 +97,17 @@ func main() {
9797
logrus.WithError(err).Fatal("Invalid arguments.")
9898
}
9999

100-
if err := secret.Add(o.GitHubOptions.TokenPath); err != nil {
100+
if err := secret.Add(o.TokenPath); err != nil {
101101
logrus.WithError(err).Fatal("Failed to start secrets agent")
102102
}
103103

104-
gc, err := o.GitHubOptions.GitHubClient(o.dryRun)
104+
gc, err := o.GitHubClient(o.dryRun)
105105
if err != nil {
106106
logrus.WithError(err).Fatal("error getting GitHub client")
107107
}
108108

109109
logrus.Info("Getting repositories that exists in the whitelist or promote official images")
110-
orgRepos, err := getReposForPrivateOrg(o.releaseRepoPath, o.WhitelistOptions.WhitelistConfig.Whitelist)
110+
orgRepos, err := getReposForPrivateOrg(o.releaseRepoPath, o.WhitelistConfig.Whitelist)
111111
if err != nil {
112112
logrus.WithError(err).Fatal("couldn't get the list of org/repos that promote official images")
113113
}
@@ -157,7 +157,7 @@ func main() {
157157

158158
logrus.Info("Preparing pull request")
159159
title := fmt.Sprintf("%s %s", matchTitle, time.Now().Format(time.RFC1123))
160-
if err := bumper.GitCommitAndPush(fmt.Sprintf("https://%s:%[email protected]/%s/%s.git", o.githubLogin, string(secret.GetTokenGenerator(o.GitHubOptions.TokenPath)()), o.githubLogin, githubRepo), remoteBranch, o.gitName, o.gitEmail, title, stdout, stderr, o.dryRun); err != nil {
160+
if err := bumper.GitCommitAndPush(fmt.Sprintf("https://%s:%[email protected]/%s/%s.git", o.githubLogin, string(secret.GetTokenGenerator(o.TokenPath)()), o.githubLogin, githubRepo), remoteBranch, o.gitName, o.gitEmail, title, stdout, stderr, o.dryRun); err != nil {
161161
logrus.WithError(err).Fatal("Failed to push changes.")
162162
}
163163

cmd/autotestgridgenerator/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func parseOptions() options {
5252
fs.StringVar(&o.upstreamBranch, "upstream-branch", upstreamBranch, "The repository branch name where the PR will be created.")
5353

5454
o.GitAuthorOptions.AddFlags(fs)
55-
o.PRCreationOptions.GitHubOptions.AddFlags(fs)
55+
o.GitHubOptions.AddFlags(fs)
5656
if err := fs.Parse(os.Args[1:]); err != nil {
5757
logrus.WithError(err).Errorf("cannot parse args: '%s'", os.Args[1:])
5858
}
5959
return o
6060
}
6161

6262
func validateOptions(o options) error {
63-
if err := o.GitAuthorOptions.Validate(); err != nil {
63+
if err := o.Validate(); err != nil {
6464
return err
6565
}
6666
return o.GitHubOptions.Validate(false)
@@ -71,7 +71,7 @@ func main() {
7171
if err := validateOptions(o); err != nil {
7272
logrus.WithError(err).Fatal("Invalid arguments.")
7373
}
74-
if err := o.PRCreationOptions.Finalize(); err != nil {
74+
if err := o.Finalize(); err != nil {
7575
logrus.WithError(err).Fatal("failed to finalize PR creation options")
7676
}
7777

@@ -96,7 +96,7 @@ func main() {
9696
logrus.WithError(err).Fatalf("failed to run %s", fullCommand)
9797
}
9898
title := fmt.Sprintf("%s at %s", matchTitle, time.Now().Format(time.RFC1123))
99-
err = o.PRCreationOptions.UpsertPR(o.workingDir, o.githubOrg, githubRepo, o.upstreamBranch, title, prcreation.PrAssignee(o.assign), prcreation.MatchTitle(matchTitle))
99+
err = o.UpsertPR(o.workingDir, o.githubOrg, githubRepo, o.upstreamBranch, title, prcreation.PrAssignee(o.assign), prcreation.MatchTitle(matchTitle))
100100
if err != nil {
101101
logrus.WithError(err).Fatalf("failed to upsert PR")
102102
}

cmd/blocking-issue-creator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func gatherOptions() options {
5050
fs.BoolVar(&o.dryRun, "dry-run", true, "Dry run for testing. Uses API tokens but does not mutate.")
5151

5252
o.github.AddFlags(fs)
53-
o.FutureOptions.Bind(fs)
53+
o.Bind(fs)
5454

5555
if err := fs.Parse(os.Args[1:]); err != nil {
5656
logrus.WithError(err).Fatal("could not parse input")

cmd/blocking-issue-creator/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type fakeGithubClient struct {
2121

2222
func (f fakeGithubClient) FindIssues(query, sortVerb string, asc bool) ([]github.Issue, error) {
2323
var issues []github.Issue
24-
for _, issue := range f.FakeClient.Issues {
24+
for _, issue := range f.Issues {
2525
issues = append(issues, *issue)
2626
}
2727
sort.Slice(issues, func(i, j int) bool { return issues[i].ID < issues[j].ID })
@@ -222,7 +222,7 @@ func TestManageIssues(t *testing.T) {
222222
fgh := fakeGithubClient{
223223
FakeClient: fakegithub.NewFakeClient(),
224224
}
225-
fgh.FakeClient.Issues = tc.issues
225+
fgh.Issues = tc.issues
226226

227227
if err := manageIssues(fgh, "", tc.repoInfo, tc.branches, logrus.WithField("id", tc.id)); err != nil {
228228
t.Fatal(err)

cmd/branchingconfigmanagers/frequency-reducer/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type options struct {
2525

2626
func (o options) validate() error {
2727
var errs []error
28-
if err := o.ConfirmableOptions.Validate(); err != nil {
28+
if err := o.Validate(); err != nil {
2929
errs = append(errs, err)
3030
}
3131

@@ -53,7 +53,7 @@ func main() {
5353
logrus.Fatalf("Not valid --current-release: %v", err)
5454
}
5555

56-
if err := o.ConfirmableOptions.Complete(); err != nil {
56+
if err := o.Complete(); err != nil {
5757
logrus.Fatalf("Couldn't complete the config options: %v", err)
5858
}
5959

@@ -75,11 +75,11 @@ func updateIntervalFieldsForMatchedSteps(
7575
configuration *config.DataWithInfo,
7676
version ocplifecycle.MajorMinor,
7777
) {
78-
testVersion, err := ocplifecycle.ParseMajorMinor(extractVersion(configuration.Info.Metadata.Branch))
78+
testVersion, err := ocplifecycle.ParseMajorMinor(extractVersion(configuration.Info.Branch))
7979
if err != nil {
8080
return
8181
}
82-
if configuration.Info.Metadata.Org == "openshift" || configuration.Info.Metadata.Org == "openshift-priv" {
82+
if configuration.Info.Org == "openshift" || configuration.Info.Org == "openshift-priv" {
8383
for _, test := range configuration.Configuration.Tests {
8484
if !strings.Contains(test.As, "mirror-nightly-image") && !strings.Contains(test.As, "promote-") {
8585
if test.Cron != nil {

cmd/branchingconfigmanagers/tide-config-manager/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func (gae *generalAvailabilityEvent) ensureStaffEngApprovedLabel(q *prowconfig.T
334334
branches.Insert(gae.openshiftFuture)
335335
}
336336

337-
if !(branches.Equal(sets.New[string](gae.releaseFuture)) || branches.Equal(sets.New[string](gae.openshiftFuture)) || branches.Equal(gae.openshiftReleaseBranchesPlus1)) {
337+
if !branches.Equal(sets.New[string](gae.releaseFuture)) && !branches.Equal(sets.New[string](gae.openshiftFuture)) && !branches.Equal(gae.openshiftReleaseBranchesPlus1) {
338338
fmt.Printf("Suspicious staff-eng-approved query: %s\n", q.Repos)
339339
}
340340
}

0 commit comments

Comments
 (0)