Skip to content

Commit

Permalink
fix: yes it's a hack...
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 18, 2024
1 parent 74f0879 commit 9842069
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 12 additions & 1 deletion pkg/commands/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,18 @@ func NewExecutor(buildInfo BuildInfo) *Executor {
e.log.Fatalf("Can't read config: %s", err)
}

if (commandLineCfg == nil || commandLineCfg.Run.Go == "") && e.cfg != nil && e.cfg.Run.Go == "" {
if commandLineCfg != nil && commandLineCfg.Run.Go != "" {
// This hack allow to have the right Run information at least for the Go version (because the default value of the "go" flag is empty).
// If you put a log for `m.cfg.Run.Go` inside `GetAllSupportedLinterConfigs`,
// you will observe that at end (without this hack) the value will have the right value but too late,
// the linters are already running with the previous uncompleted configuration.
// TODO(ldez) there is a major problem with the executor:
// the parsing of the configuration and the timing to load the configuration and linters are creating unmanageable situations.
// There is no simple solution because it's spaghetti code:
// I need to completely rewrite the command line system and the executor because it's extremely time consuming to debug,
// so it's unmaintainable.
e.cfg.Run.Go = commandLineCfg.Run.Go
} else if e.cfg.Run.Go == "" {
e.cfg.Run.Go = config.DetectGoVersion()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/lint/linter/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package linter

import (
"errors"
"fmt"

"golang.org/x/tools/go/packages"

Expand Down Expand Up @@ -151,7 +151,7 @@ func IsGoLowerThanGo122() func(cfg *config.Config) error {
return nil
}

return errors.New("this linter is disabled because the Go version of your project is lower than Go 1.22")
return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is lower than Go 1.22", cfg.Run.Go)
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/linters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st
}

args := []string{
"--allow-parallel-runners",
"--go=1.22", // TODO(ldez) remove this line when we will run go1.23 on the CI. (related to intrange, copyloopvar)
"--disable-all",
"--out-format=json",
"--max-same-issues=100",
Expand All @@ -99,7 +99,6 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st

cmd := testshared.NewRunnerBuilder(t).
WithBinPath(binPath).
WithNoParallelRunners().
WithArgs(caseArgs...).
WithRunContext(rc).
WithTargetPath(sourcePath).
Expand Down

0 comments on commit 9842069

Please sign in to comment.