Skip to content

feat: new linters configuration #5475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add Groups field
  • Loading branch information
ldez committed Feb 25, 2025
commit 937e5c92f4408894f5e9114af13289cd1b9c0d5b
36 changes: 29 additions & 7 deletions pkg/lint/linter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Deprecation struct {
type Config struct {
Linter Linter
EnabledByDefault bool
Groups map[string]struct{}

LoadMode packages.LoadMode

Expand All @@ -44,6 +45,13 @@ type Config struct {
Deprecation *Deprecation
}

func NewConfig(linter Linter) *Config {
lc := &Config{
Linter: linter,
}
return lc.WithLoadFiles()
}

func (lc *Config) WithEnabledByDefault() *Config {
lc.EnabledByDefault = true
return lc
Expand Down Expand Up @@ -75,6 +83,27 @@ func (lc *Config) WithLoadForGoAnalysis() *Config {
return lc
}

func (lc *Config) WithGroups(names ...string) *Config {
if lc.Groups == nil {
lc.Groups = make(map[string]struct{})
}

for _, name := range names {
lc.Groups[name] = struct{}{}
}

return lc
}

func (lc *Config) FromGroup(name string) bool {
if lc.Groups == nil {
return false
}

_, ok := lc.Groups[name]
return ok
}

func (lc *Config) WithURL(url string) *Config {
lc.OriginalURL = url
return lc
Expand Down Expand Up @@ -154,10 +183,3 @@ func isGoLowerThanGo(v string) func(cfg *config.Config) error {
return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is lower than Go %s", cfg.Run.Go, v)
}
}

func NewConfig(linter Linter) *Config {
lc := &Config{
Linter: linter,
}
return lc.WithLoadFiles()
}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/charithe/durationcheck"),

linter.NewConfig(errcheck.New(&cfg.LintersSettings.Errcheck)).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.0.0").
WithLoadForGoAnalysis().
Expand Down Expand Up @@ -374,6 +375,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/securego/gosec"),

linter.NewConfig(gosimple.New(&cfg.LintersSettings.Gosimple)).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.20.0").
WithLoadForGoAnalysis().
Expand All @@ -386,6 +388,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/xen0n/gosmopolitan"),

linter.NewConfig(govet.New(&cfg.LintersSettings.Govet)).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.0.0").
WithLoadForGoAnalysis().
Expand Down Expand Up @@ -413,6 +416,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/macabu/inamedparam"),

linter.NewConfig(ineffassign.New()).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.0.0").
WithURL("https://github.com/gordonklaus/ineffassign"),
Expand Down Expand Up @@ -575,6 +579,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/jjti/go-spancheck"),

linter.NewConfig(staticcheck.New(&cfg.LintersSettings.Staticcheck)).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.0.0").
WithLoadForGoAnalysis().
Expand Down Expand Up @@ -637,6 +642,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithURL("https://github.com/mvdan/unparam"),

linter.NewConfig(unused.New(&cfg.LintersSettings.Unused)).
WithGroups(config.DefaultSetNameStandard).
WithEnabledByDefault().
WithSince("v1.20.0").
WithLoadForGoAnalysis().
Expand Down