Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Alert syntax errors for "imported and not used" imports #104

Closed
ahmetb opened this issue Nov 26, 2015 · 3 comments
Closed

Alert syntax errors for "imported and not used" imports #104

ahmetb opened this issue Nov 26, 2015 · 3 comments

Comments

@ahmetb
Copy link

ahmetb commented Nov 26, 2015

This is the most annoying feature of go compiler –it fails when source files contain unused imports:

drivers/azurenew/azurenew.go:4: imported and not used: "errors"
drivers/azurenew/azurenew.go:6: imported and not used: "os"
drivers/azurenew/azurenew.go:7: imported and not used: "os/exec"
drivers/azurenew/azurenew.go:8: imported and not used: "strings"

Every time I refactor code I find myself going through the compile-edit-compile-edit... loop and I think vscode can help here.

We just need to highlight imports as syntax errors and say "imported and not used". Not sure if doable but that'd make thinks a great deal easier. Maybe goimports can help. https://godoc.org/golang.org/x/tools/cmd/goimports

@newhook
Copy link
Contributor

newhook commented Nov 26, 2015

Use goimports.

@ahmetb
Copy link
Author

ahmetb commented Nov 26, 2015

@newhook hmm the readme doesn't mention goimports but interestingly I started to get the error:

image

I don't have goimports installed yet.

@lukehoban
Copy link
Contributor

The "format" command will run whichever of gofmt, goimports or goreturns you choose via go.formatTool settings. These build on one another so goimports does everything gofmt does plus more and goreturns does everything goimports does plus more.

For what you want here, you want at least goimports which will automatically add/remove imports as needed by your code.

Out of the box, assuming you've installed all the tools (see this comment), running Format Document should fix up imports for you.

#14 is tracking adding an option to enabled format-on-save so that you don't even need to do a separate action to get formatting + imports fixup.

Given all that, I'm not sure there's anything additional to address here. If you think there is something beyond what's tracked in those other issues though feel free to reopen.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants