diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 081422c..bae624d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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: @@ -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 }} diff --git a/.golangci.yml b/.golangci.yml index d04f924..36afacd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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$ diff --git a/basic_types.go b/basic_types.go index bd7bed2..451e802 100644 --- a/basic_types.go +++ b/basic_types.go @@ -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 } diff --git a/go.mod b/go.mod index 752273d..d3a1cdd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/parsed.go b/parsed.go index 4185996..699a895 100644 --- a/parsed.go +++ b/parsed.go @@ -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 { diff --git a/parser.go b/parser.go index e299c30..6a48c53 100644 --- a/parser.go +++ b/parser.go @@ -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, } @@ -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") } @@ -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 } @@ -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 @@ -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() diff --git a/plog/plog_test.go b/plog/plog_test.go index 7e8c51f..70f3a70 100644 --- a/plog/plog_test.go +++ b/plog/plog_test.go @@ -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)) diff --git a/sources/cfgenv/source.go b/sources/cfgenv/source.go index 67f700d..2f68474 100644 --- a/sources/cfgenv/source.go +++ b/sources/cfgenv/source.go @@ -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) } diff --git a/sources/cfgenv/source_test.go b/sources/cfgenv/source_test.go index 2d50a5c..e847599 100644 --- a/sources/cfgenv/source_test.go +++ b/sources/cfgenv/source_test.go @@ -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") }, }) @@ -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 }, }) @@ -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 } diff --git a/sources/cfgflags/source.go b/sources/cfgflags/source.go index 70f47bf..fe655f6 100644 --- a/sources/cfgflags/source.go +++ b/sources/cfgflags/source.go @@ -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{} diff --git a/sources/cfgflags/source_test.go b/sources/cfgflags/source_test.go index 028149d..7b363b1 100644 --- a/sources/cfgflags/source_test.go +++ b/sources/cfgflags/source_test.go @@ -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 } diff --git a/sources/cfgtest/cfgtest.go b/sources/cfgtest/cfgtest.go index 35cb807..ddd87dd 100644 --- a/sources/cfgtest/cfgtest.go +++ b/sources/cfgtest/cfgtest.go @@ -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 diff --git a/xtypes/ecdsa_pub.go b/xtypes/ecdsa_pub.go index 09b3974..93e34c6 100644 --- a/xtypes/ecdsa_pub.go +++ b/xtypes/ecdsa_pub.go @@ -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 "", nil } diff --git a/xtypes/oneof_test.go b/xtypes/oneof_test.go index 236148c..5d8f727 100644 --- a/xtypes/oneof_test.go +++ b/xtypes/oneof_test.go @@ -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 }, }, } diff --git a/xtypes/string.go b/xtypes/string.go index 56d8c59..4c449f4 100644 --- a/xtypes/string.go +++ b/xtypes/string.go @@ -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 } diff --git a/xtypes/url_test.go b/xtypes/url_test.go index 3b08c54..8dd6ead 100644 --- a/xtypes/url_test.go +++ b/xtypes/url_test.go @@ -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{