golangci/golangci-lint · error

%s: invalid configuration: %w

Error message

%s: invalid configuration: %w

What it means

In the linter config builder, when a deprecated linter has a Replacement, the tool generates a suggested configuration for the replacement and encodes it. If encoding that suggestion fails, the error is wrapped as "<replacement>: invalid configuration". It indicates the generated suggestion for the replacement linter could not be produced.

Source

Thrown at pkg/lint/linter/config.go:204

			encoder.SetIndent(2)

			linters := map[string]any{
				"enable": []string{d.Replacement},
			}

			replacementSettings := mgr(data)

			if replacementSettings != nil {
				linters["settings"] = map[string]any{d.Replacement: replacementSettings}
			}

			suggestion := map[string]any{
				"linters": linters,
			}

			err := encoder.Encode(suggestion)
			if err != nil {
				return "", fmt.Errorf("%s: invalid configuration: %w", d.Replacement, err)
			}

			return buf.String(), nil
		}
	}
}

func IsGoLowerThanGo122() func(cfg *config.Config) error {
	return isGoLowerThanGo("1.22")
}

func isGoLowerThanGo(v string) func(cfg *config.Config) error {
	return func(cfg *config.Config) error {
		if cfg == nil || config.IsGoGreaterThanOrEqual(cfg.Run.Go, v) {
			return nil
		}

		return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is lower than Go %s", cfg.Run.Go, v)

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Read the wrapped cause after "invalid configuration" for the encode failure detail.
  2. Manually replace the deprecated linter with its replacement in .golangci.yml instead of relying on the generated suggestion.
  3. Update golangci-lint to the latest version so replacement suggestion generation matches your config schema.
  4. Validate your config with `golangci-lint config verify` to catch schema problems.

Example fix

// before: relying on deprecated linter with auto-suggestion
linters:
  enable: [interfacer]

// after: migrate manually to the replacement
linters:
  enable: [staticcheck]
Defensive patterns

Strategy: validation

Validate before calling

// before running
cmd := exec.Command("golangci-lint", "config", "verify")
if out, err := cmd.CombinedOutput(); err != nil {
    return fmt.Errorf("invalid config: %s", out)
}

Try / catch

cfg, err := buildLintersConfig(raw)
if err != nil {
    if strings.Contains(err.Error(), "invalid configuration") {
        // fall back to manually migrating deprecated linters
        log.Warnf("auto-suggestion failed (%v); migrate manually", err)
        return manualMigration(raw)
    }
    return err
}

Prevention

When it happens

Trigger: Using a deprecated linter that declares a Replacement, where building/encoding the replacement's suggested settings via encoder.Encode returns an error (e.g. an unsupported setting value in the suggestion map).

Common situations: Migrating off a deprecated linter whose replacement requires settings the current config version cannot represent; corrupted or hand-edited config that the suggestion generator chokes on.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/925295068de8f251. Report an issue: GitHub.