golangci-lint/pkg/config/linters_settings_gocritic_test.go
Ludovic Fernandez db80e16aba
dev: cleanup config package (#1929)
* split config section into files.
* extract anonymous types.
* sort linters alphabetically.
2021-04-24 16:29:04 +02:00

55 lines
1.5 KiB
Go

package config
import (
"fmt"
"sort"
"testing"
"github.com/stretchr/testify/assert"
"github.com/golangci/golangci-lint/pkg/logutils"
)
func TestUtils(t *testing.T) {
s1 := []string{"diagnostic", "experimental", "opinionated"}
s2 := []string{"opinionated", "experimental"}
s3 := intersectStringSlice(s1, s2)
sort.Strings(s3)
assert.Equal(t, s3, []string{"experimental", "opinionated"})
}
type tLog struct{}
func (l *tLog) Fatalf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
}
func (l *tLog) Panicf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
}
func (l *tLog) Errorf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
}
func (l *tLog) Warnf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
}
func (l *tLog) Infof(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
}
func (l *tLog) Child(name string) logutils.Log { return nil }
func (l *tLog) SetLevel(level logutils.LogLevel) {}
func TestFilterByDisableTags(t *testing.T) {
testLog := &tLog{}
disabledTags := []string{"experimental", "opinionated"}
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}
filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, testLog)
sort.Strings(filterEnabledChecks)
assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
}