How to disable Golang unused import error

前端 未结 8 2023
我寻月下人不归
我寻月下人不归 2020-12-05 03:30

By default, Go treats unused import as error, forcing you to delete the import. I want to know if there exists some hope to change to this behavior, e.g. reducing it to warn

相关标签:
8条回答
  • 2020-12-05 04:27

    Use if false { ... } to comment out some code. The code inside the braces must be syntactically correct, but can be nonsense code otherwise.

    0 讨论(0)
  • 2020-12-05 04:29

    put this on top of your document and forget about unused imports:

    import (
        "bufio"
        "fmt"
        "os"
        "path/filepath"
    )
    
    var _, _, _, _ = fmt.Println, bufio.NewReader, os.Open, filepath.IsAbs
    
    0 讨论(0)
提交回复
热议问题