github.com/outer199/golangci-lint@v1.10.1/pkg/lint/lintersdb/lintersdb_test.go (about) 1 package lintersdb 2 3 import ( 4 "sort" 5 "testing" 6 7 "github.com/golangci/golangci-lint/pkg/config" 8 "github.com/golangci/golangci-lint/pkg/lint/linter" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestGetEnabledLintersSet(t *testing.T) { 13 type cs struct { 14 cfg config.Linters 15 name string // test case name 16 def []string // enabled by default linters 17 exp []string // alphabetically ordered enabled linter names 18 } 19 cases := []cs{ 20 { 21 cfg: config.Linters{ 22 Disable: []string{"megacheck"}, 23 }, 24 name: "disable all linters from megacheck", 25 def: getAllMegacheckSubLinterNames(), 26 }, 27 { 28 cfg: config.Linters{ 29 Disable: []string{"staticcheck"}, 30 }, 31 name: "disable only staticcheck", 32 def: getAllMegacheckSubLinterNames(), 33 exp: []string{"megacheck.{unused,gosimple}"}, 34 }, 35 { 36 name: "merge into megacheck", 37 def: getAllMegacheckSubLinterNames(), 38 exp: []string{"megacheck"}, 39 }, 40 { 41 name: "don't disable anything", 42 def: []string{"gofmt", "govet"}, 43 exp: []string{"gofmt", "govet"}, 44 }, 45 } 46 47 for _, c := range cases { 48 t.Run(c.name, func(t *testing.T) { 49 defaultLinters := []linter.Config{} 50 for _, ln := range c.def { 51 defaultLinters = append(defaultLinters, *getLinterConfig(ln)) 52 } 53 els := getEnabledLintersSet(&c.cfg, defaultLinters) 54 var enabledLinters []string 55 for ln, lc := range els { 56 assert.Equal(t, ln, lc.Linter.Name()) 57 enabledLinters = append(enabledLinters, ln) 58 } 59 60 sort.Strings(enabledLinters) 61 sort.Strings(c.exp) 62 63 assert.Equal(t, c.exp, enabledLinters) 64 }) 65 } 66 }