@@ -36,6 +36,22 @@ func (d Depguard) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Is
36
36
dg .ListType = depguardAPI .LTBlacklist
37
37
}
38
38
39
+ if dg .ListType == depguardAPI .LTBlacklist {
40
+ // if the list type was a blacklist the packages with error messages should
41
+ // be included in the blacklist package list
42
+
43
+ noMessagePackages := make (map [string ]bool )
44
+ for _ , pkg := range dg .Packages {
45
+ noMessagePackages [pkg ] = true
46
+ }
47
+
48
+ for pkg := range lintCtx .Settings ().Depguard .PackagesWithErrorMessage {
49
+ if _ , ok := noMessagePackages [pkg ]; ! ok {
50
+ dg .Packages = append (dg .Packages , pkg )
51
+ }
52
+ }
53
+ }
54
+
39
55
issues , err := dg .Run (lintCtx .LoaderConfig , lintCtx .Program )
40
56
if err != nil {
41
57
return nil , err
@@ -49,9 +65,13 @@ func (d Depguard) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Is
49
65
}
50
66
res := make ([]result.Issue , 0 , len (issues ))
51
67
for _ , i := range issues {
68
+ userSuppliedMsgSuffix := lintCtx .Settings ().Depguard .PackagesWithErrorMessage [i .PackageName ]
69
+ if userSuppliedMsgSuffix != "" {
70
+ userSuppliedMsgSuffix = ": " + userSuppliedMsgSuffix
71
+ }
52
72
res = append (res , result.Issue {
53
73
Pos : i .Position ,
54
- Text : fmt .Sprintf ("%s %s" , formatCode (i .PackageName , lintCtx .Cfg ), msgSuffix ),
74
+ Text : fmt .Sprintf ("%s %s%s " , formatCode (i .PackageName , lintCtx .Cfg ), msgSuffix , userSuppliedMsgSuffix ),
55
75
FromLinter : d .Name (),
56
76
})
57
77
}
0 commit comments