golangci/golangci-lint · error

error in config of rule %q: %w

Error message

error in config of rule %q: %w

What it means

After the revive TOML config is decoded, getConfig iterates every configured rule and calls r.Initialize() to build the rule instance. This error is returned when a specific revive rule fails to initialize, most often because its arguments are invalid (wrong count, wrong type, or unsupported value). The rule name is embedded with %q and the Initialize error is wrapped with %w.

Source

Thrown at pkg/golinters/revive/revive.go:203

		err := toml.NewEncoder(buf).Encode(rawRoot)
		if err != nil {
			return nil, fmt.Errorf("failed to encode configuration: %w", err)
		}

		conf = &lint.Config{}
		_, err = toml.NewDecoder(buf).Decode(conf)
		if err != nil {
			return nil, fmt.Errorf("failed to decode configuration: %w", err)
		}
	}

	normalizeConfig(conf)

	for k, r := range conf.Rules {
		err := r.Initialize()
		if err != nil {
			return nil, fmt.Errorf("error in config of rule %q: %w", k, err)
		}
		conf.Rules[k] = r
	}

	return conf, nil
}

func createConfigMap(cfg *config.ReviveSettings) map[string]any {
	const severity = "severity"

	rawRoot := map[string]any{
		"confidence":         cfg.Confidence,
		severity:             cfg.Severity,
		"errorCode":          cfg.ErrorCode,
		"warningCode":        cfg.WarningCode,
		"enableAllRules":     cfg.EnableAllRules,
		"enableDefaultRules": cfg.EnableDefaultRules,

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Read the wrapped cause: it names the offending rule in quotes; check that rule's expected arguments in the revive documentation.
  2. Fix the arguments list for that rule in .golangci.yml (correct count and types).
  3. Disable (enabled: false) or remove the misconfigured rule to unblock the run, then re-add a corrected config.
  4. Verify the rule name exists in the revive version bundled with your golangci-lint release.
  5. Isolate the failure by enabling one rule at a time with a minimal config.

Example fix

// before (.golangci.yml)
linters-settings:
  revive:
    rules:
      - name: line-length-limit
        arguments: "120"
// after
linters-settings:
  revive:
    rules:
      - name: line-length-limit
        arguments: [120]
Defensive patterns

Strategy: validation

Validate before calling

// Check that each configured revive rule name is known before running
var knownReviveRules = map[string]bool{
	"var-naming": true, "line-length-limit": true, "unexported-return": true,
}

func validateReviveRules(rules []string) error {
	for _, name := range rules {
		if !knownReviveRules[name] {
			return fmt.Errorf("unknown revive rule %q", name)
		}
	}
	return nil
}

Try / catch

if err := run(); err != nil {
	if strings.Contains(err.Error(), "error in config of rule") {
		// extract the quoted rule name and fix its arguments in .golangci.yml
		return fmt.Errorf("fix revive rule config: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Running golangci-lint with revive enabled when conf.Rules contains a rule whose Initialize() returns an error: bad arguments in the revive rules section (e.g. var-naming with non-string parameters), an unknown rule name carrying a config, or a required argument not supplied.

Common situations: Misspelled rule names or wrong-shaped arguments under linters-settings.revive.rules in .golangci.yml; copying rule config from outdated revive docs; enabling a rule with arguments incompatible after a revive upgrade.

Related errors


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