goimports is a command-line formatter for Go source code. It extends gofmt-style formatting by maintaining import declarations at the same time, adding packages required by the source and removing imports that are no longer referenced. This makes it useful in editor save hooks and automated source-maintenance workflows where formatting and import cleanup should happen together.
The tool can process files, directory trees, or source supplied through standard input. Import selection is context-aware, so it can resolve imports according to the effective location of the source rather than simply rearranging existing lines.
This is free and open source software.
Key Features
- Adds missing import declarations required by Go source code.
- Removes imports that are no longer referenced.
- Formats code in the same general style as gofmt.
- Can list files whose formatting would change.
- Supports writing formatted output back to source files.
- Can display unified diffs instead of rewriting files.
- Accepts input from standard input, files, and directory trees.
- Supports a source-directory override for context-sensitive import resolution.
- Can place configured local import prefixes after third-party packages.
- Offers a format-only mode that leaves import selection unchanged.
Website: github.com/golang/tools/tree/master/cmd/goimports
Support:
Developer: The Go Authors
License: BSD 3-Clause License
goimports is written in Go. Learn Go with our recommended free books and free tutorials.
Explore our carefully curated directory of recommended free and open source software, covering every major software category.The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk. LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more. Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form. |


Please read our Comment Policy before commenting.