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

cmd/gofmt: ignores explicit file arguments not named with ".go" after CL 284138 #45859

Closed
cherrymui opened this issue Apr 29, 2021 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@cherrymui
Copy link
Member

What version of Go are you using (go version)?

tip (6d95e5a)

Does this issue reproduce with the latest release?

No.

What did you do?

Run gofmt with an input file not named with ".go".

What did you expect to see?

Format the file, emit to stdout.

What did you see instead?

Emit nothing. No error either. The command succeeded silently.

$ cat x.go_
package p
$ gofmt x.go_
$ echo $?
0

It seems this is changed in CL https://go-review.googlesource.com/c/go/+/284138 .

The gofmt document ( https://golang.org/cmd/gofmt ) mentions

Given a file, it operates on that file; given a directory, it operates on all .go files in that directory, recursively.

For "a file" case, it does not clearly require ".go" (also not clearly mention it accepts non-".go" file). Previous versions of gofmt does work with non-".go" files.

cc @mvdan @griesemer @bcmills

@cherrymui cherrymui added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Apr 29, 2021
@cherrymui cherrymui added this to the Go1.17 milestone Apr 29, 2021
@mvdan
Copy link
Member

mvdan commented Apr 29, 2021

Thanks for reporting, seems like an unintended regression. I'll also add a test case, which presumably is missing.

@mvdan mvdan self-assigned this Apr 29, 2021
@mvdan mvdan changed the title cmd/gofmt: emit empty output for input files not named with ".go" after CL 284138 cmd/gofmt: ignores explicit file arguments not named with ".go" after CL 284138 Apr 29, 2021
@gopherbot
Copy link

Change https://golang.org/cl/315270 mentions this issue: cmd/gofmt: always format non-directory arguments again

@golang golang locked and limited conversation to collaborators Apr 30, 2022
@rsc rsc unassigned mvdan Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants