This repository has been archived by the owner on Dec 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkers_test.go
108 lines (96 loc) · 2.22 KB
/
checkers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package checkers
import (
"testing"
"github.com/go-lintpack/lintpack"
"github.com/go-lintpack/lintpack/linttest"
)
func TestCheckers(t *testing.T) {
allParams := map[string]map[string]interface{}{
"captLocal": {"paramsOnly": false},
}
for _, info := range lintpack.GetCheckersInfo() {
params := allParams[info.Name]
for key, p := range info.Params {
v, ok := params[key]
if ok {
p.Value = v
}
}
}
linttest.TestCheckers(t)
}
func TestIntegration(t *testing.T) { linttest.TestIntegration(t) }
func TestTags(t *testing.T) {
// Verify that we're only using strict set of tags.
// This helps to avoid typos in tag names.
//
// Also check that exactly 1 category tag is used.
for _, info := range lintpack.GetCheckersInfo() {
categories := 0
for _, tag := range info.Tags {
switch tag {
case "diagnostic", "style", "performance":
// Category tags.
// Can only have one of them.
categories++
case "experimental", "opinionated":
// Optional tags.
default:
t.Errorf("%q checker uses unknown tag %q", info.Name, tag)
}
}
if categories != 1 {
t.Errorf("%q expected to have 1 category, found %d",
info.Name, categories)
}
}
}
func TestStableList(t *testing.T) {
// Verify that new checker is not added without "experimental"
// tag by accident. When stable checker is about to be added,
// slice above should be modified to include new checker name.
// It is a good practice to keep this list sorted.
stableList := []string{
"appendAssign",
"appendCombine",
"assignOp",
"builtinShadow",
"captLocal",
"caseOrder",
"defaultCaseOrder",
"dupArg",
"dupBranchBody",
"dupCase",
"elseif",
"flagDeref",
"ifElseChain",
"importShadow",
"indexAlloc",
"paramTypeCombine",
"rangeExprCopy",
"rangeValCopy",
"regexpMust",
"singleCaseSwitch",
"sloppyLen",
"switchTrue",
"typeSwitchVar",
"typeUnparen",
"underef",
"unlambda",
"unslice",
"dupSubExpr",
"hugeParam",
}
m := make(map[string]bool)
for _, name := range stableList {
m[name] = true
}
for _, info := range lintpack.GetCheckersInfo() {
if info.HasTag("experimental") {
continue
}
if !m[info.Name] {
t.Errorf("%q checker misses `experimental` tag", info.Name)
}
}
}