| 1 |
// staticcheck analyses Go code and makes it better. |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"log" |
| 6 |
"os" |
| 7 |
|
| 8 |
"honnef.co/go/tools/lintcmd" |
| 9 |
"honnef.co/go/tools/lintcmd/version" |
| 10 |
"honnef.co/go/tools/quickfix" |
| 11 |
"honnef.co/go/tools/simple" |
| 12 |
"honnef.co/go/tools/staticcheck" |
| 13 |
"honnef.co/go/tools/stylecheck" |
| 14 |
"honnef.co/go/tools/unused" |
| 15 |
) |
| 16 |
|
| 17 |
func main() { |
| 18 |
cmd := lintcmd.NewCommand("staticcheck") |
| 19 |
cmd.SetVersion(version.Version, version.MachineVersion) |
| 20 |
|
| 21 |
fs := cmd.FlagSet() |
| 22 |
debug := fs.String("debug.unused-graph", "", "Write unused's object graph to `file`") |
| 23 |
qf := fs.Bool("debug.run-quickfix-analyzers", false, "Run quickfix analyzers") |
| 24 |
|
| 25 |
cmd.ParseFlags(os.Args[1:]) |
| 26 |
|
| 27 |
cmd.AddAnalyzers(simple.Analyzers...) |
| 28 |
cmd.AddAnalyzers(staticcheck.Analyzers...) |
| 29 |
cmd.AddAnalyzers(stylecheck.Analyzers...) |
| 30 |
cmd.AddAnalyzers(unused.Analyzer) |
| 31 |
|
| 32 |
if *qf { |
| 33 |
cmd.AddAnalyzers(quickfix.Analyzers...) |
| 34 |
} |
| 35 |
|
| 36 |
if *debug != "" { |
| 37 |
f, err := os.OpenFile(*debug, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
| 38 |
if err != nil { |
| 39 |
log.Fatal(err) |
| 40 |
} |
| 41 |
unused.Debug = f |
| 42 |
} |
| 43 |
|
| 44 |
cmd.Run() |
| 45 |
} |