Skip to content

Commit

Permalink
depguard: throw error only when the linter is called (#3880)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 2, 2023
1 parent 2e907f9 commit 68be5ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2
github.com/gofrs/flock v0.8.1
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
github.com/golangci/depguard/v2 v2.0.2-0.20230601235138-ed68d3771f48
github.com/golangci/depguard/v2 v2.0.2-0.20230602133032-4f22f8585733
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe
github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions pkg/golinters/depguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

func NewDepguard(settings *config.DepGuardSettings) *goanalysis.Linter {
Expand All @@ -32,15 +33,19 @@ func NewDepguard(settings *config.DepGuardSettings) *goanalysis.Linter {
}
}

a, err := depguard.NewAnalyzer(&conf)
if err != nil {
linterLogger.Fatalf("depguard: create analyzer: %v", err)
}
a := depguard.NewCoreAnalyzer(depguard.CoreSettings{})

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
).WithContextSetter(func(lintCtx *linter.Context) {
coreSettings, err := conf.Compile()
if err != nil {
lintCtx.Log.Errorf("create analyzer: %v", err)
}

a.Run = coreSettings.Run
}).WithLoadMode(goanalysis.LoadModeSyntax)
}

0 comments on commit 68be5ba

Please sign in to comment.