Skip to content

Commit fb5a141

Browse files
committed
Migrate golangci-lint cfg to v2. Fix new findings
The new v2 version of `golangci-lint` comes with configuration file structure and therefore the configuration had to be migrated. I simply had to execute `golangci-lint migrate` and copy the comments to the new config as they are not touched by the migration. There were also few minor new findings that had to be fixed.
1 parent b55f392 commit fb5a141

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

.golangci.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
version: "2"
23
run:
34
# Timeout for analysis, e.g. 30s, 5m.
45
# Default: 1m
@@ -12,16 +13,35 @@ linters:
1213
- gocyclo
1314
# Inspects source code for security problems.
1415
- gosec
15-
linters-settings:
16-
gocyclo:
17-
# Minimal code complexity to report.
18-
# https://github.com/fzipp/gocyclo#readme
19-
min-complexity: 28
20-
gosec:
21-
excludes:
22-
- G115
16+
settings:
17+
gocyclo:
18+
# Minimal code complexity to report.
19+
# https://github.com/fzipp/gocyclo#readme
20+
min-complexity: 28
21+
gosec:
22+
excludes:
23+
# Ignore controversial integer overflow warnings.
24+
- G115
25+
exclusions:
26+
generated: lax
27+
presets:
28+
- comments
29+
- common-false-positives
30+
- legacy
31+
- std-error-handling
32+
paths:
33+
- third_party$
34+
- builtin$
35+
- examples$
2336
issues:
2437
# Disable max issues per linter.
2538
max-issues-per-linter: 0
2639
# Disable max same issues.
2740
max-same-issues: 0
41+
formatters:
42+
exclusions:
43+
generated: lax
44+
paths:
45+
- third_party$
46+
- builtin$
47+
- examples$

internal/command/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func getOptions(args []string, log Logger, mopts ...MetaOption) optionsFlags {
340340
}
341341
}
342342

343-
if opts.ShowGUID && !(_platform.Equal(opts.SourceType) || _all.Equal(opts.SourceType) || _default.Equal(opts.SourceType)) {
343+
if opts.ShowGUID && !_platform.Equal(opts.SourceType) && !_all.Equal(opts.SourceType) && !_default.Equal(opts.SourceType) {
344344
log.Fatalf("Source type must be 'platform' when using the --guid flag")
345345
}
346346

internal/command/query.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query
132132
}
133133

134134
if len(args) != 1 {
135-
return queryOptions{}, fmt.Errorf("Expected 1 argument, got %d.", len(args))
135+
return queryOptions{}, fmt.Errorf("expected 1 argument, got %d", len(args))
136136
}
137137

138138
if isInstantQuery(opts) && !validInstantQueryArgs(opts) {
139-
return queryOptions{}, errors.New("When issuing an instant query, you cannot specify --start, --end, or --step")
139+
return queryOptions{}, errors.New("when issuing an instant query, you cannot specify --start, --end, or --step")
140140
}
141141

142142
if isRangeQuery(opts) && !validRangeQueryArgs(opts) {
143-
return queryOptions{}, errors.New("When issuing a range query, you must specify all of --start, --end, and --step")
143+
return queryOptions{}, errors.New("when issuing a range query, you must specify all of --start, --end, and --step")
144144
}
145145

146146
if isInstantQuery(opts) {
@@ -150,7 +150,7 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query
150150

151151
parsedTime, err := getParsedTime(opts.Time)
152152
if err != nil {
153-
return queryOptions{}, fmt.Errorf("Couldn't parse --time: %s", err.Error())
153+
return queryOptions{}, fmt.Errorf("couldn't parse --time: %s", err.Error())
154154
}
155155

156156
return queryOptions{timeProvided: true, time: parsedTime}, nil
@@ -159,11 +159,11 @@ func newQueryOptions(cli plugin.CliConnection, args []string, log Logger) (query
159159
if isRangeQuery(opts) {
160160
parsedStart, err := getParsedTime(opts.Start)
161161
if err != nil {
162-
return queryOptions{}, fmt.Errorf("Couldn't parse --start: %s", err.Error())
162+
return queryOptions{}, fmt.Errorf("couldn't parse --start: %s", err.Error())
163163
}
164164
parsedEnd, err := getParsedTime(opts.End)
165165
if err != nil {
166-
return queryOptions{}, fmt.Errorf("Couldn't parse --end: %s", err.Error())
166+
return queryOptions{}, fmt.Errorf("couldn't parse --end: %s", err.Error())
167167
}
168168

169169
return queryOptions{start: parsedStart, end: parsedEnd, step: opts.Step, rangeQuery: true}, nil

internal/command/query_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var _ = Describe("LogCache", func() {
7373
}).To(Panic())
7474

7575
Expect(tc.logger.fatalfMessage).To(HavePrefix(
76-
"When issuing a range query, you must specify all of --start, --end, and --step",
76+
"when issuing a range query, you must specify all of --start, --end, and --step",
7777
))
7878
})
7979

@@ -85,7 +85,7 @@ var _ = Describe("LogCache", func() {
8585
}).To(Panic())
8686

8787
Expect(tc.logger.fatalfMessage).To(HavePrefix(
88-
"When issuing an instant query, you cannot specify --start, --end, or --step",
88+
"when issuing an instant query, you cannot specify --start, --end, or --step",
8989
))
9090
})
9191

@@ -152,7 +152,7 @@ var _ = Describe("LogCache", func() {
152152
}).To(Panic())
153153

154154
Expect(tc.logger.fatalfMessage).To(HavePrefix(
155-
fmt.Sprintf("Couldn't parse --time: invalid time format: %s", timeArg),
155+
fmt.Sprintf("couldn't parse --time: invalid time format: %s", timeArg),
156156
))
157157
},
158158
Entry("with an arbitary string", "asdfkj"),
@@ -229,7 +229,7 @@ var _ = Describe("LogCache", func() {
229229
}).To(Panic())
230230

231231
Expect(tc.logger.fatalfMessage).To(HavePrefix(
232-
fmt.Sprintf("Couldn't parse --%s: invalid time format: %s", invalidField, invalidArg),
232+
fmt.Sprintf("couldn't parse --%s: invalid time format: %s", invalidField, invalidArg),
233233
))
234234
},
235235
Entry("with an arbitary string for start", "start", "asdfkj"),

internal/command/tail.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ func newTailOptions(cli plugin.CliConnection, args []string, log Logger) (tailOp
238238
}
239239

240240
if len(args) != 1 {
241-
return tailOptions{}, fmt.Errorf("Expected 1 argument, got %d.", len(args))
241+
return tailOptions{}, fmt.Errorf("expected 1 argument, got %d", len(args))
242242
}
243243

244244
if opts.JSONOutput && opts.OutputFormat != "" {
245-
return tailOptions{}, errors.New("Cannot use output-format and json flags together")
245+
return tailOptions{}, errors.New("cannot use output-format and json flags together")
246246
}
247247

248248
if opts.EnvelopeType != "" && opts.EnvelopeClass != "" {
@@ -331,16 +331,16 @@ func typeFilter(e *loggregator_v2.Envelope, o tailOptions) bool {
331331

332332
func (o tailOptions) validate() error {
333333
if o.startTime.After(o.endTime) && o.endTime != time.Unix(0, 0) {
334-
return errors.New("Invalid date/time range. Ensure your start time is prior or equal the end time.")
334+
return errors.New("invalid date/time range. Ensure your start time is prior or equal the end time")
335335
}
336336

337337
if o.lines > 1000 || o.lines < 0 {
338-
return errors.New("Lines cannot be greater than 1000.")
338+
return errors.New("lines cannot be greater than 1000")
339339
}
340340

341341
_, err := regexp.Compile(o.nameFilter)
342342
if err != nil {
343-
return fmt.Errorf("Invalid name filter '%s'. Ensure your name-filter is a valid regex.", o.nameFilter)
343+
return fmt.Errorf("invalid name filter '%s'. Ensure your name-filter is a valid regex", o.nameFilter)
344344
}
345345

346346
return nil

internal/command/tail_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ var _ = Describe("LogCache", func() {
11021102
)
11031103
}).To(Panic())
11041104

1105-
Expect(logger.fatalfMessage).To(Equal("Cannot use output-format and json flags together"))
1105+
Expect(logger.fatalfMessage).To(Equal("cannot use output-format and json flags together"))
11061106
})
11071107

11081108
It("fatally logs if an output-format is malformed", func() {
@@ -1158,7 +1158,7 @@ var _ = Describe("LogCache", func() {
11581158
)
11591159
}).To(Panic())
11601160

1161-
Expect(logger.fatalfMessage).To(Equal("Lines cannot be greater than 1000."))
1161+
Expect(logger.fatalfMessage).To(Equal("lines cannot be greater than 1000"))
11621162
})
11631163

11641164
It("accepts 0 for --lines", func() {
@@ -1245,7 +1245,7 @@ var _ = Describe("LogCache", func() {
12451245
)
12461246
}).To(Panic())
12471247

1248-
Expect(logger.fatalfMessage).To(Equal("Invalid date/time range. Ensure your start time is prior or equal the end time."))
1248+
Expect(logger.fatalfMessage).To(Equal("invalid date/time range. Ensure your start time is prior or equal the end time"))
12491249
})
12501250

12511251
It("fatally logs if the name-filter regex is invalid", func() {
@@ -1261,7 +1261,7 @@ var _ = Describe("LogCache", func() {
12611261
)
12621262
}).To(Panic())
12631263

1264-
Expect(logger.fatalfMessage).To(Equal("Invalid name filter '*foo'. Ensure your name-filter is a valid regex."))
1264+
Expect(logger.fatalfMessage).To(Equal("invalid name filter '*foo'. Ensure your name-filter is a valid regex"))
12651265
})
12661266

12671267
It("fatally logs if too many arguments are given", func() {
@@ -1276,7 +1276,7 @@ var _ = Describe("LogCache", func() {
12761276
)
12771277
}).To(Panic())
12781278

1279-
Expect(logger.fatalfMessage).To(Equal("Expected 1 argument, got 2."))
1279+
Expect(logger.fatalfMessage).To(Equal("expected 1 argument, got 2"))
12801280
})
12811281

12821282
It("fatally logs if not enough arguments are given", func() {
@@ -1291,7 +1291,7 @@ var _ = Describe("LogCache", func() {
12911291
)
12921292
}).To(Panic())
12931293

1294-
Expect(logger.fatalfMessage).To(Equal("Expected 1 argument, got 0."))
1294+
Expect(logger.fatalfMessage).To(Equal("expected 1 argument, got 0"))
12951295
})
12961296

12971297
Context("when name-filter argument is not supplied", func() {

0 commit comments

Comments
 (0)