staticcheck.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // staticcheck analyses Go code and makes it better.
  2. package main // import "honnef.co/go/tools/cmd/staticcheck"
  3. import (
  4. "log"
  5. "os"
  6. "golang.org/x/tools/go/analysis"
  7. "honnef.co/go/tools/lint"
  8. "honnef.co/go/tools/lint/lintutil"
  9. "honnef.co/go/tools/simple"
  10. "honnef.co/go/tools/staticcheck"
  11. "honnef.co/go/tools/stylecheck"
  12. "honnef.co/go/tools/unused"
  13. )
  14. func main() {
  15. fs := lintutil.FlagSet("staticcheck")
  16. wholeProgram := fs.Bool("unused.whole-program", false, "Run unused in whole program mode")
  17. debug := fs.String("debug.unused-graph", "", "Write unused's object graph to `file`")
  18. fs.Parse(os.Args[1:])
  19. var cs []*analysis.Analyzer
  20. for _, v := range simple.Analyzers {
  21. cs = append(cs, v)
  22. }
  23. for _, v := range staticcheck.Analyzers {
  24. cs = append(cs, v)
  25. }
  26. for _, v := range stylecheck.Analyzers {
  27. cs = append(cs, v)
  28. }
  29. u := unused.NewChecker(*wholeProgram)
  30. if *debug != "" {
  31. f, err := os.OpenFile(*debug, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. u.Debug = f
  36. }
  37. cums := []lint.CumulativeChecker{u}
  38. lintutil.ProcessFlagSet(cs, cums, fs)
  39. }