@@ -36,6 +36,22 @@ func (d Depguard) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Is
3636 dg .ListType = depguardAPI .LTBlacklist
3737 }
3838
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+
3955 issues , err := dg .Run (lintCtx .LoaderConfig , lintCtx .Program )
4056 if err != nil {
4157 return nil , err
@@ -49,9 +65,13 @@ func (d Depguard) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Is
4965 }
5066 res := make ([]result.Issue , 0 , len (issues ))
5167 for _ , i := range issues {
68+ userSuppliedMsgSuffix := lintCtx .Settings ().Depguard .PackagesWithErrorMessage [i .PackageName ]
69+ if userSuppliedMsgSuffix != "" {
70+ userSuppliedMsgSuffix = ": " + userSuppliedMsgSuffix
71+ }
5272 res = append (res , result.Issue {
5373 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 ),
5575 FromLinter : d .Name (),
5676 })
5777 }
0 commit comments