From a893212f0208b5fc32d74dc148a85c9d709a4ec8 Mon Sep 17 00:00:00 2001 From: Ryan Currah Date: Sun, 20 Dec 2020 05:27:55 -0500 Subject: [PATCH] gomodguard: updated for new features and fixes (#1567) --- .golangci.example.yml | 1 + go.mod | 2 +- go.sum | 4 ++++ pkg/config/config.go | 1 + pkg/golinters/gomodguard.go | 8 ++++---- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index c994edc3..4c5e0fe0 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -263,6 +263,7 @@ linters-settings: # - github.com/mitchellh/go-homedir: # Blocked module with version constraint # version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons # reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional) + local_replace_directives: false # Set to true to raise lint issues for packages that are loaded from a local path via replace directive govet: # report about shadowed variables check-shadowing: true diff --git a/go.mod b/go.mod index 1c19b514..a5c212e8 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/nishanths/exhaustive v0.1.0 github.com/pkg/errors v0.9.1 github.com/polyfloyd/go-errorlint v0.0.0-20201127212506-19bd8db6546f - github.com/ryancurrah/gomodguard v1.1.0 + github.com/ryancurrah/gomodguard v1.2.0 github.com/ryanrolds/sqlclosecheck v0.3.0 github.com/securego/gosec/v2 v2.5.0 github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c diff --git a/go.sum b/go.sum index d59c3f73..1b4211a2 100644 --- a/go.sum +++ b/go.sum @@ -334,6 +334,8 @@ github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryancurrah/gomodguard v1.1.0 h1:DWbye9KyMgytn8uYpuHkwf0RHqAYO6Ay/D0TbCpPtVU= github.com/ryancurrah/gomodguard v1.1.0/go.mod h1:4O8tr7hBODaGE6VIhfJDHcwzh5GUccKSJBU0UMXJFVM= +github.com/ryancurrah/gomodguard v1.2.0 h1:YWfhGOrXwLGiqcC/u5EqG6YeS8nh+1fw0HEc85CVZro= +github.com/ryancurrah/gomodguard v1.2.0/go.mod h1:rNqbC4TOIdUDcVMSIpNNAzTbzXAZa6W5lnUepvuMMgQ= github.com/ryanrolds/sqlclosecheck v0.3.0 h1:AZx+Bixh8zdUBxUA1NxbxVAS78vTPq4rCb8OUZI9xFw= github.com/ryanrolds/sqlclosecheck v0.3.0/go.mod h1:1gREqxyTGR3lVtpngyFo3hZAgk0KCtEdgEkHwDbigdA= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -453,6 +455,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/pkg/config/config.go b/pkg/config/config.go index 34f6ba65..1e2c7943 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -245,6 +245,7 @@ type LintersSettings struct { Version string `mapstructure:"version"` Reason string `mapstructure:"reason"` } `mapstructure:"versions"` + LocalReplaceDirectives bool `mapstructure:"local_replace_directives"` } `mapstructure:"blocked"` } diff --git a/pkg/golinters/gomodguard.go b/pkg/golinters/gomodguard.go index 1376ad15..af2e6d1d 100644 --- a/pkg/golinters/gomodguard.go +++ b/pkg/golinters/gomodguard.go @@ -1,8 +1,6 @@ package golinters import ( - "log" - "os" "sync" "github.com/ryancurrah/gomodguard" @@ -40,7 +38,7 @@ func NewGomodguard() *goanalysis.Linter { var ( files = []string{} linterCfg = lintCtx.Cfg.LintersSettings.Gomodguard - processorCfg = gomodguard.Configuration{} + processorCfg = &gomodguard.Configuration{} ) processorCfg.Allowed.Modules = linterCfg.Allowed.Modules processorCfg.Allowed.Domains = linterCfg.Allowed.Domains @@ -70,7 +68,9 @@ func NewGomodguard() *goanalysis.Linter { files = append(files, pass.Fset.PositionFor(file.Pos(), false).Filename) } - processor, err := gomodguard.NewProcessor(processorCfg, log.New(os.Stderr, "", 0)) + processorCfg.Blocked.LocalReplaceDirectives = linterCfg.Blocked.LocalReplaceDirectives + + processor, err := gomodguard.NewProcessor(processorCfg) if err != nil { lintCtx.Log.Warnf("running gomodguard failed: %s: if you are not using go modules "+ "it is suggested to disable this linter", err)