From eefb97438cd8572fa8b59003dd1dd9ae390ef298 Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Thu, 25 Feb 2021 17:36:43 -0600 Subject: [PATCH] ineffassign: use upstrea instead of golangci fork (#1780) --- go.mod | 2 +- go.sum | 4 +-- pkg/golinters/ineffassign.go | 52 +++-------------------------------- pkg/lint/lintersdb/manager.go | 1 + test/run_test.go | 2 -- test/testdata/ineffassign.go | 6 ++-- 6 files changed, 12 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index d7dfac693082..2302e8707fb5 100644 --- a/go.mod +++ b/go.mod @@ -25,12 +25,12 @@ require ( github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613 github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a - github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770 github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5 github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 + github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3 github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3 diff --git a/go.sum b/go.sum index 4ef6a4476232..9e88d7142295 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,6 @@ github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613 h1:9kfjN3AdxcbsZB github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613/go.mod h1:SyvUF2NxV+sN8upjjeVYr5W7tyxaT1JVtvhKhOn2ii8= github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a h1:iR3fYXUjHCR97qWS8ch1y9zPNsgXThGwjKPrYfqMPks= github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU= -github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc h1:gLLhTLMk2/SutryVJ6D4VZCU3CUqr8YloG7FPIBWFpI= -github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= @@ -170,6 +168,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/gookit/color v1.3.6/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 h1:Nb2aRlC404yz7gQIfRZxX9/MLvQiqXyiBTJtgAy6yrI= +github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254/go.mod h1:M9mZEtGIsR1oDaZagNPNG9iq9n2HrhZ17dsXk73V3Lw= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= diff --git a/pkg/golinters/ineffassign.go b/pkg/golinters/ineffassign.go index 93c1fb11bbb8..d25adeea5cc1 100644 --- a/pkg/golinters/ineffassign.go +++ b/pkg/golinters/ineffassign.go @@ -1,61 +1,17 @@ package golinters import ( - "fmt" - "sync" - - "github.com/golangci/ineffassign" + "github.com/gordonklaus/ineffassign/pkg/ineffassign" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" ) -const ineffassignName = "ineffassign" - func NewIneffassign() *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: ineffassignName, - Doc: goanalysis.TheOnlyanalyzerDoc, - } return goanalysis.NewLinter( - ineffassignName, + "ineffassign", "Detects when assignments to existing variables are not used", - []*analysis.Analyzer{analyzer}, + []*analysis.Analyzer{ineffassign.Analyzer}, nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - analyzer.Run = func(pass *analysis.Pass) (interface{}, error) { - var fileNames []string - for _, f := range pass.Files { - pos := pass.Fset.PositionFor(f.Pos(), false) - fileNames = append(fileNames, pos.Filename) - } - - issues := ineffassign.Run(fileNames) - if len(issues) == 0 { - return nil, nil - } - - res := make([]goanalysis.Issue, 0, len(issues)) - for _, i := range issues { - res = append(res, goanalysis.NewIssue(&result.Issue{ - Pos: i.Pos, - Text: fmt.Sprintf("ineffectual assignment to %s", formatCode(i.IdentName, lintCtx.Cfg)), - FromLinter: ineffassignName, - }, pass)) - } - - mu.Lock() - resIssues = append(resIssues, res...) - mu.Unlock() - - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + ).WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 6ebeed72a8e8..17f621898d75 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -184,6 +184,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/mdempsky/unconvert"), linter.NewConfig(golinters.NewIneffassign()). + WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). WithURL("https://github.com/gordonklaus/ineffassign"), linter.NewConfig(golinters.NewDupl()). diff --git a/test/run_test.go b/test/run_test.go index 7c889cfcde8b..34a0736651f5 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -185,8 +185,6 @@ func TestLintFilesWithLineDirective(t *testing.T) { Run("-Egomodguard", "--disable-all", "--config=testdata/linedirective/gomodguard.yml", getTestDataDir("linedirective")). ExpectHasIssue("import of package `github.com/ryancurrah/gomodguard` is blocked because the module is not " + "in the allowed modules list. (gomodguard)") - r.Run("-Eineffassign", "--disable-all", "--no-config", getTestDataDir("linedirective")). - ExpectHasIssue("ineffectual assignment to `x` (ineffassign)") r.Run("-Elll", "--disable-all", "--config=testdata/linedirective/lll.yml", getTestDataDir("linedirective")). ExpectHasIssue("line is 57 characters (lll)") r.Run("-Emisspell", "--disable-all", "--no-config", getTestDataDir("linedirective")). diff --git a/test/testdata/ineffassign.go b/test/testdata/ineffassign.go index a792b6f6be50..69d3cc81c9c1 100644 --- a/test/testdata/ineffassign.go +++ b/test/testdata/ineffassign.go @@ -1,11 +1,13 @@ //args: -Eineffassign package testdata +import "math" + func _() { - x := 0 + x := math.MinInt8 for { _ = x - x = 0 // ERROR "ineffectual assignment to `x`" + x = 0 // ERROR "ineffectual assignment to x" x = 0 } }