Skip to content

Commit cda1ef6

Browse files
committed
refactor: Migrate golang-ci-lint to 2.2.2
Along the way, address/ignore staticcheck linter issues.
1 parent 747e186 commit cda1ef6

File tree

9 files changed

+57
-45
lines changed

9 files changed

+57
-45
lines changed

.golangci.yml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,54 @@
1+
version: "2"
12
run:
23
build-tags:
34
- cap
45
- filament
5-
deadline: 10m
66

77
linters:
8-
disable-all: true
8+
default: none
99
enable:
1010
- bodyclose
1111
- errcheck
1212
- goconst
1313
- goprintffuncname
14-
- gosimple
1514
- govet
16-
- gofmt
1715
- ineffassign
1816
- nakedret
1917
- noctx
2018
- nolintlint
2119
- rowserrcheck
2220
- staticcheck
23-
- stylecheck
24-
- typecheck
2521
- unconvert
2622
- unparam
2723
- unused
2824
- whitespace
25+
exclusions:
26+
generated: lax
27+
presets:
28+
- comments
29+
- common-false-positives
30+
- legacy
31+
- std-error-handling
32+
rules:
33+
- linters:
34+
- errcheck
35+
- nolintlint
36+
- staticcheck
37+
path: _test\.go
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
2942

30-
linters-settings:
31-
gofmt:
32-
simplify: false
33-
34-
issues:
35-
# List of regexps of issue texts to exclude.
36-
#
37-
# But independently of this option we use default exclude patterns,
38-
# it can be disabled by `exclude-use-default: false`.
39-
# To list all excluded by default patterns execute `golangci-lint run --help`
40-
#
41-
exclude-rules:
42-
# Exclude some linters from running on tests files.
43-
- path: _test\.go
44-
linters:
45-
- errcheck
46-
- nolintlint
43+
formatters:
44+
enable:
45+
- gofmt
46+
settings:
47+
gofmt:
48+
simplify: false
49+
exclusions:
50+
generated: lax
51+
paths:
52+
- third_party$
53+
- builtin$
54+
- examples$

cmd/fibratus/app/rules/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ func createRule(name string) error {
8787
return err
8888
}
8989

90-
n := fmt.Sprintf("%s.yml", strings.Replace(strings.ToLower(name), " ", "_", -1))
90+
n := fmt.Sprintf("%s.yml", strings.ReplaceAll(strings.ToLower(name), " ", "_"))
9191
if tacticID != "" {
92-
n = strings.Replace(strings.ToLower(tactics[tacticID]), " ", "_", -1) + "_" + n
92+
n = strings.ReplaceAll(strings.ToLower(tactics[tacticID]), " ", "_") + "_" + n
9393
}
9494
f, err := os.Create(n)
9595
if err != nil {

pkg/alertsender/eventlog/eventlog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (s *eventlog) Send(alert alertsender.Alert) error {
7777
// assume alert ID has the UUID format
7878
// where we build the short version by
7979
// taking the first 12 characters
80-
id := strings.Replace(alert.ID, "-", "", -1)
80+
id := strings.ReplaceAll(alert.ID, "-", "")
8181
h := crc32.ChecksumIEEE([]byte(id[:minIDChars]))
8282
// take the lower 16 bits of the CRC32 hash
8383
code = uint16(h & 0xFFFF)
@@ -86,7 +86,7 @@ func (s *eventlog) Send(alert alertsender.Alert) error {
8686
msg := alert.String(s.config.Verbose)
8787
// trim null characters to avoid
8888
// UTF16PtrFromString complaints
89-
msg = strings.Replace(msg, "\x00", "", -1)
89+
msg = strings.ReplaceAll(msg, "\x00", "")
9090

9191
m, err := windows.UTF16PtrFromString(msg)
9292
if err != nil {

pkg/event/marshaller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (js *jsonStream) writeMore() *jsonStream {
124124
}
125125

126126
func (js *jsonStream) shouldWriteMore(i, l int) bool {
127+
//nolint:staticcheck
127128
return !(i == l-1)
128129
}
129130

@@ -295,9 +296,10 @@ func writeStringSlowPath(stream *jsonStream, i int, s string, valLen int) {
295296

296297
func writeFirstBuf(space []byte, v uint32) []byte {
297298
start := v >> 24
298-
if start == 0 {
299+
switch start {
300+
case 0:
299301
space = append(space, byte(v>>16), byte(v>>8))
300-
} else if start == 1 {
302+
case 1:
301303
space = append(space, byte(v>>8))
302304
}
303305
space = append(space, byte(v))

pkg/event/param.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ func (pars Params) String() string {
706706
case SnakeCase:
707707
sb.WriteString(par.Name + ParamKVDelimiter + par.String())
708708
case DotCase:
709-
sb.WriteString(strings.Replace(par.Name, "_", ".", -1) + ParamKVDelimiter + par.String())
709+
sb.WriteString(strings.ReplaceAll(par.Name, "_", ".") + ParamKVDelimiter + par.String())
710710
case PascalCase:
711-
sb.WriteString(strings.Replace(caser.String(strings.Replace(par.Name, "_", " ", -1)), " ", "", -1) + ParamKVDelimiter + par.String())
711+
sb.WriteString(strings.ReplaceAll(caser.String(strings.ReplaceAll(par.Name, "_", " ")), " ", "") + ParamKVDelimiter + par.String())
712712
case CamelCase:
713713
}
714714
if i != len(pars)-1 {

pkg/filter/ql/functions/replace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (f Replace) Call(args []interface{}) (interface{}, bool) {
3636
if len(args) == 3 {
3737
o := parseString(1, args)
3838
n := parseString(2, args)
39-
return strings.Replace(s, o, n, -1), true
39+
return strings.ReplaceAll(s, o, n), true
4040
}
4141
// apply multiple replacements
4242
repl := s
@@ -49,7 +49,7 @@ func (f Replace) Call(args []interface{}) (interface{}, bool) {
4949
if !ok {
5050
break
5151
}
52-
repl = strings.Replace(repl, o, n, -1)
52+
repl = strings.ReplaceAll(repl, o, n)
5353
}
5454
return repl, true
5555
}

pkg/filter/ql/lexer.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,16 @@ func (s *scanner) scanString() (tok token, pos int, lit string) {
326326
s.r.unread()
327327
_, pos = s.r.curr()
328328

329-
var err error
330-
lit, err = ScanString(s.r)
331-
if err == errBadString {
329+
lit, err := ScanString(s.r)
330+
switch err {
331+
case errBadString:
332332
return Badstr, pos, lit
333-
} else if err == errBadEscape {
333+
case errBadEscape:
334334
_, pos = s.r.curr()
335335
return Badstr, pos, lit
336+
default:
337+
return Str, pos, lit
336338
}
337-
return Str, pos, lit
338339
}
339340

340341
var errBadString = errors.New("bad string")
@@ -358,15 +359,16 @@ func ScanString(r io.RuneScanner) (string, error) {
358359
// If the next character is an escape then write the escaped char.
359360
// If it's not a valid escape then return an error.
360361
ch1, _, _ := r.ReadRune()
361-
if ch1 == 'n' {
362+
switch ch1 {
363+
case 'n':
362364
_, _ = buf.WriteRune('\n')
363-
} else if ch1 == '\\' {
365+
case '\\':
364366
_, _ = buf.WriteRune('\\')
365-
} else if ch1 == '"' {
367+
case '"':
366368
_, _ = buf.WriteRune('"')
367-
} else if ch1 == '\'' {
369+
case '\'':
368370
_, _ = buf.WriteRune('\'')
369-
} else {
371+
default:
370372
return string(ch0) + string(ch1), errBadEscape
371373
}
372374
} else {

pkg/sys/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func EnumDevices() []Driver {
7474
continue
7575
}
7676
dev := syscall.UTF16ToString(filename)
77-
drv.Filename = strings.Replace(dev, "\\SystemRoot", os.Getenv("SYSTEMROOT"), -1)
77+
drv.Filename = strings.Replace(dev, "\\SystemRoot", os.Getenv("SYSTEMROOT"), 1)
7878
drivers[i] = drv
7979
}
8080
return drivers

pkg/util/key/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func Format(key string) (Key, string) {
188188
if strings.HasSuffix(sid, "_Classes") {
189189
return CurrentUser, "Software\\Classes\\" + path[n+1:]
190190
}
191-
return CurrentUser, strings.Replace(path[n+1:], "_Classes", "Software\\Classes", -1)
191+
return CurrentUser, strings.Replace(path[n+1:], "_Classes", "Software\\Classes", 1)
192192
case sid == loggedSID:
193193
if len(path) == len(loggedSID) {
194194
return CurrentUser, ""

0 commit comments

Comments
 (0)