goimports claims to be a drop-in replacement for editor's gofmt-on-save hook and have the same command-line interface as gofmt; but it does not support the -s flag. -s flag can be useful in on-save hook unlike gofmt's -r flag.
I am not against it but gofmt (or go fmt) is not depending on anything but the std lib at the moment. Note that we are also considering removing that -r option from gofmt; so it may make sense to remove the -s option as well and have a separate tool instead. Not for 1.4 for sure.
_Status changed to Thinking._
This is causing some issues on my end - is this ever going to be considered? Or, at the least, the documentation needs to be updated.
I forked the tools repository and added this behavior if anyone is interested: go install github.com/jzelinskie/tools/cmd/goimports
I just copied the code from gofmt and removed the import comments: https://github.com/jzelinskie/tools/commit/348c54dbd0dc54b93cd91d71cfd483d55d00f971
If you're using vim-go you can add the following to your .vimrc to get both gofmt -s and goimports on save.
let g:go_fmt_command = "goimports"
let g:go_fmt_options = "-s"
Related: #14500
(Note FTR: per https://github.com/golang/tools/commit/7d47e840ac8ec63c4a5cd5c900156cad5e6b6a63, goimports is no longer claimed to be "a drop-in replacement [for gofmt]".)
@akavel, thanks.
I'll close this then.
Most helpful comment
I forked the tools repository and added this behavior if anyone is interested:
go install github.com/jzelinskie/tools/cmd/goimportsI just copied the code from gofmt and removed the import comments: https://github.com/jzelinskie/tools/commit/348c54dbd0dc54b93cd91d71cfd483d55d00f971
If you're using vim-go you can add the following to your .vimrc to get both
gofmt -sandgoimportson save.