1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-03 13:11:25 +02:00
revive/test/golint_test.go

73 lines
1.6 KiB
Go
Raw Normal View History

2018-02-04 15:02:45 -08:00
package test
import (
"flag"
"os"
2018-02-04 15:02:45 -08:00
"path"
"regexp"
"testing"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
2018-02-04 15:02:45 -08:00
)
var lintMatch = flag.String("lint.match", "", "restrict fixtures matches to this pattern")
var rules = []lint.Rule{
&rule.VarDeclarationsRule{},
&rule.PackageCommentsRule{},
&rule.DotImportsRule{},
&rule.BlankImportsRule{},
&rule.ExportedRule{},
2018-05-26 21:28:31 -07:00
&rule.VarNamingRule{},
2018-05-26 16:14:36 -07:00
&rule.IndentErrorFlowRule{},
2018-02-04 15:02:45 -08:00
&rule.RangeRule{},
&rule.ErrorfRule{},
2018-05-26 21:28:31 -07:00
&rule.ErrorNamingRule{},
2018-02-04 15:02:45 -08:00
&rule.ErrorStringsRule{},
2018-05-26 21:28:31 -07:00
&rule.ReceiverNamingRule{},
2018-02-04 15:02:45 -08:00
&rule.IncrementDecrementRule{},
&rule.ErrorReturnRule{},
&rule.UnexportedReturnRule{},
2018-05-26 21:28:31 -07:00
&rule.TimeNamingRule{},
&rule.ContextKeysType{},
2018-02-04 15:02:45 -08:00
}
func TestAll(t *testing.T) {
baseDir := "../testdata/golint/"
2018-02-04 15:02:45 -08:00
rx, err := regexp.Compile(*lintMatch)
if err != nil {
t.Fatalf("Bad -lint.match value %q: %v", *lintMatch, err)
}
fis, err := os.ReadDir(baseDir)
2018-02-04 15:02:45 -08:00
if err != nil {
t.Fatalf("os.ReadDir: %v", err)
2018-02-04 15:02:45 -08:00
}
if len(fis) == 0 {
t.Fatalf("no files in %v", baseDir)
}
for _, fi := range fis {
if !rx.MatchString(fi.Name()) {
continue
}
t.Run(fi.Name(), func(t *testing.T) {
filePath := path.Join(baseDir, fi.Name())
src, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
}
2018-02-04 15:02:45 -08:00
fileInfo, err := os.Stat(filePath)
if err != nil {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
}
if err := assertFailures(t, baseDir, fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
t.Errorf("Linting %s: %v", fi.Name(), err)
}
})
2018-02-04 15:02:45 -08:00
}
}