Skip to content

ineffassign: use upstream instead of golangci fork #1780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
1 change: 1 addition & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()).
Expand Down
2 changes: 0 additions & 2 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")).
Expand Down
6 changes: 4 additions & 2 deletions test/testdata/ineffassign.go
Original file line number Diff line number Diff line change
@@ -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
}
}