Skip to content

dev: review and clean linter tests #3139

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 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ issues:
- path: pkg/lint/lintersdb/manager.go
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."


run:
timeout: 5m
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.
Expand Down
6 changes: 0 additions & 6 deletions pkg/result/processors/sort_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ var (

type ByName struct{ next comparator }

//nolint:golint
func (cmp ByName) Next() comparator { return cmp.next }

//nolint:golint
func (cmp ByName) Compare(a, b *result.Issue) compareResult {
var res compareResult

Expand All @@ -110,10 +108,8 @@ func (cmp ByName) Compare(a, b *result.Issue) compareResult {

type ByLine struct{ next comparator }

//nolint:golint
func (cmp ByLine) Next() comparator { return cmp.next }

//nolint:golint
func (cmp ByLine) Compare(a, b *result.Issue) compareResult {
var res compareResult

Expand All @@ -130,10 +126,8 @@ func (cmp ByLine) Compare(a, b *result.Issue) compareResult {

type ByColumn struct{ next comparator }

//nolint:golint
func (cmp ByColumn) Next() comparator { return cmp.next }

//nolint:golint
func (cmp ByColumn) Compare(a, b *result.Issue) compareResult {
var res compareResult

Expand Down
143 changes: 73 additions & 70 deletions test/enabled_linters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,11 @@ import (
"github.com/golangci/golangci-lint/test/testshared"
)

func inSlice(s []string, v string) bool {
for _, sv := range s {
if sv == v {
return true
}
}

return false
}

func getEnabledByDefaultFastLintersExcept(except ...string) []string {
m := lintersdb.NewManager(nil, nil)
ebdl := m.GetAllEnabledByDefaultLinters()
var ret []string
for _, lc := range ebdl {
if lc.IsSlowLinter() {
continue
}

if !inSlice(except, lc.Name()) {
ret = append(ret, lc.Name())
}
}

return ret
}

func getAllFastLintersWith(with ...string) []string {
linters := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
ret := append([]string{}, with...)
for _, lc := range linters {
if lc.IsSlowLinter() {
continue
}
ret = append(ret, lc.Name())
}

return ret
}

func getEnabledByDefaultLinters() []string {
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
var ret []string
for _, lc := range ebdl {
ret = append(ret, lc.Name())
}

return ret
}

func getEnabledByDefaultFastLintersWith(with ...string) []string {
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
ret := append([]string{}, with...)
for _, lc := range ebdl {
if lc.IsSlowLinter() {
continue
}

ret = append(ret, lc.Name())
}

return ret
}

//nolint:funlen
func TestEnabledLinters(t *testing.T) {
// require to display the message "Active x linters: [x,y]"
t.Setenv("GL_TEST_RUN", "1")

cases := []struct {
name string
cfg string
Expand All @@ -93,28 +32,28 @@ func TestEnabledLinters(t *testing.T) {
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
},
{
name: "enable golint in config",
name: "enable revive in config",
cfg: `
linters:
enable:
- golint
- revive
`,
enabledLinters: getEnabledByDefaultFastLintersWith("golint"),
enabledLinters: getEnabledByDefaultFastLintersWith("revive"),
},
{
name: "disable govet in cmd",
args: []string{"-Dgovet"},
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
},
{
name: "enable gofmt in cmd and enable golint in config",
name: "enable gofmt in cmd and enable revive in config",
args: []string{"-Egofmt"},
cfg: `
linters:
enable:
- golint
- revive
`,
enabledLinters: getEnabledByDefaultFastLintersWith("golint", "gofmt"),
enabledLinters: getEnabledByDefaultFastLintersWith("revive", "gofmt"),
},
{
name: "fast option in config",
Expand Down Expand Up @@ -195,3 +134,67 @@ func TestEnabledLinters(t *testing.T) {
})
}
}

func inSlice(s []string, v string) bool {
for _, sv := range s {
if sv == v {
return true
}
}

return false
}

func getEnabledByDefaultFastLintersExcept(except ...string) []string {
m := lintersdb.NewManager(nil, nil)
ebdl := m.GetAllEnabledByDefaultLinters()
var ret []string
for _, lc := range ebdl {
if lc.IsSlowLinter() {
continue
}

if !inSlice(except, lc.Name()) {
ret = append(ret, lc.Name())
}
}

return ret
}

func getAllFastLintersWith(with ...string) []string {
linters := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
ret := append([]string{}, with...)
for _, lc := range linters {
if lc.IsSlowLinter() {
continue
}
ret = append(ret, lc.Name())
}

return ret
}

func getEnabledByDefaultLinters() []string {
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
var ret []string
for _, lc := range ebdl {
ret = append(ret, lc.Name())
}

return ret
}

func getEnabledByDefaultFastLintersWith(with ...string) []string {
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
ret := append([]string{}, with...)
for _, lc := range ebdl {
if lc.IsSlowLinter() {
continue
}

ret = append(ret, lc.Name())
}

return ret
}
Loading