Add stringintconv and ifaceassert to govet (#1360)
This commit is contained in:
parent
191d6c873b
commit
f00da2c0b7
@ -17,6 +17,7 @@ import (
|
|||||||
"golang.org/x/tools/go/analysis/passes/errorsas"
|
"golang.org/x/tools/go/analysis/passes/errorsas"
|
||||||
"golang.org/x/tools/go/analysis/passes/findcall"
|
"golang.org/x/tools/go/analysis/passes/findcall"
|
||||||
"golang.org/x/tools/go/analysis/passes/httpresponse"
|
"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/inspect" // unused internal analyzer
|
||||||
"golang.org/x/tools/go/analysis/passes/loopclosure"
|
"golang.org/x/tools/go/analysis/passes/loopclosure"
|
||||||
"golang.org/x/tools/go/analysis/passes/lostcancel"
|
"golang.org/x/tools/go/analysis/passes/lostcancel"
|
||||||
@ -28,6 +29,7 @@ import (
|
|||||||
"golang.org/x/tools/go/analysis/passes/shift"
|
"golang.org/x/tools/go/analysis/passes/shift"
|
||||||
"golang.org/x/tools/go/analysis/passes/sortslice"
|
"golang.org/x/tools/go/analysis/passes/sortslice"
|
||||||
"golang.org/x/tools/go/analysis/passes/stdmethods"
|
"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/structtag"
|
||||||
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
|
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
|
||||||
"golang.org/x/tools/go/analysis/passes/tests"
|
"golang.org/x/tools/go/analysis/passes/tests"
|
||||||
@ -55,6 +57,7 @@ var (
|
|||||||
errorsas.Analyzer,
|
errorsas.Analyzer,
|
||||||
findcall.Analyzer,
|
findcall.Analyzer,
|
||||||
httpresponse.Analyzer,
|
httpresponse.Analyzer,
|
||||||
|
ifaceassert.Analyzer,
|
||||||
loopclosure.Analyzer,
|
loopclosure.Analyzer,
|
||||||
lostcancel.Analyzer,
|
lostcancel.Analyzer,
|
||||||
nilfunc.Analyzer,
|
nilfunc.Analyzer,
|
||||||
@ -64,6 +67,7 @@ var (
|
|||||||
shift.Analyzer,
|
shift.Analyzer,
|
||||||
sortslice.Analyzer,
|
sortslice.Analyzer,
|
||||||
stdmethods.Analyzer,
|
stdmethods.Analyzer,
|
||||||
|
stringintconv.Analyzer,
|
||||||
structtag.Analyzer,
|
structtag.Analyzer,
|
||||||
testinggoroutine.Analyzer,
|
testinggoroutine.Analyzer,
|
||||||
tests.Analyzer,
|
tests.Analyzer,
|
||||||
@ -90,6 +94,7 @@ var (
|
|||||||
printf.Analyzer,
|
printf.Analyzer,
|
||||||
shift.Analyzer,
|
shift.Analyzer,
|
||||||
stdmethods.Analyzer,
|
stdmethods.Analyzer,
|
||||||
|
stringintconv.Analyzer,
|
||||||
structtag.Analyzer,
|
structtag.Analyzer,
|
||||||
tests.Analyzer,
|
tests.Analyzer,
|
||||||
unmarshal.Analyzer,
|
unmarshal.Analyzer,
|
||||||
|
7
test/testdata/govet.go
vendored
7
test/testdata/govet.go
vendored
@ -8,7 +8,7 @@ import (
|
|||||||
"os"
|
"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"
|
return &os.PathError{"first", "path", os.ErrNotExist} // ERROR "composites: \\`(os|io/fs)\\.PathError\\` composite literal uses unkeyed fields"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,3 +36,8 @@ func GovetPrintf() {
|
|||||||
x := "dummy"
|
x := "dummy"
|
||||||
fmt.Printf("%d", x) // ERROR "printf: Printf format %d has arg x of wrong type string"
|
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
test/testdata/govet_ifaceassert.go
vendored
Normal file
14
test/testdata/govet_ifaceassert.go
vendored
Normal file
@ -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\\)"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user