Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
strategy:
matrix:
go: [1.18, 1.19]
go: [1.22, 1.24]
name: build
runs-on: ubuntu-latest
steps:
Expand All @@ -27,7 +27,7 @@ jobs:
test:
strategy:
matrix:
go: [1.18, 1.19]
go: [1.22, 1.24]
name: test
runs-on: ubuntu-latest
steps:
Expand All @@ -42,8 +42,8 @@ jobs:
golangci:
strategy:
matrix:
go: [1.19]
lint: [v1.50.1]
go: [1.24]
lint: [v2.1.6]
name: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -53,6 +53,6 @@ jobs:
go-version: ${{ matrix.go }}
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: ${{ matrix.lint }}
58 changes: 44 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
version: "2"
linters:
disable-all: true
default: none
enable:
- deadcode
- copyloopvar
- errcheck
- exportloopref
- goimports
- revive
- gosimple
- gocyclo
- godox
- goprintffuncname
- govet
- ineffassign
- misspell
- noctx
- prealloc
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck
- vet

linters-settings:
goimports:
local-prefixes: github.com/simplesurance/proteus
settings:
staticcheck:
checks:
- "all"
gocyclo:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
min-complexity: 18
godox:
keywords:
- FIXME
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
settings:
goimports:
local-prefixes:
- github.com/simplesurance/proteus
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion basic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func configStandardCallbacks(fieldData *paramSetField, val reflect.Value) error
// configuration provider.
switch val.Type().Kind() {
case reflect.String:
fieldData.validFn = func(str string) error {
fieldData.validFn = func(_ string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/simplesurance/proteus

go 1.18
go 1.22

require golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
7 changes: 0 additions & 7 deletions parsed.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,6 @@ func mapKeysSorted[T any](v map[string]T) []string {
return ret
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func sortedParamNames(set paramSet) []string {
paramNames := make([]string, 0, len(set.fields))
for k := range set.fields {
Expand Down
14 changes: 7 additions & 7 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func MustParse(config any, options ...Option) (*Parsed, error) {
cfgflags.New(),
cfgenv.New("CFG"),
},
loggerFn: func(log plog.Entry) {}, // nop logger
loggerFn: func(_ plog.Entry) {}, // nop logger
autoUsageExitFn: func() { os.Exit(0) },
autoUsageWriter: os.Stdout,
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func MustParse(config any, options ...Option) (*Parsed, error) {
return &ret, nil
}

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

return paramName, ret, nil
}
Expand Down Expand Up @@ -458,7 +458,7 @@ func addSpecialFlags(appConfig config, parsed *Parsed, opts settings) error {
// when the --version flag is provided, the
// parsed object will try to determine if the
// value is valid. Show the version instead.
validFn: func(v string) error {
validFn: func(_ string) error {
fmt.Println(opts.version)
os.Exit(0)
return nil
Expand Down Expand Up @@ -492,7 +492,7 @@ func addSpecialFlags(appConfig config, parsed *Parsed, opts settings) error {
// when the --help flag is provided, the parsed object will
// try to determine if the value is valid. Generate the
// help usage instead of terminate the application.
validFn: func(v string) error {
validFn: func(_ string) error {
parsed.Usage(opts.autoUsageWriter)
parsed.help(opts.autoUsageWriter)
parsed.settings.autoUsageExitFn()
Expand Down
2 changes: 1 addition & 1 deletion plog/plog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestSkipCaller(t *testing.T) {
loggedEntry = e
}

logf := func(m string) {
logf := func(_ string) {
// The log entry should not register the following file/line number;
// It should register instead its caller.
logger.E("test error", plog.SkipCallers(1))
Expand Down
2 changes: 1 addition & 1 deletion sources/cfgenv/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *envVarProvider) Stop() {

func (r *envVarProvider) Watch(
paramIDs sources.Parameters,
updater sources.Updater,
_ sources.Updater,
) (initial types.ParamValues, _ error) {
return parse(r.prefix+"__", paramIDs)
}
Expand Down
6 changes: 3 additions & 3 deletions sources/cfgenv/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestCfgEnv(t *testing.T) {
"paramset3": map[string]sources.ParameterInfo{"a": {}, "b": {}, "c": {}, "enabled_bool": {IsBool: true}, "other_bool": {IsBool: true}},
}, &testUpdater{
LogFn: plog.TestLogger(t),
IsBooleanFn: func(setName, paramName string) bool {
IsBooleanFn: func(_, paramName string) bool {
return strings.HasSuffix(paramName, "bool")
},
})
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestUnexpectedEnvVar(t *testing.T) {
"": map[string]sources.ParameterInfo{"expected": {}},
}, &testUpdater{
LogFn: plog.TestLogger(t),
IsBooleanFn: func(setName, paramName string) bool {
IsBooleanFn: func(_, _ string) bool {
return false
},
})
Expand All @@ -123,7 +123,7 @@ func (t *testUpdater) Log(entry plog.Entry) {
t.LogFn(entry)
}

func (t *testUpdater) Peek(setName, paramName string) (*string, error) {
func (*testUpdater) Peek(_, _ string) (*string, error) {
// environment variables do not read values from another providers
return nil, nil
}
2 changes: 1 addition & 1 deletion sources/cfgflags/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *flagProvider) Stop() {

func (r *flagProvider) Watch(
paramIDs sources.Parameters,
updater sources.Updater,
_ sources.Updater,
) (initial types.ParamValues, err error) {
ret := types.ParamValues{}

Expand Down
2 changes: 1 addition & 1 deletion sources/cfgflags/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ func (t *testUpdater) Log(entry plog.Entry) {
t.LogFn(entry)
}

func (t *testUpdater) Peek(setName, paramName string) (*string, error) {
func (t *testUpdater) Peek(_, _ string) (*string, error) {
return nil, nil // flags do not peek values from other provider
}
2 changes: 1 addition & 1 deletion sources/cfgtest/cfgtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *TestProvider) Stop() {
// variables never change, we only read once, and we don't have to watch
// for changes.
func (r *TestProvider) Watch(
paramIDs sources.Parameters,
_ sources.Parameters,
updater sources.Updater,
) (initial types.ParamValues, err error) {
r.updater = updater
Expand Down
2 changes: 1 addition & 1 deletion xtypes/ecdsa_pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (d *ECDSAPubKey) ValueValid(s string) error {
// GetDefaultValue will be used to read the default value when showing usage
// information.
func (d *ECDSAPubKey) GetDefaultValue() (string, error) {
// FIXME show the public key
// TODO show the public key
return "<secret>", nil
}

Expand Down
2 changes: 1 addition & 1 deletion xtypes/oneof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestOneOfCallbackProvidedParameter(t *testing.T) {
}{
P: &xtypes.OneOf{
Choices: []string{"do", "re", "mi"},
UpdateFn: func(s string) { invoked = true },
UpdateFn: func(_ string) { invoked = true },
},
}

Expand Down
2 changes: 1 addition & 1 deletion xtypes/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *String) Value() string {

// ValueValid test if the provided parameter value is valid. Has no side
// effects.
func (d *String) ValueValid(s string) error {
func (d *String) ValueValid(_ string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion xtypes/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestEmptyURL(t *testing.T) {
params := struct {
URL *xtypes.URL
}{
URL: &xtypes.URL{ValidateFn: func(u *url.URL) error { return nil }},
URL: &xtypes.URL{ValidateFn: func(_ *url.URL) error { return nil }},
}

provider := cfgtest.New(types.ParamValues{
Expand Down