github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/cmd/staticcheck/staticcheck.go (about)

     1  // staticcheck analyses Go code and makes it better.
     2  package main
     3  
     4  import (
     5  	"log"
     6  	"os"
     7  
     8  	"github.com/amarpal/go-tools/lintcmd"
     9  	"github.com/amarpal/go-tools/lintcmd/version"
    10  	"github.com/amarpal/go-tools/quickfix"
    11  	"github.com/amarpal/go-tools/simple"
    12  	"github.com/amarpal/go-tools/staticcheck"
    13  	"github.com/amarpal/go-tools/stylecheck"
    14  	"github.com/amarpal/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  }