Skip to content

Commit

Permalink
Use upstream ineffassign instead of golangci fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Vilgelm committed Feb 25, 2021
1 parent b77118f commit 795077e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 52 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

52 changes: 4 additions & 48 deletions pkg/golinters/ineffassign.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion test/testdata/ineffassign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 795077e

Please sign in to comment.