From 9db5019d19af1bee1415215b0df44a3591913cc4 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:09:09 -0600 Subject: [PATCH 01/11] Remove interfacer linter --- pkg/golinters/interfacer.go | 67 ------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 pkg/golinters/interfacer.go diff --git a/pkg/golinters/interfacer.go b/pkg/golinters/interfacer.go deleted file mode 100644 index 1edbe894cc6a..000000000000 --- a/pkg/golinters/interfacer.go +++ /dev/null @@ -1,67 +0,0 @@ -package golinters - -import ( - "sync" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/passes/buildssa" - "mvdan.cc/interfacer/check" - - "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" - "github.com/golangci/golangci-lint/pkg/lint/linter" - "github.com/golangci/golangci-lint/pkg/result" -) - -const interfacerName = "interfacer" - -func NewInterfacer() *goanalysis.Linter { - var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: interfacerName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Requires: []*analysis.Analyzer{buildssa.Analyzer}, - } - return goanalysis.NewLinter( - interfacerName, - "Linter that suggests narrower interface types", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - analyzer.Run = func(pass *analysis.Pass) (interface{}, error) { - ssa := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) - ssaPkg := ssa.Pkg - c := &check.Checker{} - prog := goanalysis.MakeFakeLoaderProgram(pass) - c.Program(prog) - c.ProgramSSA(ssaPkg.Prog) - - issues, err := c.Check() - if err != nil { - return nil, err - } - if len(issues) == 0 { - return nil, nil - } - - res := make([]goanalysis.Issue, 0, len(issues)) - for _, i := range issues { - pos := pass.Fset.Position(i.Pos()) - res = append(res, goanalysis.NewIssue(&result.Issue{ - Pos: pos, - Text: i.Message(), - FromLinter: interfacerName, - }, pass)) - } - - mu.Lock() - resIssues = append(resIssues, res...) - mu.Unlock() - - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) -} From 53581adcd3872864f887c3f19408ebaa9714e389 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:09:26 -0600 Subject: [PATCH 02/11] Remove interfacer replace pattern --- pkg/result/processors/identifier_marker.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/result/processors/identifier_marker.go b/pkg/result/processors/identifier_marker.go index 5cc4e56ba229..a7de46cefd72 100644 --- a/pkg/result/processors/identifier_marker.go +++ b/pkg/result/processors/identifier_marker.go @@ -23,9 +23,6 @@ var replacePatterns = []replacePattern{ {`^(\S+) - (\S+) always receives (.*)$`, "`${1}` - `${2}` always receives `${3}`"}, {`^(\S+) - result (\S+) is always (\S+)`, "`${1}` - result `${2}` is always `${3}`"}, - // interfacer - {`^(\S+) can be (\S+)$`, "`${1}` can be `${2}`"}, - // govet {`^printf: (\S+) arg list ends with redundant newline$`, "printf: `${1}` arg list ends with redundant newline"}, {`^composites: (\S+) composite literal uses unkeyed fields$`, "composites: `${1}` composite literal uses unkeyed fields"}, From ff04a25568202e2c8917ec78f45623f39c726c80 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:10:37 -0600 Subject: [PATCH 03/11] Remove interfacer nolint comments --- pkg/golinters/scopelint.go | 1 - pkg/result/processors/base_rule.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/golinters/scopelint.go b/pkg/golinters/scopelint.go index ba3921e1964e..a3538c5543a1 100644 --- a/pkg/golinters/scopelint.go +++ b/pkg/golinters/scopelint.go @@ -162,7 +162,6 @@ func (f *Node) Visit(node ast.Node) ast.Visitor { // The variadic arguments may start with link and category types, // and must end with a format string and any arguments. -//nolint:interfacer func (f *Node) errorf(n ast.Node, format string, args ...interface{}) { pos := f.fset.Position(n.Pos()) f.errorAtf(pos, format, args...) diff --git a/pkg/result/processors/base_rule.go b/pkg/result/processors/base_rule.go index b6ce4f2159e9..a485b579bc2a 100644 --- a/pkg/result/processors/base_rule.go +++ b/pkg/result/processors/base_rule.go @@ -58,7 +58,7 @@ func (r *baseRule) matchLinter(issue *result.Issue) bool { return false } -func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { // nolint:interfacer +func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { sourceLine, errSourceLine := lineCache.GetLine(issue.FilePath(), issue.Line()) if errSourceLine != nil { log.Warnf("Failed to get line %s:%d from line cache: %s", issue.FilePath(), issue.Line(), errSourceLine) From cec8ac01fb8355b32393ed1ead2bd9854c7b59f8 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:11:01 -0600 Subject: [PATCH 04/11] Remove interfacer linter config --- pkg/lint/lintersdb/manager.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index b8f4ed880df7..c1509328cd8a 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -168,10 +168,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). WithURL("https://github.com/opennota/check"), - linter.NewConfig(golinters.NewInterfacer()). - WithLoadForGoAnalysis(). - WithPresets(linter.PresetStyle). - WithURL("https://github.com/mvdan/interfacer"), linter.NewConfig(golinters.NewUnconvert()). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). From cb094efeab322954f425f0d828fed370811f6b92 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:11:19 -0600 Subject: [PATCH 05/11] Remove InterfacerCheck --- test/testdata/interfacer.go | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/testdata/interfacer.go diff --git a/test/testdata/interfacer.go b/test/testdata/interfacer.go deleted file mode 100644 index 55b1e291d0f7..000000000000 --- a/test/testdata/interfacer.go +++ /dev/null @@ -1,8 +0,0 @@ -//args: -Einterfacer -package testdata - -import "io" - -func InterfacerCheck(f io.ReadCloser) { // ERROR "`f` can be `io.Closer`" - f.Close() -} From 4969966c14ee3b832a288c87169b80a3d374bbc0 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:15:33 -0600 Subject: [PATCH 06/11] Update bench to run golangci-lint only --- test/bench/bench_test.go | 56 ++++++---------------------------------- 1 file changed, 8 insertions(+), 48 deletions(-) diff --git a/test/bench/bench_test.go b/test/bench/bench_test.go index 77e4e5dca01c..226eecb8b4ff 100644 --- a/test/bench/bench_test.go +++ b/test/bench/bench_test.go @@ -16,7 +16,6 @@ import ( gops "github.com/mitchellh/go-ps" "github.com/shirou/gopsutil/process" - "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/test/testshared" ) @@ -36,7 +35,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) { _, err := os.Stat(dir) if os.IsNotExist(err) { repo := fmt.Sprintf("https://github.com/%s/%s.git", owner, name) - err = exec.Command("git", "clone", repo).Run() + err = exec.Command("git", "clone", repo, dir).Run() if err != nil { b.Fatalf("can't git clone %s/%s: %s", owner, name, err) } @@ -56,7 +55,6 @@ func getBenchLintersArgsNoMegacheck() []string { "--enable=errcheck", "--enable=dupl", "--enable=ineffassign", - "--enable=interfacer", "--enable=unconvert", "--enable=goconst", "--enable=gosec", @@ -69,21 +67,6 @@ func getBenchLintersArgs() []string { }, getBenchLintersArgsNoMegacheck()...) } -func getGometalinterCommonArgs() []string { - return []string{ - "--deadline=30m", - "--skip=testdata", - "--skip=builtin", - "--vendor", - "--cyclo-over=30", - "--dupl-threshold=150", - "--exclude", fmt.Sprintf("(%s)", strings.Join(config.GetDefaultExcludePatternsStrings(), "|")), - "--disable-all", - "--enable=vet", - "--enable=vetshadow", - } -} - func printCommand(cmd string, args ...string) { if os.Getenv("PRINT_CMD") != "1" { return @@ -96,16 +79,6 @@ func printCommand(cmd string, args ...string) { log.Printf("%s %s", cmd, strings.Join(quotedArgs, " ")) } -func runGometalinter(b *testing.B) { - args := []string{} - args = append(args, getGometalinterCommonArgs()...) - args = append(args, getBenchLintersArgs()...) - args = append(args, "./...") - - printCommand("gometalinter", args...) - _ = exec.Command("gometalinter", args...).Run() -} - func getGolangciLintCommonArgs() []string { return []string{"run", "--no-config", "--issues-exit-code=0", "--deadline=30m", "--disable-all", "--enable=govet"} } @@ -211,20 +184,6 @@ type runResult struct { duration time.Duration } -func compare(b *testing.B, gometalinterRun, golangciLintRun func(*testing.B), repoName, mode string, kLOC int) { - gometalinterRes := runOne(b, gometalinterRun, "gometalinter") - golangciLintRes := runOne(b, golangciLintRun, "golangci-lint") - - if mode != "" { - mode = " " + mode - } - log.Printf("%s (%d kLoC): golangci-lint%s: time: %s, %.1f times faster; memory: %dMB, %.1f times less", - repoName, kLOC, mode, - golangciLintRes.duration, gometalinterRes.duration.Seconds()/golangciLintRes.duration.Seconds(), - golangciLintRes.peakMemMB, float64(gometalinterRes.peakMemMB)/float64(golangciLintRes.peakMemMB), - ) -} - func runOne(b *testing.B, run func(*testing.B), progName string) *runResult { doneCh := make(chan struct{}) peakMemCh := trackPeakMemoryUsage(b, doneCh, progName) @@ -240,7 +199,7 @@ func runOne(b *testing.B, run func(*testing.B), progName string) *runResult { } } -func BenchmarkWithGometalinter(b *testing.B) { +func BenchmarkGolangciLint(b *testing.B) { testshared.NewLintRunner(b).Install() type bcase struct { @@ -252,10 +211,6 @@ func BenchmarkWithGometalinter(b *testing.B) { name: "self repo", prepare: prepareGithubProject("golangci", "golangci-lint"), }, - { - name: "gometalinter repo", - prepare: prepareGithubProject("alecthomas", "gometalinter"), - }, { name: "hugo", prepare: prepareGithubProject("gohugoio", "hugo"), @@ -284,7 +239,12 @@ func BenchmarkWithGometalinter(b *testing.B) { for _, bc := range bcases { bc.prepare(b) lc := getGoLinesTotalCount(b) + result := runOne(b, runGolangciLintForBench, "golangci-lint") - compare(b, runGometalinter, runGolangciLintForBench, bc.name, "", lc/1000) + log.Printf("%s (%d kLoC): time: %s, memory: %dMB", + bc.name, lc/1000, + result.duration, + result.peakMemMB, + ) } } From 903844f5f7b54271247ac0b2a71472944ad89acc Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:15:45 -0600 Subject: [PATCH 07/11] Run go mod tidy --- go.mod | 2 -- go.sum | 4 ---- 2 files changed, 6 deletions(-) diff --git a/go.mod b/go.mod index db1ed3326b34..2527dcd02db4 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 honnef.co/go/tools v0.0.1-2020.1.6 mvdan.cc/gofumpt v0.1.0 - mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed - mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7 ) diff --git a/go.sum b/go.sum index 25a3338cbf96..200afffe5979 100644 --- a/go.sum +++ b/go.sum @@ -648,10 +648,6 @@ honnef.co/go/tools v0.0.1-2020.1.6 h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YV honnef.co/go/tools v0.0.1-2020.1.6/go.mod h1:pyyisuGw24ruLjrr1ddx39WE0y9OooInRzEYLhQB2YY= mvdan.cc/gofumpt v0.1.0 h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw= mvdan.cc/gofumpt v0.1.0/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48= -mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I= -mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= -mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphDJbHOQO1DFFFTeBo= -mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7 h1:kAREL6MPwpsk1/PQPFD3Eg7WAQR5mPTWZJaBiG5LDbY= mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7/go.mod h1:HGC5lll35J70Y5v7vCGb9oLhHoScFwkHDJm/05RdSTc= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= From 872931ae43989e4435293c087aba3b6bc8032bed Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sat, 13 Feb 2021 17:25:09 -0600 Subject: [PATCH 08/11] Remove interfacer from .golangci.yml --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 830b3f405c3b..863177f73837 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -88,7 +88,6 @@ linters: - gosimple - govet - ineffassign - - interfacer - lll - misspell - nakedret From 1d3f6ddad94c1704051526778925627de6204d31 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sun, 21 Feb 2021 12:54:59 -0600 Subject: [PATCH 09/11] Reconcile go.mod after merge --- go.mod | 2 ++ go.sum | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/go.mod b/go.mod index 780c21781291..ba63e10b8e5a 100644 --- a/go.mod +++ b/go.mod @@ -79,5 +79,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 honnef.co/go/tools v0.1.2 mvdan.cc/gofumpt v0.1.0 + mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed + mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7 ) diff --git a/go.sum b/go.sum index 24c12815babf..874315fd6a58 100644 --- a/go.sum +++ b/go.sum @@ -656,6 +656,10 @@ honnef.co/go/tools v0.1.2 h1:SMdYLJl312RXuxXziCCHhRsp/tvct9cGKey0yv95tZM= honnef.co/go/tools v0.1.2/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= mvdan.cc/gofumpt v0.1.0 h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw= mvdan.cc/gofumpt v0.1.0/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48= +mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I= +mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= +mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphDJbHOQO1DFFFTeBo= +mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7 h1:kAREL6MPwpsk1/PQPFD3Eg7WAQR5mPTWZJaBiG5LDbY= mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7/go.mod h1:HGC5lll35J70Y5v7vCGb9oLhHoScFwkHDJm/05RdSTc= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= From e40130c35296cd6447973430e14ab44aad4bd4e0 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sun, 21 Feb 2021 13:11:09 -0600 Subject: [PATCH 10/11] Restore interfacer nolint directives --- pkg/golinters/scopelint.go | 1 + pkg/result/processors/base_rule.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/golinters/scopelint.go b/pkg/golinters/scopelint.go index a3538c5543a1..ba3921e1964e 100644 --- a/pkg/golinters/scopelint.go +++ b/pkg/golinters/scopelint.go @@ -162,6 +162,7 @@ func (f *Node) Visit(node ast.Node) ast.Visitor { // The variadic arguments may start with link and category types, // and must end with a format string and any arguments. +//nolint:interfacer func (f *Node) errorf(n ast.Node, format string, args ...interface{}) { pos := f.fset.Position(n.Pos()) f.errorAtf(pos, format, args...) diff --git a/pkg/result/processors/base_rule.go b/pkg/result/processors/base_rule.go index a485b579bc2a..b6ce4f2159e9 100644 --- a/pkg/result/processors/base_rule.go +++ b/pkg/result/processors/base_rule.go @@ -58,7 +58,7 @@ func (r *baseRule) matchLinter(issue *result.Issue) bool { return false } -func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { +func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { // nolint:interfacer sourceLine, errSourceLine := lineCache.GetLine(issue.FilePath(), issue.Line()) if errSourceLine != nil { log.Warnf("Failed to get line %s:%d from line cache: %s", issue.FilePath(), issue.Line(), errSourceLine) From 96b99cd697d5c02f646646df8f3447f993fc85f6 Mon Sep 17 00:00:00 2001 From: Patrick Kuca Date: Sun, 21 Feb 2021 13:11:20 -0600 Subject: [PATCH 11/11] Restore interfacer replace pattern --- pkg/result/processors/identifier_marker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/result/processors/identifier_marker.go b/pkg/result/processors/identifier_marker.go index a7de46cefd72..5cc4e56ba229 100644 --- a/pkg/result/processors/identifier_marker.go +++ b/pkg/result/processors/identifier_marker.go @@ -23,6 +23,9 @@ var replacePatterns = []replacePattern{ {`^(\S+) - (\S+) always receives (.*)$`, "`${1}` - `${2}` always receives `${3}`"}, {`^(\S+) - result (\S+) is always (\S+)`, "`${1}` - result `${2}` is always `${3}`"}, + // interfacer + {`^(\S+) can be (\S+)$`, "`${1}` can be `${2}`"}, + // govet {`^printf: (\S+) arg list ends with redundant newline$`, "printf: `${1}` arg list ends with redundant newline"}, {`^composites: (\S+) composite literal uses unkeyed fields$`, "composites: `${1}` composite literal uses unkeyed fields"},