From 795077e1c6d93cf30bf0fccd5e0f7fd27baf6271 Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Thu, 25 Feb 2021 16:50:16 -0600 Subject: [PATCH] Use upstream ineffassign instead of golangci fork --- go.mod | 2 +- go.sum | 4 +-- pkg/golinters/ineffassign.go | 52 +++--------------------------------- test/testdata/ineffassign.go | 2 +- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/go.mod b/go.mod index d7dfac6930821..2302e8707fb5d 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 4ef6a44762329..9e88d71422950 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 93c1fb11bbb8e..d25adeea5cc17 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/test/testdata/ineffassign.go b/test/testdata/ineffassign.go index a792b6f6be502..5f53e44fd3a18 100644 --- a/test/testdata/ineffassign.go +++ b/test/testdata/ineffassign.go @@ -5,7 +5,7 @@ func _() { x := 0 for { _ = x - x = 0 // ERROR "ineffectual assignment to `x`" + x = 0 // ERROR "ineffectual assignment to x" x = 0 } }