golangci/golangci-lint · error

invalid preset: %s

Error message

invalid preset: %s

What it means

LinterExclusions.Validate checks every entry in linters.exclusions.presets against the known set: comments, std-error-handling, common-false-positives, legacy. An unknown preset name fails with 'invalid preset'.

Source

Thrown at pkg/config/linters_exclusions.go:48

}

func (e *LinterExclusions) Validate() error {
	for i, rule := range e.Rules {
		if err := rule.Validate(); err != nil {
			return fmt.Errorf("error in exclude rule #%d: %w", i, err)
		}
	}

	allPresets := []string{
		ExclusionPresetComments,
		ExclusionPresetStdErrorHandling,
		ExclusionPresetCommonFalsePositives,
		ExclusionPresetLegacy,
	}

	for _, preset := range e.Presets {
		if !slices.Contains(allPresets, preset) {
			return fmt.Errorf("invalid preset: %s", preset)
		}
	}

	return nil
}

type ExcludeRule struct {
	BaseRule `mapstructure:",squash"`
}

func (e *ExcludeRule) Validate() error {
	return e.BaseRule.Validate(excludeRuleMinConditionsCount)
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Replace the preset name with one of: comments, std-error-handling, common-false-positives, legacy
  2. Remove the invalid preset and express the exclusions as explicit rules instead
  3. Check docs at golangci-lint.run for the current preset list

Example fix

# before
linters:
  exclusions:
    presets:
      - false-positives
# after
linters:
  exclusions:
    presets:
      - common-false-positives
Defensive patterns

Strategy: validation

Validate before calling

var validPresets = []string{"comments","std-error-handling","common-false-positives","legacy"}
for _, p := range cfg.Linters.Exclusions.Presets {
	if !slices.Contains(validPresets, p) {
		return fmt.Errorf("invalid preset: %s", p)
	}
}

Try / catch

if err := exclusions.Validate(); err != nil { log.Fatalf("preset error: %v", err) }

Prevention

When it happens

Trigger: Config with linters.exclusions.presets: [my-preset] or a misspelled preset name; v1 preset names that no longer exist in v2.

Common situations: Copying old v1 configs where preset sets differed; typos like 'false-positives' instead of 'common-false-positives'; inventing custom preset names (not supported).

Related errors


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