Skip to content

Commit 937e5c9

Browse files
committed
feat: add Groups field
1 parent 7360aed commit 937e5c9

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

pkg/lint/linter/config.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Deprecation struct {
2929
type Config struct {
3030
Linter Linter
3131
EnabledByDefault bool
32+
Groups map[string]struct{}
3233

3334
LoadMode packages.LoadMode
3435

@@ -44,6 +45,13 @@ type Config struct {
4445
Deprecation *Deprecation
4546
}
4647

48+
func NewConfig(linter Linter) *Config {
49+
lc := &Config{
50+
Linter: linter,
51+
}
52+
return lc.WithLoadFiles()
53+
}
54+
4755
func (lc *Config) WithEnabledByDefault() *Config {
4856
lc.EnabledByDefault = true
4957
return lc
@@ -75,6 +83,27 @@ func (lc *Config) WithLoadForGoAnalysis() *Config {
7583
return lc
7684
}
7785

86+
func (lc *Config) WithGroups(names ...string) *Config {
87+
if lc.Groups == nil {
88+
lc.Groups = make(map[string]struct{})
89+
}
90+
91+
for _, name := range names {
92+
lc.Groups[name] = struct{}{}
93+
}
94+
95+
return lc
96+
}
97+
98+
func (lc *Config) FromGroup(name string) bool {
99+
if lc.Groups == nil {
100+
return false
101+
}
102+
103+
_, ok := lc.Groups[name]
104+
return ok
105+
}
106+
78107
func (lc *Config) WithURL(url string) *Config {
79108
lc.OriginalURL = url
80109
return lc
@@ -154,10 +183,3 @@ func isGoLowerThanGo(v string) func(cfg *config.Config) error {
154183
return fmt.Errorf("this linter is disabled because the Go version (%s) of your project is lower than Go %s", cfg.Run.Go, v)
155184
}
156185
}
157-
158-
func NewConfig(linter Linter) *Config {
159-
lc := &Config{
160-
Linter: linter,
161-
}
162-
return lc.WithLoadFiles()
163-
}

pkg/lint/lintersdb/builder_linter.go

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
205205
WithURL("https://github.com/charithe/durationcheck"),
206206

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

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

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

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

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

639644
linter.NewConfig(unused.New(&cfg.LintersSettings.Unused)).
645+
WithGroups(config.DefaultSetNameStandard).
640646
WithEnabledByDefault().
641647
WithSince("v1.20.0").
642648
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)