@@ -18,121 +18,177 @@ func TestStringFormatConfigure(t *testing.T) {
1818 {
1919 name : "Not a Slice" ,
2020 arguments : lint.Arguments {
21- "this is not a slice" },
22- wantErr : errors .New ("invalid configuration for string-format: argument is not a slice [argument 0, option 0]" )},
21+ "this is not a slice" ,
22+ },
23+ wantErr : errors .New ("invalid configuration for string-format: argument is not a slice [argument 0, option 0]" ),
24+ },
2325 {
2426 name : "Missing Regex" ,
2527 arguments : lint.Arguments {
2628 []any {
27- "method[0]" }},
28- wantErr : errors .New ("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]" )},
29+ "method[0]" ,
30+ },
31+ },
32+ wantErr : errors .New ("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]" ),
33+ },
2934 {
3035 name : "Bad Argument Type" ,
3136 arguments : lint.Arguments {
3237 []any {
33- 1 }},
34- wantErr : errors .New ("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]" )},
38+ 1 ,
39+ },
40+ },
41+ wantErr : errors .New ("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]" ),
42+ },
3543 {
3644 name : "Empty Scope" ,
3745 arguments : lint.Arguments {
3846 []any {
3947 "" ,
40- "//" }},
41- wantErr : errors .New ("invalid configuration for string-format: empty scope provided [argument 0, option 0]" )},
48+ "//" ,
49+ },
50+ },
51+ wantErr : errors .New ("invalid configuration for string-format: empty scope provided [argument 0, option 0]" ),
52+ },
4253 {
4354 name : "Small or Empty Regex" ,
4455 arguments : lint.Arguments {
4556 []any {
4657 "method[1].a" ,
47- "-" }},
48- wantErr : errors .New ("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]" )},
58+ "-" ,
59+ },
60+ },
61+ wantErr : errors .New ("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]" ),
62+ },
4963 {
5064 name : "Bad Scope" ,
5165 arguments : lint.Arguments {
5266 []any {
5367 "1.a" ,
54- "//" }},
55- wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]" )},
68+ "//" ,
69+ },
70+ },
71+ wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]" ),
72+ },
5673 {
5774 name : "Bad Regex" ,
5875 arguments : lint.Arguments {
5976 []any {
6077 "method[1].a" ,
61- "/(/" }},
62- wantErr : errors .New ("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]" )},
78+ "/(/" ,
79+ },
80+ },
81+ wantErr : errors .New ("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]" ),
82+ },
6383 {
6484 name : "Sample Config" ,
6585 arguments : lint.Arguments {
6686 []any {
67- "core.WriteError[1].Message" , "/^([^A-Z]$)/" , "must not start with a capital letter" },
87+ "core.WriteError[1].Message" , "/^([^A-Z]$)/" , "must not start with a capital letter" ,
88+ },
6889 []any {
69- "fmt.Errorf[0]" , "/^|[^\\ .!?]$/" , "must not end in punctuation" },
90+ "fmt.Errorf[0]" , "/^|[^\\ .!?]$/" , "must not end in punctuation" ,
91+ },
7092 []any {
71- "panic" , "/^[^\\ n]*$/" , "must not contain line breaks" }}},
93+ "panic" , "/^[^\\ n]*$/" , "must not contain line breaks" ,
94+ },
95+ },
96+ },
7297 {
7398 name : "Underscores in Scope" ,
7499 arguments : lint.Arguments {
75100 []any {
76101 "some_pkg._some_function_name[5].some_member" ,
77- "//" }}},
102+ "//" ,
103+ },
104+ },
105+ },
78106 {
79107 name : "Underscores in Multiple Scopes" ,
80108 arguments : lint.Arguments {
81109 []any {
82110 "fmt.Errorf[0],core.WriteError[1].Message" ,
83- "//" }}},
111+ "//" ,
112+ },
113+ },
114+ },
84115 {
85116 name : "', ' Delimiter" ,
86117 arguments : lint.Arguments {
87118 []any {
88119 "abc, mt.Errorf" ,
89- "//" }}},
120+ "//" ,
121+ },
122+ },
123+ },
90124 {
91125 name : "' ,' Delimiter" ,
92126 arguments : lint.Arguments {
93127 []any {
94128 "abc ,mt.Errorf" ,
95- "//" }}},
129+ "//" ,
130+ },
131+ },
132+ },
96133 {
97134 name : "', ' Delimiter" ,
98135 arguments : lint.Arguments {
99136 []any {
100137 "abc, mt.Errorf" ,
101- "//" }}},
138+ "//" ,
139+ },
140+ },
141+ },
102142 {
103143 name : "', ' Delimiter" ,
104144 arguments : lint.Arguments {
105145 []any {
106146 "abc, mt.Errorf" ,
107- "//" }}},
147+ "//" ,
148+ },
149+ },
150+ },
108151 {
109152 name : "Empty Middle Scope" ,
110153 arguments : lint.Arguments {
111154 []any {
112155 "abc, ,mt.Errorf" ,
113- "//" }},
114- wantErr : errors .New ("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]" )},
156+ "//" ,
157+ },
158+ },
159+ wantErr : errors .New ("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]" ),
160+ },
115161 {
116162 name : "Empty First Scope" ,
117163 arguments : lint.Arguments {
118164 []any {
119165 ",mt.Errorf" ,
120- "//" }},
121- wantErr : errors .New ("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]" )},
166+ "//" ,
167+ },
168+ },
169+ wantErr : errors .New ("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]" ),
170+ },
122171 {
123172 name : "Bad First Scope" ,
124173 arguments : lint.Arguments {
125174 []any {
126175 "1.a,fmt.Errorf[0]" ,
127- "//" }},
128- wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]" )},
176+ "//" ,
177+ },
178+ },
179+ wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]" ),
180+ },
129181 {
130182 name : "Bad Second Scope" ,
131183 arguments : lint.Arguments {
132184 []any {
133185 "fmt.Errorf[0],1.a" ,
134- "//" }},
135- wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]" )}}
186+ "//" ,
187+ },
188+ },
189+ wantErr : errors .New ("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]" ),
190+ },
191+ }
136192
137193 for _ , tt := range tests {
138194 t .Run (tt .name , func (t * testing.T ) {
0 commit comments