Skip to content

Commit 5ed02c5

Browse files
committed
Add linter gocritic and fix issues
1 parent 5922818 commit 5ed02c5

File tree

40 files changed

+161
-164
lines changed

40 files changed

+161
-164
lines changed

.golangci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"errorlint",
1515
"funlen",
1616
"ginkgolinter",
17+
"gocritic",
1718
"gocyclo",
1819
"gosec",
1920
"govet",

benchmarks/cmd/dataset.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ func calculate(sample *parser.Sample, dsPop Dataset, scores scoresByXP) {
8888
}
8989

9090
if _, ok := sample.Experiments[experiment]; !ok {
91-
//fmt.Printf("missing experiment %s\n", name)
91+
// fmt.Printf("missing experiment %s\n", name)
9292
continue
9393
}
9494

9595
if _, ok := sample.Experiments[experiment].Measurements[measurement]; !ok {
96-
//fmt.Printf("missing measurement %s for experiments %s\n", measurement, name)
96+
// fmt.Printf("missing measurement %s for experiments %s\n", measurement, name)
9797
continue
9898
}
9999

@@ -104,7 +104,7 @@ func calculate(sample *parser.Sample, dsPop Dataset, scores scoresByXP) {
104104
// calculate zscore
105105
m := sample.Experiments[experiment].Measurements[measurement]
106106
zscore := stat.StdScore(m.Value, mean, stddev)
107-
//fmt.Printf("zscore %s - %s %v %v %v\n", experiment, measurement, m, mean, zscore)
107+
// fmt.Printf("zscore %s - %s %v %v %v\n", experiment, measurement, m, mean, zscore)
108108

109109
// store in dsPop
110110
sg.Mean = mean
@@ -125,7 +125,7 @@ func calculate(sample *parser.Sample, dsPop Dataset, scores scoresByXP) {
125125
avg := stat.Mean(xp.ZScores, xp.Weights)
126126
xp.MeanZScore = avg
127127
scores[name] = xp
128-
//fmt.Printf("%s %v %v %v\n", name, avg, xp.ZScores, xp.Weights)
128+
// fmt.Printf("%s %v %v %v\n", name, avg, xp.ZScores, xp.Weights)
129129
}
130130

131131
}

benchmarks/cmd/report.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@ func newTableZScore(rows map[string]Row) *table.Table {
195195
r.AppendCell(table.C(fmt.Sprintf("%.02fs", row.StdDevDuration)))
196196
r.AppendCell(table.C(fmt.Sprintf("%.02f", row.ZScore)))
197197
}
198-
if row.ZScore < 0 {
198+
switch {
199+
case row.ZScore < 0:
199200
r.AppendCell(table.C("better"))
200-
} else if row.ZScore > 0 {
201+
case row.ZScore > 0:
201202
r.AppendCell(table.C("worse"))
202-
} else {
203+
default:
203204
r.AppendCell(table.C(""))
204205
}
205206

benchmarks/record/record.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ func Nodes(ctx context.Context, experiment *gm.Experiment) {
172172
for _, image := range node.Status.Images {
173173
name := ""
174174
// in k3d, the first image name contains the hash, not the tag
175-
if len(image.Names) == 0 {
175+
switch {
176+
case len(image.Names) == 0:
176177
continue
177-
} else if len(image.Names) > 1 {
178+
case len(image.Names) > 1:
178179
name = image.Names[1]
179-
} else {
180+
default:
180181
name = image.Names[0]
181182
}
182183
images[name] = struct{}{}

integrationtests/cli/apply/apply_online_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("Fleet apply online", Label("online"), func() {
3535
)
3636

3737
JustBeforeEach(func() {
38-
//Setting up all the needed mocked interfaces for the test
38+
// Setting up all the needed mocked interfaces for the test
3939
ctrl = gomock.NewController(GinkgoT())
4040
clientMock = mocks.NewMockK8sClient(ctrl)
4141
clientMock.EXPECT().Get(
@@ -68,7 +68,7 @@ var _ = Describe("Fleet apply online", Label("online"), func() {
6868
BeforeEach(func() {
6969
name = "labels_update"
7070
dirs = []string{cli.AssetsPath + "labels_update"}
71-
//bundle in the cluster
71+
// bundle in the cluster
7272
oldBundle = &fleet.Bundle{
7373
ObjectMeta: metav1.ObjectMeta{
7474
Labels: map[string]string{
@@ -129,7 +129,7 @@ data:
129129
BeforeEach(func() {
130130
name = "labels_update"
131131
dirs = []string{cli.AssetsPath + "labels_update"}
132-
//bundle in the cluster
132+
// bundle in the cluster
133133
oldBundle = &fleet.Bundle{
134134
ObjectMeta: metav1.ObjectMeta{
135135
Namespace: "foo",
@@ -160,7 +160,7 @@ data:
160160
ts := metav1.NewTime(time.Now())
161161
name = "labels_update"
162162
dirs = []string{cli.AssetsPath + "labels_update"}
163-
//bundle in the cluster
163+
// bundle in the cluster
164164
oldBundle = &fleet.Bundle{
165165
ObjectMeta: metav1.ObjectMeta{
166166
Namespace: "foo",
@@ -224,7 +224,7 @@ data:
224224
BeforeEach(func() {
225225
name = "labels_update"
226226
dirs = []string{cli.AssetsPath + "labels_update"}
227-
//bundle in the cluster
227+
// bundle in the cluster
228228
oldBundle = &fleet.Bundle{
229229
ObjectMeta: metav1.ObjectMeta{
230230
Namespace: "foo",

integrationtests/cli/helpers.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ func IsResourcePresentInBundle(resourcePath string, resources []v1alpha1.BundleR
7171
if resource.Content == resourceFileEncoded {
7272
return true, nil
7373
}
74-
} else {
75-
if strings.ReplaceAll(resource.Content, "\n", "") == strings.ReplaceAll(string(resourceFile), "\n", "") {
76-
return true, nil
77-
}
74+
} else if strings.ReplaceAll(resource.Content, "\n", "") == strings.ReplaceAll(string(resourceFile), "\n", "") {
75+
return true, nil
7876
}
7977
}
8078

integrationtests/controller/bundle/userid_logging_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ var _ = Describe("Bundle UserID logging", func() {
7272
return bundle.Status.ObservedGeneration
7373
}).Should(BeNumerically(">", 0))
7474

75-
Eventually(func() string {
76-
return logsBuffer.String()
77-
}).Should(ContainSubstring(bundle.Name))
75+
Eventually(logsBuffer.String).Should(ContainSubstring(bundle.Name))
7876
}
7977

8078
When("Bundle has user ID label", func() {

integrationtests/controller/bundledeployment/userid_logging_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ var _ = Describe("UserID logging", func() {
6363
})
6464

6565
It("logs userID in reconciliation", func() {
66-
Eventually(func() string {
67-
return logsBuffer.String()
68-
}).Should(ContainSubstring(bd.Name))
66+
Eventually(logsBuffer.String).Should(ContainSubstring(bd.Name))
6967

7068
logs := logsBuffer.String()
7169
bdLogs := utils.ExtractResourceLogs(logs, bd.Name)
@@ -117,9 +115,7 @@ var _ = Describe("UserID logging", func() {
117115
})
118116

119117
It("does not log userID in reconciliation", func() {
120-
Eventually(func() string {
121-
return logsBuffer.String()
122-
}).Should(ContainSubstring(bd.Name))
118+
Eventually(logsBuffer.String).Should(ContainSubstring(bd.Name))
123119

124120
logs := logsBuffer.String()
125121
bdLogs := utils.ExtractResourceLogs(logs, bd.Name)

integrationtests/gitjob/controller/userid_logging_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ var _ = Describe("GitRepo UserID logging", func() {
5555
})
5656

5757
It("includes userID in log output", func() {
58-
Eventually(func() string {
59-
return logsBuffer.String()
60-
}, timeout).Should(Or(
58+
Eventually(logsBuffer.String, timeout).Should(Or(
6159
ContainSubstring(`"userID":"`+userID+`"`),
6260
ContainSubstring(`"userID": "`+userID+`"`),
6361
))
@@ -74,9 +72,7 @@ var _ = Describe("GitRepo UserID logging", func() {
7472
})
7573

7674
It("does not include userID in log output", func() {
77-
Eventually(func() string {
78-
return logsBuffer.String()
79-
}, timeout).Should(ContainSubstring(gitrepo.Name))
75+
Eventually(logsBuffer.String, timeout).Should(ContainSubstring(gitrepo.Name))
8076

8177
logs := logsBuffer.String()
8278
gitrepoLogs := utils.ExtractResourceLogs(logs, gitrepo.Name)

integrationtests/helmops/controller/userid_logging_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ var _ = Describe("HelmOp UserID logging", func() {
6060
})
6161

6262
It("includes userID in log output", func() {
63-
Eventually(func() string {
64-
return logsBuffer.String()
65-
}, timeout).Should(Or(
63+
Eventually(logsBuffer.String, timeout).Should(Or(
6664
ContainSubstring(`"userID":"`+userID+`"`),
6765
ContainSubstring(`"userID": "`+userID+`"`),
6866
))
@@ -79,9 +77,7 @@ var _ = Describe("HelmOp UserID logging", func() {
7977
})
8078

8179
It("does not include userID in log output", func() {
82-
Eventually(func() string {
83-
return logsBuffer.String()
84-
}, timeout).Should(ContainSubstring(helmop.Name))
80+
Eventually(logsBuffer.String, timeout).Should(ContainSubstring(helmop.Name))
8581

8682
logs := logsBuffer.String()
8783
helmopLogs := utils.ExtractResourceLogs(logs, helmop.Name)

0 commit comments

Comments
 (0)