-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Milestone
Description
What version of Go are you using (go version
)?
$ go version go version go1.19 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="auto" GOARCH="amd64" GOBIN="/usr/local/opt/go/libexec/bin" GOCACHE="/Users/fupeng/Library/Caches/go-build" GOENV="/Users/fupeng/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/fupeng/go/pkg/mod" GONOPROXY="*tenxcloud.com" GONOSUMDB="*tenxcloud.com" GOOS="darwin" GOPATH="/Users/fupeng/go" GOPRIVATE="*tenxcloud.com" GOPROXY="https://goproxy.cn" GOROOT="/usr/local/opt/go/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/fupeng/go/src/dupword/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3v/mkwyck4x0f5bxv2gdv4_l8v00000gn/T/go-build2181850160=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
1. Create the simplest linter by following the example in the singlechecker documentation
// GOPATH/showlintererr/main.go
package main
import (
"golang.org/x/tools/go/analysis/passes/assign" <------- this Analyzer detects useless assignments.
"golang.org/x/tools/go/analysis/singlechecker"
)
func main() {
singlechecker.Main(assign.Analyzer)
}
2. give some error example
// GOPATH/showlinterexample/a.go
package showlinterexample
func A() {
x := 2
x = x
y := 3
y = y
}
and _test.go
:
// GOPATH/showlinterexample/a_test.go
package showlinterexample
import (
"testing"
)
func TestA(t *testing.T) {
z := 4
z = z
_ = z
}
3. run this linter
$ go run ../showlintererr/main.go -fix -test ./...
/Users/fupeng/go/src/showlinterexample/a.go:5:2: self-assignment of x to x
/Users/fupeng/go/src/showlinterexample/a.go:7:2: self-assignment of y to y
/Users/fupeng/go/src/showlinterexample/a_test.go:9:2: self-assignment of z to z <---- error in _test.go display !
exit status 3
$ cat a.go
package showlinterexample
func A() {
x := 2
<------------ error in source file auto-fix
y := 3
_, _ = x, y
}
$ cat a_test.go
package showlinterexample
import (
"testing"
)
func TestA(t *testing.T) {
z := 4
z = z <------------ error in _test.go file ** not ** auto fix
_ = z
}
$ go run ../showlintererr/main.go -fix -test ./...
/Users/fupeng/go/src/showlinterexample/a_test.go:9:2: self-assignment of z to z
exit status 3
$ cat a_test.go
package showlinterexample
import (
"testing"
)
func TestA(t *testing.T) {
z := 4
<------------ error in _test.go file auto fix run command again.
_ = z
}
What did you expect to see?
auto-fix should run once, and all error should be fix.
What did you see instead?
errors in the test file are displayed, but not automatically fixed.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.