by GreaterFool · 10y ago · 0 comments
https://godoc.org/golang.org/x/tools/cmd/goimports
Hook it to your editor's save command and never worry about imports again.
On the other hand, stop leaving unused variables around...
Plus, now your compiler has options.
I don't think there's any problem with doing that. I use a linter to stop me committing code that has unused variables in it, and to highlight those kinds of style issues in my editor so I'm aware of them. But for a compiler to refuse to run unpolished code in development is just bad design.
It's as if Go's designers took the hubristic or naive view that all code would, in an ideal world, be typed out perfectly first time, as opposed to being gradually hammered into shape through trial and error. This is worse than a design flaw, it feels like an active imposition.