Closed
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/golang-tools/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-build515639227=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I'm developing an linter to remove duplicate words from comments.(Yes, I know this scenario would be fine in many cases using the text tool, I just wanted to learn go ast by the way)
When my test file is as follows:
/*
package a
this comment include duplicated word and
and so the current line of `and` should
be removed
*/
package a
After run dupword -fix ./...
this file become :
package a
My analysis.Diagnostic.SuggestedFixes.TextEdits
is
TextEdits: []analysis.TextEdit{{
Pos: c.Slash,
End: c.End(),
NewText: []byte(update),
}},
https://github.com/golang/tools/blob/248c34b88a4148128f89e41923498bd86f805b7d/go/analysis/internal/checker/checker.go#L377
change to offsetedit
, the offsetedit.start
is 0. And it is ignored in https://github.com/golang/tools/blob/master/go/analysis/internal/checker/checker.go#L408
What did you expect to see?
even if TextEdits.Pos
is 0, it can be applied.
What did you see instead?
Just be deleted.