lintcmd: restructure code
@@ -129,6 +129,7 @@ func (cmd *Command) initFlagSet(name string) {
flags.StringVar(&cmd.flags.formatter, "f", "text", "Output `format` (valid choices are 'stylish', 'text' and 'json')")
flags.StringVar(&cmd.flags.explain, "explain", "", "Print description of `check`")
flags.BoolVar(&cmd.flags.listChecks, "list-checks", false, "List all available checks")
+ flags.BoolVar(&cmd.flags.merge, "merge", false, "Merge results of multiple Staticcheck runs")
flags.StringVar(&cmd.flags.debugCpuprofile, "debug.cpuprofile", "", "Write CPU profile to `file`")
flags.StringVar(&cmd.flags.debugMemprofile, "debug.memprofile", "", "Write memory profile to `file`")
@@ -248,11 +249,6 @@ func (cmd *Command) Run() {
trace.Start(f)
}
- if cmd.flags.debugVersion {
- version.Verbose(cmd.version, cmd.machineVersion)
- exit(0)
- }
-
defaultChecks := []string{"all"}
cs := make([]*lint.Analyzer, 0, len(cmd.analyzers))
for _, a := range cmd.analyzers {
@@ -263,7 +259,10 @@ func (cmd *Command) Run() {
}
config.DefaultConfig.Checks = defaultChecks
- if cmd.flags.listChecks {
+ if cmd.flags.debugVersion {
+ version.Verbose(cmd.version, cmd.machineVersion)
+ exit(0)
+ } else if cmd.flags.listChecks {
sort.Slice(cs, func(i, j int) bool {
return cs[i].Analyzer.Name < cs[j].Analyzer.Name
})
@@ -275,22 +274,10 @@ func (cmd *Command) Run() {
fmt.Printf("%s %s\n", c.Analyzer.Name, title)
}
exit(0)
- }
-
- if cmd.flags.printVersion {
+ } else if cmd.flags.printVersion {
version.Print(cmd.version, cmd.machineVersion)
exit(0)
- }
-
- // Validate that the tags argument is well-formed. go/packages
- // doesn't detect malformed build flags and returns unhelpful
- // errors.
- tf := buildutil.TagsFlag{}
- if err := tf.Set(cmd.flags.tags); err != nil {
- fmt.Fprintln(os.Stderr, fmt.Errorf("invalid value %q for flag -tags: %s", cmd.flags.tags, err))
- exit(1)
- }
-
+ } else if explain := cmd.flags.explain; explain != "" {
if explain := cmd.flags.explain; explain != "" {
check, ok := cmd.analyzers[explain]
if !ok {
@@ -305,6 +292,15 @@ func (cmd *Command) Run() {
fmt.Println("Online documentation\n https://staticcheck.io/docs/checks#" + check.Analyzer.Name)
exit(0)
}
+ } else {
+ // Validate that the tags argument is well-formed. go/packages
+ // doesn't detect malformed build flags and returns unhelpful
+ // errors.
+ tf := buildutil.TagsFlag{}
+ if err := tf.Set(cmd.flags.tags); err != nil {
+ fmt.Fprintln(os.Stderr, fmt.Errorf("invalid value %q for flag -tags: %s", cmd.flags.tags, err))
+ exit(1)
+ }
var f formatter
switch cmd.flags.formatter {
@@ -395,9 +391,9 @@ func (cmd *Command) Run() {
exit(1)
}
}
-
exit(0)
}
+}
func usage(name string, fs *flag.FlagSet) func() {
return func() {
