golangci/golangci-lint · error

can't parse --config option: %w

Error message

can't parse --config option: %w

What it means

The config loader's evaluateOptions parses the --config flag (and related options) before loading YAML/etc. Any failure other than the sentinel errConfigDisabled (config explicitly disabled) is wrapped as "can't parse --config option", so an invalid --config value stops loading entirely.

Source

Thrown at pkg/config/base_loader.go:66

		return err
	}

	err = l.parseConfig()
	if err != nil {
		return err
	}

	return nil
}

func (l *BaseLoader) setConfigFile() error {
	configFile, err := l.evaluateOptions()
	if err != nil {
		if errors.Is(err, errConfigDisabled) {
			return nil
		}

		return fmt.Errorf("can't parse --config option: %w", err)
	}

	if configFile != "" {
		l.viper.SetConfigFile(configFile)

		// Assume YAML if the file has no extension.
		if filepath.Ext(configFile) == "" {
			l.viper.SetConfigType("yaml")
		}
	} else {
		l.setupConfigFileSearch()
	}

	return nil
}

func (l *BaseLoader) evaluateOptions() (string, error) {
	if l.opts.NoConfig && l.opts.Config != "" {

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Check the --config flag value for typos and that it points to an existing file, not a directory
  2. Run `golangci-lint config path` / `--config` with an absolute path to rule out CWD issues
  3. If you intended to skip config, use the dedicated option to disable config rather than a malformed --config
  4. Inspect the wrapped %w error for the precise parse failure

Example fix

// before
golangci-lint run --config .golangci.yml.bak
// after
golangci-lint run --config .golangci.yml
Defensive patterns

Strategy: validation

Validate before calling

cfg := flag.String("config", "", "path")
if *cfg != "" {
	info, err := os.Stat(*cfg)
	if err != nil {
		return fmt.Errorf("--config %s: %w", *cfg, err)
	}
	if info.IsDir() {
		return fmt.Errorf("--config %s is a directory", *cfg)
	}
}

Prevention

When it happens

Trigger: Invoking `golangci-lint run --config <path>` where path resolution/evaluation fails — e.g. empty/invalid flag value, unsupported expansion, or an error surfaced by the option evaluator.

Common situations: Typo'd --config path or flag value; passing a directory instead of a file; shell quoting dropping the value; combining --config with config-disabling flags incorrectly.

Related errors


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