go
build_error
ai_generated
true
./main.go:5:2: 导入了但未使用:"fmt"
./main.go:5:2: imported and not used: "fmt"
ID: go/imported-and-not-used
80%修复率
95%置信度
0证据数
2024-01-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.x | active | — | — | — |
根因分析
声明了导入,但文件中未引用该包的任何标识符。Go 将未使用的导入视为编译错误。
English
An import is declared but no identifier from that package is referenced in the file. Go treats unused imports as a compile error.
解决方案
-
98% 成功率
// delete the import line, or run: goimports -w ./... # or: gofmt -w main.go
-
90% 成功率
import _ "net/http/pprof"
无效尝试
常见但无效的做法:
-
100% 失败
linters respect it but the compiler still errors
-
80% 失败
compiles but is dead code and often flagged by vet
-
100% 失败
does not disable unused-import errors