cmd/staticcheck: add flag for dumping 'unused' debug graph
package main // import "honnef.co/go/tools/cmd/staticcheck"
import (
+ "log"
"os"
"golang.org/x/tools/go/analysis"
@@ -16,6 +17,7 @@ import (
func main() {
fs := lintutil.FlagSet("staticcheck")
wholeProgram := fs.Bool("unused.whole-program", false, "Run unused in whole program mode")
+ debug := fs.String("debug.unused-graph", "", "Write unused's object graph to `file`")
fs.Parse(os.Args[1:])
var cs []*analysis.Analyzer
@@ -30,6 +32,13 @@ func main() {
}
u := unused.NewChecker(*wholeProgram)
+ if *debug != "" {
+ f, err := os.OpenFile(*debug, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
+ if err != nil {
+ log.Fatal(err)
+ }
+ u.Debug = f
+ }
cums := []lint.CumulativeChecker{u}
lintutil.ProcessFlagSet(cs, cums, fs)
}
