golangci/golangci-lint · error
can't combine option --config and --no-config
Error message
can't combine option --config and --no-config
What it means
The golangci-lint configuration loader (BaseLoader.evaluateOptions) refuses to run when both --config (or opts.Config) and --no-config (opts.NoConfig) are supplied, since they are mutually exclusive ways to control config discovery. It is a CLI/config contradiction detected before any file is read.
Source
Thrown at pkg/config/base_loader.go:85
}
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 != "" {
return "", errors.New("can't combine option --config and --no-config")
}
if l.opts.NoConfig {
return "", errConfigDisabled
}
configFile, err := homedir.Expand(l.opts.Config)
if err != nil {
return "", errors.New("failed to expand configuration path")
}
return configFile, nil
}
func (l *BaseLoader) setupConfigFileSearch() {
l.viper.SetConfigName(".golangci")
configSearchPaths := l.getConfigSearchPaths()View on GitHub (pinned to ed7a235d2d)
Solutions
- Remove the --no-config flag if you want a specific config file.
- Remove --config and keep --no-config if you want defaults only.
- In code, ensure only one of l.opts.Config / l.opts.NoConfig is set before calling Load/setConfigFile.
Example fix
// before golangci-lint run --no-config --config .golangci.yml // after golangci-lint run --config .golangci.yml
Defensive patterns
Strategy: validation
Validate before calling
const flags = process.argv.slice(2);
if (flags.includes('--no-config') && flags.some(f => f.startsWith('--config'))) {
throw new Error('Remove either --no-config or --config before running golangci-lint');
} Prevention
- Keep --no-config out of shared scripts/aliases; scope it to specific invocations.
- Build CLI args from a single source of truth (CI config) so flags can't duplicate.
- Run `golangci-lint config verify` in CI to catch config/flag conflicts early.
When it happens
Trigger: Running golangci-lint with both `--config <file>` and `--no-config` flags, or programmatically calling setConfigFile after setting opts.NoConfig = true (or vice versa) before Load.
Common situations: Shell scripts/aliases where --no-config is baked in and a CI job appends --config; users overriding a default flag; passing both flags to `golangci-lint config` or `run` subcommands.
Related errors
- config is disabled by --no-config
- can't get enabled formatters: %w
- can't load config: %w
- can't get enabled linters: %w
- can't start CPU profiling: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/f09b21da0c06a8c7.
Report an issue: GitHub.