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

proposal: cmd/go: add go fmt -s #35258

Closed
willfaught opened this issue Oct 30, 2019 · 5 comments

Comments

@willfaught
Copy link
Contributor

@willfaught willfaught commented Oct 30, 2019

gofmt currently has a very useful -s flag:

-s simplify code

It would be great to have this in go fmt as well, so I can stop using gofmt altogether.

@gopherbot gopherbot added this to the Proposal milestone Oct 30, 2019
@gopherbot gopherbot added the Proposal label Oct 30, 2019
@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Oct 31, 2019

Somewhat related to #21476, since the "simplify" functionality isn't reusable by multiple tools at the moment.

@rsc rsc changed the title proposal: add simplify (-s) flag from gofmt to go fmt proposal: cmd/go: add simplify (-s) flag from gofmt to go fmt Nov 14, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 14, 2019

It's unclear where this ends. Should we add -r too? Then the gofmt and go command flags have to remain disjoint. It seems better to invoke gofmt when you want to use more than just the standard reformatting.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 20, 2019

Any new extensions of gofmt are likely to be new tools. The -s and -r flags are pieces of history but not the right place for equivalent functionality being added today. Also go fmt does not just invoke gofmt. It invokes gofmt -l -w. Adding more flag control would be a bit odd for that reason too.

Note that gofmt can be pointed at a directory tree.

This seems like a likely decline.

Leaving open for a week for final comments.

@willfaught

This comment has been minimized.

Copy link
Contributor Author

@willfaught willfaught commented Nov 20, 2019

Those are all good points. If go fmt will forever remain a simple invocation of gofmt, then this should be closed.

I think it would be simpler for go fmt to be the only tool for formatting Go code. Currently, we have go fmt and gofmt to choose from, and their options and behavior aren't equivalent. I see the go doc and godoc split that was recently addressed as being similar. Now go doc is the only tool for browsing documentation on the command line (with the handy new -all flag), and godoc handles other concerns. I think I had that kind of simplification in mind when thinking about this proposal. Not sure whether it's appropriate to pivot this specific GitHub issue to be about that broader idea, or if I should just create a new issue for it. Advice/thoughts appreciated.

@rsc rsc added this to Final Comment in Proposals Nov 27, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 27, 2019

gofmt is invoked from tons of scripts; godoc was not.
In an ideal world maybe we'd have one, but we have two.
Also go fmt only works on packages (like everything in the go command)
while lots of editors and the like want to pipe into gofmt.
It would be very odd for go fmt to read stdin instead of operating on the current directory like go build etc.
It seems like fundamentally we need two.

In any event, there doesn't seem to be any change in the argument for not adding more flags to the existing go fmt, so declining.

@rsc rsc closed this Nov 27, 2019
@rsc rsc changed the title proposal: cmd/go: add simplify (-s) flag from gofmt to go fmt proposal: cmd/go: add go fmt -s Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.