2013-12-19 15:26:26 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Command goimports updates your Go import lines,
|
|
|
|
adding missing ones and removing unreferenced ones.
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2014-11-09 14:50:40 -07:00
|
|
|
$ go get golang.org/x/tools/cmd/goimports
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2017-06-12 11:22:52 -06:00
|
|
|
In addition to fixing imports, goimports also formats
|
|
|
|
your code in the same style as gofmt so it can be used
|
|
|
|
as a replacement for your editor's gofmt-on-save hook.
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2014-07-01 11:24:22 -06:00
|
|
|
For emacs, make sure you have the latest go-mode.el:
|
|
|
|
https://github.com/dominikh/go-mode.el
|
2013-12-17 19:21:03 -07:00
|
|
|
Then in your .emacs file:
|
|
|
|
(setq gofmt-command "goimports")
|
|
|
|
(add-hook 'before-save-hook 'gofmt-before-save)
|
|
|
|
|
|
|
|
For vim, set "gofmt_command" to "goimports":
|
2014-12-11 19:58:46 -07:00
|
|
|
https://golang.org/change/39c724dd7f252
|
|
|
|
https://golang.org/wiki/IDEsAndTextEditorPlugins
|
2013-12-17 19:21:03 -07:00
|
|
|
etc
|
|
|
|
|
|
|
|
For GoSublime, follow the steps described here:
|
2014-01-02 12:02:13 -07:00
|
|
|
http://michaelwhatcott.com/gosublime-goimports/
|
2013-12-17 19:21:03 -07:00
|
|
|
|
|
|
|
For other editors, you probably know what to do.
|
|
|
|
|
2016-07-15 12:28:37 -06:00
|
|
|
To exclude directories in your $GOPATH from being scanned for Go
|
|
|
|
files, goimports respects a configuration file at
|
|
|
|
$GOPATH/src/.goimportsignore which may contain blank lines, comment
|
|
|
|
lines (beginning with '#'), or lines naming a directory relative to
|
|
|
|
the configuration file to ignore when scanning. No globbing or regex
|
|
|
|
patterns are allowed. Use the "-v" verbose flag to verify it's
|
|
|
|
working and see what goimports is doing.
|
|
|
|
|
|
|
|
File bugs or feature requests at:
|
|
|
|
|
|
|
|
https://golang.org/issues/new?title=x/tools/cmd/goimports:+
|
|
|
|
|
2013-12-17 19:21:03 -07:00
|
|
|
Happy hacking!
|
2013-12-19 15:26:26 -07:00
|
|
|
|
|
|
|
*/
|
2014-12-08 21:00:58 -07:00
|
|
|
package main // import "golang.org/x/tools/cmd/goimports"
|