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

x/tools/go/analysis/internal/checker: if offsetedit's start is 0, it can't be apply #54774

Closed
Abirdcfly opened this issue Aug 30, 2022 · 2 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Abirdcfly
Copy link
Contributor

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.TextEditsis

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.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Aug 30, 2022
@gopherbot gopherbot added this to the Unreleased milestone Aug 30, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/426654 mentions this issue: go/analysis/internal/checker: applyFixes condition changed to greater…

@heschi
Copy link
Contributor

heschi commented Aug 30, 2022

@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2022
@timothy-king timothy-king added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Analysis Issues related to static analysis (vet, x/tools/go/analysis) and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 30, 2022
Abirdcfly added a commit to Abirdcfly/tools that referenced this issue Sep 4, 2022
Make sure modifying the first character of the file takes effect
Fixes golang/go#54774
Abirdcfly added a commit to Abirdcfly/tools that referenced this issue Sep 7, 2022
Make sure modifying the first character of the file takes effect.

Fixes golang/go#54774
Abirdcfly added a commit to Abirdcfly/tools that referenced this issue Sep 7, 2022
…racter

Make sure modifying the first character of the file takes effect.

Fixes golang/go#54774
Abirdcfly added a commit to Abirdcfly/dupword that referenced this issue Sep 9, 2022
 x/tools/go/analysis/internal/checker: if offsetedit's start is 0, it can't be apply golang/go#54774 and has been fixed by CL 426654
@golang golang locked and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants