Skip to content
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

Add stringintconv and ifaceassert to govet #1360

Merged
merged 2 commits into from Feb 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/golinters/govet.go
Expand Up @@ -17,6 +17,7 @@ import (
"golang.org/x/tools/go/analysis/passes/errorsas"
"golang.org/x/tools/go/analysis/passes/findcall"
"golang.org/x/tools/go/analysis/passes/httpresponse"
"golang.org/x/tools/go/analysis/passes/ifaceassert"
_ "golang.org/x/tools/go/analysis/passes/inspect" // unused internal analyzer
"golang.org/x/tools/go/analysis/passes/loopclosure"
"golang.org/x/tools/go/analysis/passes/lostcancel"
Expand All @@ -28,6 +29,7 @@ import (
"golang.org/x/tools/go/analysis/passes/shift"
"golang.org/x/tools/go/analysis/passes/sortslice"
"golang.org/x/tools/go/analysis/passes/stdmethods"
"golang.org/x/tools/go/analysis/passes/stringintconv"
"golang.org/x/tools/go/analysis/passes/structtag"
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
"golang.org/x/tools/go/analysis/passes/tests"
Expand Down Expand Up @@ -55,6 +57,7 @@ var (
errorsas.Analyzer,
findcall.Analyzer,
httpresponse.Analyzer,
ifaceassert.Analyzer,
loopclosure.Analyzer,
lostcancel.Analyzer,
nilfunc.Analyzer,
Expand All @@ -64,6 +67,7 @@ var (
shift.Analyzer,
sortslice.Analyzer,
stdmethods.Analyzer,
stringintconv.Analyzer,
structtag.Analyzer,
testinggoroutine.Analyzer,
tests.Analyzer,
Expand All @@ -90,6 +94,7 @@ var (
printf.Analyzer,
shift.Analyzer,
stdmethods.Analyzer,
stringintconv.Analyzer,
structtag.Analyzer,
tests.Analyzer,
unmarshal.Analyzer,
Expand Down
7 changes: 6 additions & 1 deletion test/testdata/govet.go
Expand Up @@ -8,7 +8,7 @@ import (
"os"
)

func Govet() error {
func GovetComposites() error {
return &os.PathError{"first", "path", os.ErrNotExist} // ERROR "composites: \\`(os|io/fs)\\.PathError\\` composite literal uses unkeyed fields"
}

Expand Down Expand Up @@ -36,3 +36,8 @@ func GovetPrintf() {
x := "dummy"
fmt.Printf("%d", x) // ERROR "printf: Printf format %d has arg x of wrong type string"
}

func GovetStringIntConv() {
i := 42
fmt.Println("i = " + string(i)) // ERROR "stringintconv: conversion from int to string yields a string of one rune, not a string of digits \\(did you mean fmt.Sprint\\(x\\)\\?\\)"
}
14 changes: 14 additions & 0 deletions test/testdata/govet_ifaceassert.go
@@ -0,0 +1,14 @@
//args: -Egovet
//config: linters-settings.govet.enable=ifaceassert
package testdata

import (
"io"
)

func GovetIfaceAssert() {
var v interface {
Read()
}
_ = v.(io.Reader) // ERROR "impossible type assertion: no type can implement both interface\\{Read\\(\\)\\} and io\\.Reader \\(conflicting types for Read method\\)"
}