Skip to content

Commit f00da2c

Browse files
author
Sergey Vilgelm
authored
Add stringintconv and ifaceassert to govet (#1360)
1 parent 191d6c8 commit f00da2c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkg/golinters/govet.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"golang.org/x/tools/go/analysis/passes/errorsas"
1818
"golang.org/x/tools/go/analysis/passes/findcall"
1919
"golang.org/x/tools/go/analysis/passes/httpresponse"
20+
"golang.org/x/tools/go/analysis/passes/ifaceassert"
2021
_ "golang.org/x/tools/go/analysis/passes/inspect" // unused internal analyzer
2122
"golang.org/x/tools/go/analysis/passes/loopclosure"
2223
"golang.org/x/tools/go/analysis/passes/lostcancel"
@@ -28,6 +29,7 @@ import (
2829
"golang.org/x/tools/go/analysis/passes/shift"
2930
"golang.org/x/tools/go/analysis/passes/sortslice"
3031
"golang.org/x/tools/go/analysis/passes/stdmethods"
32+
"golang.org/x/tools/go/analysis/passes/stringintconv"
3133
"golang.org/x/tools/go/analysis/passes/structtag"
3234
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
3335
"golang.org/x/tools/go/analysis/passes/tests"
@@ -55,6 +57,7 @@ var (
5557
errorsas.Analyzer,
5658
findcall.Analyzer,
5759
httpresponse.Analyzer,
60+
ifaceassert.Analyzer,
5861
loopclosure.Analyzer,
5962
lostcancel.Analyzer,
6063
nilfunc.Analyzer,
@@ -64,6 +67,7 @@ var (
6467
shift.Analyzer,
6568
sortslice.Analyzer,
6669
stdmethods.Analyzer,
70+
stringintconv.Analyzer,
6771
structtag.Analyzer,
6872
testinggoroutine.Analyzer,
6973
tests.Analyzer,
@@ -90,6 +94,7 @@ var (
9094
printf.Analyzer,
9195
shift.Analyzer,
9296
stdmethods.Analyzer,
97+
stringintconv.Analyzer,
9398
structtag.Analyzer,
9499
tests.Analyzer,
95100
unmarshal.Analyzer,

test/testdata/govet.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
)
1010

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

@@ -36,3 +36,8 @@ func GovetPrintf() {
3636
x := "dummy"
3737
fmt.Printf("%d", x) // ERROR "printf: Printf format %d has arg x of wrong type string"
3838
}
39+
40+
func GovetStringIntConv() {
41+
i := 42
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\\)\\?\\)"
43+
}

test/testdata/govet_ifaceassert.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//args: -Egovet
2+
//config: linters-settings.govet.enable=ifaceassert
3+
package testdata
4+
5+
import (
6+
"io"
7+
)
8+
9+
func GovetIfaceAssert() {
10+
var v interface {
11+
Read()
12+
}
13+
_ = v.(io.Reader) // ERROR "impossible type assertion: no type can implement both interface\\{Read\\(\\)\\} and io\\.Reader \\(conflicting types for Read method\\)"
14+
}

0 commit comments

Comments
 (0)