Skip to content

Commit e23fe50

Browse files
ci: golangci-lint v2 and min go version 1.22 (#38)
* ci: updating golangci-lint and implementing suggestions * go 1.24 is out, change min version to 1.22 * Implement suggestions from golangci-lint * Configuring CI checks to run with go 1.22 and 1.24
1 parent 9bb4df9 commit e23fe50

16 files changed

Lines changed: 70 additions & 47 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
build:
1313
strategy:
1414
matrix:
15-
go: [1.18, 1.19]
15+
go: [1.22, 1.24]
1616
name: build
1717
runs-on: ubuntu-latest
1818
steps:
@@ -27,7 +27,7 @@ jobs:
2727
test:
2828
strategy:
2929
matrix:
30-
go: [1.18, 1.19]
30+
go: [1.22, 1.24]
3131
name: test
3232
runs-on: ubuntu-latest
3333
steps:
@@ -42,8 +42,8 @@ jobs:
4242
golangci:
4343
strategy:
4444
matrix:
45-
go: [1.19]
46-
lint: [v1.50.1]
45+
go: [1.24]
46+
lint: [v2.1.6]
4747
name: lint
4848
runs-on: ubuntu-latest
4949
steps:
@@ -53,6 +53,6 @@ jobs:
5353
go-version: ${{ matrix.go }}
5454
cache: true
5555
- name: golangci-lint
56-
uses: golangci/golangci-lint-action@v6
56+
uses: golangci/golangci-lint-action@v8
5757
with:
5858
version: ${{ matrix.lint }}

.golangci.yml

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
4-
- deadcode
5+
- copyloopvar
56
- errcheck
6-
- exportloopref
7-
- goimports
8-
- revive
9-
- gosimple
7+
- gocyclo
8+
- godox
9+
- goprintffuncname
10+
- govet
1011
- ineffassign
1112
- misspell
13+
- noctx
1214
- prealloc
15+
- revive
1316
- rowserrcheck
1417
- sqlclosecheck
1518
- staticcheck
16-
- structcheck
17-
- typecheck
1819
- unconvert
1920
- unused
20-
- varcheck
21-
- vet
22-
23-
linters-settings:
24-
goimports:
25-
local-prefixes: github.com/simplesurance/proteus
21+
settings:
22+
staticcheck:
23+
checks:
24+
- "all"
25+
gocyclo:
26+
# Minimal code complexity to report.
27+
# Default: 30 (but we recommend 10-20)
28+
min-complexity: 18
29+
godox:
30+
keywords:
31+
- FIXME
32+
exclusions:
33+
generated: lax
34+
presets:
35+
- comments
36+
- common-false-positives
37+
- legacy
38+
- std-error-handling
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- goimports
46+
settings:
47+
goimports:
48+
local-prefixes:
49+
- github.com/simplesurance/proteus
50+
exclusions:
51+
generated: lax
52+
paths:
53+
- third_party$
54+
- builtin$
55+
- examples$

basic_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func configStandardCallbacks(fieldData *paramSetField, val reflect.Value) error
6666
// configuration provider.
6767
switch val.Type().Kind() {
6868
case reflect.String:
69-
fieldData.validFn = func(str string) error {
69+
fieldData.validFn = func(_ string) error {
7070
return nil
7171
}
7272

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/simplesurance/proteus
22

3-
go 1.18
3+
go 1.22
44

55
require golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e

parsed.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,6 @@ func mapKeysSorted[T any](v map[string]T) []string {
449449
return ret
450450
}
451451

452-
func min(a, b int) int {
453-
if a < b {
454-
return a
455-
}
456-
return b
457-
}
458-
459452
func sortedParamNames(set paramSet) []string {
460453
paramNames := make([]string, 0, len(set.fields))
461454
for k := range set.fields {

parser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func MustParse(config any, options ...Option) (*Parsed, error) {
134134
cfgflags.New(),
135135
cfgenv.New("CFG"),
136136
},
137-
loggerFn: func(log plog.Entry) {}, // nop logger
137+
loggerFn: func(_ plog.Entry) {}, // nop logger
138138
autoUsageExitFn: func() { os.Exit(0) },
139139
autoUsageWriter: os.Stdout,
140140
}
@@ -205,7 +205,7 @@ func MustParse(config any, options ...Option) (*Parsed, error) {
205205
return &ret, nil
206206
}
207207

208-
func inferConfigFromValue(value any, opts settings) (config, error) {
208+
func inferConfigFromValue(value any, _ settings) (config, error) {
209209
if reflect.ValueOf(value).Kind() != reflect.Ptr {
210210
return nil, errors.New("configuration struct must be a pointer")
211211
}
@@ -420,10 +420,10 @@ func parseParam(structField reflect.StructField, fieldVal reflect.Value) (
420420
// parameter sets have no value, and the callback functions should
421421
// not be called; install handlers to help debug in case of a mistake.
422422
panicMessage := fmt.Sprintf("%q is a paramset, it have no value", paramName)
423-
ret.validFn = func(v string) error { panic(panicMessage) }
424-
ret.setValueFn = func(v *string) error { panic(panicMessage) }
423+
ret.validFn = func(_ string) error { panic(panicMessage) }
424+
ret.setValueFn = func(_ *string) error { panic(panicMessage) }
425425
ret.getDefaultFn = func() (string, error) { panic(panicMessage) }
426-
ret.redactFn = func(s string) string { panic(panicMessage) }
426+
ret.redactFn = func(_ string) string { panic(panicMessage) }
427427

428428
return paramName, ret, nil
429429
}
@@ -458,7 +458,7 @@ func addSpecialFlags(appConfig config, parsed *Parsed, opts settings) error {
458458
// when the --version flag is provided, the
459459
// parsed object will try to determine if the
460460
// value is valid. Show the version instead.
461-
validFn: func(v string) error {
461+
validFn: func(_ string) error {
462462
fmt.Println(opts.version)
463463
os.Exit(0)
464464
return nil
@@ -492,7 +492,7 @@ func addSpecialFlags(appConfig config, parsed *Parsed, opts settings) error {
492492
// when the --help flag is provided, the parsed object will
493493
// try to determine if the value is valid. Generate the
494494
// help usage instead of terminate the application.
495-
validFn: func(v string) error {
495+
validFn: func(_ string) error {
496496
parsed.Usage(opts.autoUsageWriter)
497497
parsed.help(opts.autoUsageWriter)
498498
parsed.settings.autoUsageExitFn()

plog/plog_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestSkipCaller(t *testing.T) {
5959
loggedEntry = e
6060
}
6161

62-
logf := func(m string) {
62+
logf := func(_ string) {
6363
// The log entry should not register the following file/line number;
6464
// It should register instead its caller.
6565
logger.E("test error", plog.SkipCallers(1))

sources/cfgenv/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (r *envVarProvider) Stop() {
5454

5555
func (r *envVarProvider) Watch(
5656
paramIDs sources.Parameters,
57-
updater sources.Updater,
57+
_ sources.Updater,
5858
) (initial types.ParamValues, _ error) {
5959
return parse(r.prefix+"__", paramIDs)
6060
}

sources/cfgenv/source_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestCfgEnv(t *testing.T) {
5151
"paramset3": map[string]sources.ParameterInfo{"a": {}, "b": {}, "c": {}, "enabled_bool": {IsBool: true}, "other_bool": {IsBool: true}},
5252
}, &testUpdater{
5353
LogFn: plog.TestLogger(t),
54-
IsBooleanFn: func(setName, paramName string) bool {
54+
IsBooleanFn: func(_, paramName string) bool {
5555
return strings.HasSuffix(paramName, "bool")
5656
},
5757
})
@@ -100,7 +100,7 @@ func TestUnexpectedEnvVar(t *testing.T) {
100100
"": map[string]sources.ParameterInfo{"expected": {}},
101101
}, &testUpdater{
102102
LogFn: plog.TestLogger(t),
103-
IsBooleanFn: func(setName, paramName string) bool {
103+
IsBooleanFn: func(_, _ string) bool {
104104
return false
105105
},
106106
})
@@ -123,7 +123,7 @@ func (t *testUpdater) Log(entry plog.Entry) {
123123
t.LogFn(entry)
124124
}
125125

126-
func (t *testUpdater) Peek(setName, paramName string) (*string, error) {
126+
func (*testUpdater) Peek(_, _ string) (*string, error) {
127127
// environment variables do not read values from another providers
128128
return nil, nil
129129
}

sources/cfgflags/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *flagProvider) Stop() {
5858

5959
func (r *flagProvider) Watch(
6060
paramIDs sources.Parameters,
61-
updater sources.Updater,
61+
_ sources.Updater,
6262
) (initial types.ParamValues, err error) {
6363
ret := types.ParamValues{}
6464

0 commit comments

Comments
 (0)