@@ -159,6 +159,48 @@ var (
159
159
suggestions : []string {"Don't use Reflect" },
160
160
},
161
161
},
162
+ {
163
+ name : "Strict Mode Default" ,
164
+ list : & List {
165
+ Allow : []string {"os" },
166
+ Deny : map [string ]string {
167
+ "reflect" : "Don't use Reflect" ,
168
+ },
169
+ },
170
+ exp : & list {
171
+ listMode : listModeStrict ,
172
+ allow : []string {"os" },
173
+ deny : []string {"reflect" },
174
+ suggestions : []string {"Don't use Reflect" },
175
+ },
176
+ },
177
+ {
178
+ name : "Set Strict Mode" ,
179
+ list : & List {
180
+ ListMode : "sTriCT" ,
181
+ Allow : []string {"os" },
182
+ Deny : map [string ]string {
183
+ "reflect" : "Don't use Reflect" ,
184
+ },
185
+ },
186
+ exp : & list {
187
+ listMode : listModeStrict ,
188
+ allow : []string {"os" },
189
+ deny : []string {"reflect" },
190
+ suggestions : []string {"Don't use Reflect" },
191
+ },
192
+ },
193
+ {
194
+ name : "Unknown List Mode" ,
195
+ list : & List {
196
+ ListMode : "MiddleOut" ,
197
+ Allow : []string {"os" },
198
+ Deny : map [string ]string {
199
+ "reflect" : "Don't use Reflect" ,
200
+ },
201
+ },
202
+ expErr : errors .New ("MiddleOut is not a known list mode" ),
203
+ },
162
204
}
163
205
settingsCompileScenarios = []* settingsCompileScenario {
164
206
{
@@ -259,6 +301,7 @@ func init() {
259
301
// Only doing this so I have a controlled list of expansions for packages
260
302
utils .PackageExpandable ["$gostd" ] = & expanderTest {}
261
303
}
304
+
262
305
func TestListCompile (t * testing.T ) {
263
306
for _ , s := range listCompileScenarios {
264
307
t .Run (s .name , testListCompile (s ))
@@ -521,27 +564,45 @@ var listImportAllowedScenarios = []*listImportAllowedScenario{
521
564
},
522
565
},
523
566
{
524
- name : "Both only allows what is in allow and not in deny" ,
567
+ name : "Both in Strict mode allows what is in allow and not in deny" ,
525
568
setup : & list {
526
- allow : []string {"some/pkg/a" },
527
- deny : []string {"some/pkg/a/foo" },
528
- suggestions : []string {"because I said so" },
569
+ listMode : listModeStrict ,
570
+ allow : []string {"some/pkg/a/foo" , "some/pkg/b" , "some/pkg/c" },
571
+ deny : []string {"some/pkg/a" , "some/pkg/b/foo" },
572
+ suggestions : []string {"because I said so" , "really don't use" },
529
573
},
530
574
tests : []* listImportAllowedScenarioInner {
531
575
{
532
576
name : "in allow but not in deny" ,
533
- input : "some/pkg/a/bar " ,
577
+ input : "some/pkg/c/alpha " ,
534
578
expected : true ,
535
579
},
536
580
{
537
- name : "in allow and in deny " ,
581
+ name : "subpackage allowed but root denied " ,
538
582
input : "some/pkg/a/foo/bar" ,
539
583
expected : false ,
540
584
suggestion : "because I said so" ,
541
585
},
586
+ {
587
+ name : "subpackage not in allowed but root denied" ,
588
+ input : "some/pkg/a/baz" ,
589
+ expected : false ,
590
+ suggestion : "because I said so" ,
591
+ },
592
+ {
593
+ name : "subpackage denied but root allowed" ,
594
+ input : "some/pkg/b/foo/bar" ,
595
+ expected : false ,
596
+ suggestion : "really don't use" ,
597
+ },
598
+ {
599
+ name : "subpackage not denied but root allowed" ,
600
+ input : "some/pkg/b/baz" ,
601
+ expected : true ,
602
+ },
542
603
{
543
604
name : "not in allow nor in deny" ,
544
- input : "some/pkg/b/foo/bar " ,
605
+ input : "some/pkg/d/alpha " ,
545
606
expected : false ,
546
607
},
547
608
},
@@ -564,7 +625,6 @@ func TestListImportAllowed(t *testing.T) {
564
625
}
565
626
})
566
627
}
567
-
568
628
}
569
629
570
630
type linterSettingsWhichListsScenario struct {
0 commit comments