mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-07-28 06:59:10 -04:00
dev: rewrite linters Manager (#4419)
This commit is contained in:
parent
26f8088b38
commit
b14d05cdb4
27 changed files with 1749 additions and 1825 deletions
|
@ -7,6 +7,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
|
||||
"github.com/golangci/golangci-lint/test/testshared"
|
||||
)
|
||||
|
@ -29,7 +31,7 @@ func TestEnabledLinters(t *testing.T) {
|
|||
disable:
|
||||
- govet
|
||||
`,
|
||||
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
|
||||
enabledLinters: getEnabledByDefaultFastLintersExcept(t, "govet"),
|
||||
},
|
||||
{
|
||||
name: "enable revive in config",
|
||||
|
@ -38,12 +40,12 @@ func TestEnabledLinters(t *testing.T) {
|
|||
enable:
|
||||
- revive
|
||||
`,
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith("revive"),
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(t, "revive"),
|
||||
},
|
||||
{
|
||||
name: "disable govet in cmd",
|
||||
args: []string{"-Dgovet"},
|
||||
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
|
||||
enabledLinters: getEnabledByDefaultFastLintersExcept(t, "govet"),
|
||||
},
|
||||
{
|
||||
name: "enable gofmt in cmd and enable revive in config",
|
||||
|
@ -53,7 +55,7 @@ func TestEnabledLinters(t *testing.T) {
|
|||
enable:
|
||||
- revive
|
||||
`,
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith("revive", "gofmt"),
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(t, "revive", "gofmt"),
|
||||
},
|
||||
{
|
||||
name: "fast option in config",
|
||||
|
@ -61,7 +63,7 @@ func TestEnabledLinters(t *testing.T) {
|
|||
linters:
|
||||
fast: true
|
||||
`,
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(),
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(t),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
{
|
||||
|
@ -70,13 +72,13 @@ func TestEnabledLinters(t *testing.T) {
|
|||
linters:
|
||||
fast: false
|
||||
`,
|
||||
enabledLinters: getEnabledByDefaultLinters(),
|
||||
enabledLinters: getEnabledByDefaultLinters(t),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
{
|
||||
name: "set fast option in command-line",
|
||||
args: []string{"--fast"},
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(),
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(t),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
{
|
||||
|
@ -86,7 +88,7 @@ func TestEnabledLinters(t *testing.T) {
|
|||
fast: false
|
||||
`,
|
||||
args: []string{"--fast"},
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(),
|
||||
enabledLinters: getEnabledByDefaultFastLintersWith(t),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
{
|
||||
|
@ -96,13 +98,13 @@ func TestEnabledLinters(t *testing.T) {
|
|||
fast: true
|
||||
`,
|
||||
args: []string{"--fast=false"},
|
||||
enabledLinters: getEnabledByDefaultLinters(),
|
||||
enabledLinters: getEnabledByDefaultLinters(t),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
{
|
||||
name: "fast option combined with enable and enable-all",
|
||||
args: []string{"--enable-all", "--fast", "--enable=unused"},
|
||||
enabledLinters: getAllFastLintersWith("unused"),
|
||||
enabledLinters: getAllFastLintersWith(t, "unused"),
|
||||
noImplicitFast: true,
|
||||
},
|
||||
}
|
||||
|
@ -127,7 +129,7 @@ func TestEnabledLinters(t *testing.T) {
|
|||
Runner().
|
||||
Run()
|
||||
|
||||
sort.StringSlice(c.enabledLinters).Sort()
|
||||
sort.Strings(c.enabledLinters)
|
||||
|
||||
r.ExpectOutputContains(fmt.Sprintf("Active %d linters: [%s]",
|
||||
len(c.enabledLinters), strings.Join(c.enabledLinters, " ")))
|
||||
|
@ -135,8 +137,12 @@ func TestEnabledLinters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getEnabledByDefaultFastLintersExcept(except ...string) []string {
|
||||
m := lintersdb.NewManager(nil, nil)
|
||||
func getEnabledByDefaultFastLintersExcept(t *testing.T, except ...string) []string {
|
||||
t.Helper()
|
||||
|
||||
m, err := lintersdb.NewManager(nil, nil, lintersdb.NewLinterBuilder())
|
||||
require.NoError(t, err)
|
||||
|
||||
ebdl := m.GetAllEnabledByDefaultLinters()
|
||||
var ret []string
|
||||
for _, lc := range ebdl {
|
||||
|
@ -152,8 +158,13 @@ func getEnabledByDefaultFastLintersExcept(except ...string) []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
func getAllFastLintersWith(with ...string) []string {
|
||||
linters := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
|
||||
func getAllFastLintersWith(t *testing.T, with ...string) []string {
|
||||
t.Helper()
|
||||
|
||||
dbManager, err := lintersdb.NewManager(nil, nil, lintersdb.NewLinterBuilder())
|
||||
require.NoError(t, err)
|
||||
|
||||
linters := dbManager.GetAllSupportedLinterConfigs()
|
||||
ret := append([]string{}, with...)
|
||||
for _, lc := range linters {
|
||||
if lc.IsSlowLinter() {
|
||||
|
@ -165,8 +176,13 @@ func getAllFastLintersWith(with ...string) []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
func getEnabledByDefaultLinters() []string {
|
||||
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
|
||||
func getEnabledByDefaultLinters(t *testing.T) []string {
|
||||
t.Helper()
|
||||
|
||||
dbManager, err := lintersdb.NewManager(nil, nil, lintersdb.NewLinterBuilder())
|
||||
require.NoError(t, err)
|
||||
|
||||
ebdl := dbManager.GetAllEnabledByDefaultLinters()
|
||||
var ret []string
|
||||
for _, lc := range ebdl {
|
||||
if lc.Internal {
|
||||
|
@ -179,8 +195,13 @@ func getEnabledByDefaultLinters() []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
func getEnabledByDefaultFastLintersWith(with ...string) []string {
|
||||
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
|
||||
func getEnabledByDefaultFastLintersWith(t *testing.T, with ...string) []string {
|
||||
t.Helper()
|
||||
|
||||
dbManager, err := lintersdb.NewManager(nil, nil, lintersdb.NewLinterBuilder())
|
||||
require.NoError(t, err)
|
||||
|
||||
ebdl := dbManager.GetAllEnabledByDefaultLinters()
|
||||
ret := append([]string{}, with...)
|
||||
for _, lc := range ebdl {
|
||||
if lc.IsSlowLinter() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue