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/cmd/goimports: confusing error message when file contains CRLF #70297

Open
abitrolly opened this issue Nov 12, 2024 · 8 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@abitrolly
Copy link

Go version

go version go1.23.3 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
  set GOARCH=amd64
  set GOBIN=
  set GOCACHE=C:\Users\runneradmin\AppData\Local\go-build
  set GOENV=C:\Users\runneradmin\AppData\Roaming\go\env
  set GOEXE=.exe
  set GOEXPERIMENT=
  set GOFLAGS=
  set GOHOSTARCH=amd64
  set GOHOSTOS=windows
  set GOINSECURE=
  set GOMODCACHE=C:\Users\runneradmin\go\pkg\mod
  set GONOPROXY=
  set GONOSUMDB=
  set GOOS=windows
  set GOPATH=C:\Users\runneradmin\go
  set GOPRIVATE=
  set GOPROXY=https://proxy.golang.org,direct
  set GOROOT=C:\hostedtoolcache\windows\go\1.23.3\x64
  set GOSUMDB=sum.golang.org
  set GOTMPDIR=
  set GOTOOLCHAIN=auto
  set GOTOOLDIR=C:\hostedtoolcache\windows\go\1.23.3\x64\pkg\tool\windows_amd64
  set GOVCS=
  set GOVERSION=go1.23.3
  set GODEBUG=
  set GOTELEMETRY=local
  set GOTELEMETRYDIR=C:\Users\runneradmin\AppData\Roaming\go\telemetry
  set GCCGO=gccgo
  set GOAMD64=v1
  set AR=ar
  set CC=gcc
  set CXX=g++
  set CGO_ENABLED=1
  set GOMOD=D:\a\sflags\sflags\go.mod
  set GOWORK=
  set CGO_CFLAGS=-O2 -g
  set CGO_CPPFLAGS=
  set CGO_CXXFLAGS=-O2 -g
  set CGO_FFLAGS=-O2 -g
  set CGO_LDFLAGS=-O2 -g
  set PKG_CONFIG=pkg-config
  set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\RUNNER~1\AppData\Local\Temp\go-build1760277560=/tmp/go-build -gno-record-gcc-switches

What did you do?

Run golangci-lint which invokes goimports on Windows machine.

https://github.com/urfave/sflags/actions/runs/11786526137/job/32829983012

Other reports are visible from golangci/golangci-lint#580

What did you see happen?

cmd\genvalues\main.go:1: File is not `goimports`-ed (goimports)

What did you expect to see?

cmd\genvalues\main.go:1: File contains CRLF linefeeds (goimports)
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 12, 2024
@gopherbot gopherbot added this to the Unreleased milestone Nov 12, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/627215 mentions this issue: internal/imports: keep the crlf if exist

@cherrymui
Copy link
Member

There have been a number of discussions about CRLF. I couldn't find exactly what the conclusion was. The CL above replaces \n to \r\n as long as there exists a single \r\n, which I don't think is the right behavior.

cc @golang/tools-team

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 12, 2024
@Zxilly
Copy link
Member

Zxilly commented Nov 13, 2024

I don't have a complaint about always defaulting to \n, maybe what we should do is ignore the difference between \n and \r\n when diffing, which also solves this issue.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/627415 mentions this issue: cmd/goimports: ignore line breaks when comparing

@findleyr
Copy link
Member

My understanding is that gofmt'ed code has \n line endings (see for example #16355. Am I misunderstanding?

goimports leaves code in gofmt'ed state, so this seems to be working as intended. The error message in question seems to be coming from a different tool (cmd\genvalues\main.go), not goimports itself.

@Zxilly
Copy link
Member

Zxilly commented Feb 20, 2025

The file cmd/genvalues/main.go is the problematic file detected in the user's project, which is not related to the Go project.

@findleyr
Copy link
Member

@Zxilly my comment is about Go code in general, not just code in the Go project. cmd/genvalues/main.go is the system that produced the confusing error message above. As you note, that is not our code.

The go community has standardized on gofmt, and gofmt has standardized on \n. Therefore, it is correct that goimports produce a diff in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants