Skip to content

Commit

Permalink
fixup! fix: Remove unrelated flags from config and linters command
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 authored and ldez committed Feb 2, 2024
1 parent 40d374d commit da2bd78
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,7 @@ linters:
- test
- unused

# Run only fast linters from enabled linters set (first run won't be fast)
# Enable only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true

Expand Down
1 change: 1 addition & 0 deletions pkg/commands/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (e *Executor) initLinters() {
fs := e.lintersCmd.Flags()
fs.SortFlags = false // sort them as they are defined here
e.initConfigFileFlagSet(fs, &e.cfg.Run)
e.initLintersFlagSet(fs, &e.cfg.Linters)
e.rootCmd.AddCommand(e.lintersCmd)
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ func (e *Executor) initConfigFileFlagSet(fs *pflag.FlagSet, cfg *config.Run) {
fs.BoolVar(&cfg.NoConfig, "no-config", false, wh("Don't read config file"))
}

func (e *Executor) initLintersFlagSet(fs *pflag.FlagSet, cfg *config.Linters) {
fs.StringSliceVarP(&cfg.Disable, "disable", "D", nil, wh("Disable specific linter"))
fs.BoolVar(&cfg.DisableAll, "disable-all", false, wh("Disable all linters"))
fs.StringSliceVarP(&cfg.Enable, "enable", "E", nil, wh("Enable specific linter"))
fs.BoolVar(&cfg.EnableAll, "enable-all", false, wh("Enable all linters"))
fs.BoolVar(&cfg.Fast, "fast", false, wh("Enable only fast linters from enabled linters set (first run won't be fast)"))
fs.StringSliceVarP(&cfg.Presets, "presets", "p", nil,
wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see "+
"them. This option implies option --disable-all", strings.Join(e.DBManager.AllPresets(), "|"))))
}

//nolint:funlen,gomnd
func (e *Executor) initFlagSet(fs *pflag.FlagSet, cfg *config.Config, isFinalInit bool) {
hideFlag := func(name string) {
Expand Down Expand Up @@ -206,15 +217,7 @@ func (e *Executor) initFlagSet(fs *pflag.FlagSet, cfg *config.Config, isFinalIni

// Linters config
lc := &cfg.Linters
fs.StringSliceVarP(&lc.Enable, "enable", "E", nil, wh("Enable specific linter"))
fs.StringSliceVarP(&lc.Disable, "disable", "D", nil, wh("Disable specific linter"))
fs.BoolVar(&lc.EnableAll, "enable-all", false, wh("Enable all linters"))

fs.BoolVar(&lc.DisableAll, "disable-all", false, wh("Disable all linters"))
fs.StringSliceVarP(&lc.Presets, "presets", "p", nil,
wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see "+
"them. This option implies option --disable-all", strings.Join(e.DBManager.AllPresets(), "|"))))
fs.BoolVar(&lc.Fast, "fast", false, wh("Run only fast linters from enabled linters set (first run won't be fast)"))
e.initLintersFlagSet(fs, lc)

// Issues config
ic := &cfg.Issues
Expand Down
11 changes: 6 additions & 5 deletions test/testshared/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ func (b *RunnerBuilder) Runner() *Runner {
b.tb.Fatal("--no-config and -c cannot be used at the same time")
}

arguments := []string{
"--internal-cmd-test",
}
arguments := []string{}

if b.allowParallelRunners {
arguments = append(arguments, "--allow-parallel-runners")
if b.command == "run" {
arguments = append(arguments, "--internal-cmd-test")
if b.allowParallelRunners {
arguments = append(arguments, "--allow-parallel-runners")
}
}

if b.noConfig {
Expand Down
11 changes: 10 additions & 1 deletion test/testshared/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ func TestRunnerBuilder_Runner(t *testing.T) {
},
},
{
desc: "with command",
desc: "with non run command",
builder: NewRunnerBuilder(t).WithCommand("example"),
expected: &Runner{
env: []string(nil),
command: "example",
args: []string{},
},
},
{
desc: "with run command",
builder: NewRunnerBuilder(t).WithCommand("run"),
expected: &Runner{
env: []string(nil),
command: "run",
args: []string{
"--internal-cmd-test",
"--allow-parallel-runners",
Expand Down

0 comments on commit da2bd78

Please sign in to comment.