-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathidentifier_marker_test.go
139 lines (124 loc) · 3.39 KB
/
identifier_marker_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package processors
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/golangci/golangci-lint/pkg/result"
)
func TestIdentifierMarker_Process(t *testing.T) {
testCases := []struct {
desc string
linter string
in string
out string
}{
// unparam
{
linter: "unparam",
in: "foo - bar is unused",
out: "`foo` - `bar` is unused",
},
{
linter: "unparam",
in: "foo - bar always receives fii (abc)",
out: "`foo` - `bar` always receives `fii` (`abc`)",
},
{
linter: "unparam",
in: "foo - bar always receives fii",
out: "`foo` - `bar` always receives `fii`",
},
{
linter: "unparam",
in: "createEntry - result err is always nil",
out: "`createEntry` - result `err` is always `nil`",
},
// govet
{
linter: "govet",
in: "printf: foo arg list ends with redundant newline",
out: "printf: `foo` arg list ends with redundant newline",
},
// gosec
{
linter: "gosec",
in: "TLS InsecureSkipVerify set true.",
out: "TLS `InsecureSkipVerify` set true.",
},
// gosimple
{
linter: "gosimple",
in: "should replace loop with foo",
out: "should replace loop with `foo`",
},
{
linter: "gosimple",
in: "should use a simple channel send/receive instead of select with a single case",
out: "should use a simple channel send/receive instead of `select` with a single case",
},
{
linter: "gosimple",
in: "should omit comparison to bool constant, can be simplified to !projectIntegration.Model.Storage",
out: "should omit comparison to bool constant, can be simplified to `!projectIntegration.Model.Storage`",
},
{
linter: "gosimple",
in: "redundant return statement",
out: "redundant `return` statement",
},
{
linter: "gosimple",
in: "S1017: should replace this if statement with an unconditional strings.TrimPrefix",
out: "S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`",
},
// staticcheck
{
linter: "staticcheck",
in: "this value of foo is never used",
out: "this value of `foo` is never used",
},
{
linter: "staticcheck",
in: "should use time.Since instead of time.Now().Sub",
out: "should use `time.Since` instead of `time.Now().Sub`",
},
{
linter: "staticcheck",
in: "should check returned error before deferring response.Close()",
out: "should check returned error before deferring `response.Close()`",
},
{
linter: "staticcheck",
in: "no value of type uint is less than 0",
out: "no value of type `uint` is less than `0`",
},
// unused
{
linter: "unused",
in: "var testInputs is unused",
out: "var `testInputs` is unused",
},
// From a linter without patterns.
{
linter: "foo",
in: "var testInputs is unused",
out: "var testInputs is unused",
},
// Non-matching text.
{
linter: "unused",
in: "foo is a foo",
out: "foo is a foo",
},
}
p := NewIdentifierMarker()
for _, test := range testCases {
t.Run(fmt.Sprintf("%s: %s", test.linter, test.in), func(t *testing.T) {
t.Parallel()
out, err := p.Process([]result.Issue{{FromLinter: test.linter, Text: test.in}})
require.NoError(t, err)
assert.Equal(t, []result.Issue{{FromLinter: test.linter, Text: test.out}}, out)
})
}
}