-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: support gofmt option to simplify code #21476
Comments
FWIW, it's a historical artifact that the simplify (-s) mechanism is implemented as part of the gofmt command. I think AST simplification (and rewriting) should be factored out and provided via separate libraries. Then those libraries could be trivially used from other places (incl. gofmt or goimports if so desired). |
@griesemer So basically, to implement this, someone should first factor out the simplification code and then use that to implement simplification in goimports? |
@mbyio Yes. |
@griesemer isn't the point of |
@jimeh goimports already does more than gofmt. I'm just suggesting that simplifications such as this should be factored out into a separate library. Maybe that library is used by gofmt and goimports, or just goimports. But the main point is that the code should be isolated into a separate package. |
Using
goimports
as of golang/tools@84a35efThe
goimports
command handles import fixing andgofmt
code formatting. It does not, however, implement the code simplification option-s
.This means that
goimports
cannot be used as a drop-in replacement to save-hooks that usegofmt -s
(for example, when using-s
as thegofmt-args
value for the save-hook withgo-mode.el
).There are no problems identified by
goimports
:With
gofmt -s
, we get:The text was updated successfully, but these errors were encountered: