github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/cmd/megacheck/megacheck.go (about)

     1  // megacheck runs staticcheck, gosimple and unused.
     2  package main // import "github.com/golangci/go-tools/cmd/megacheck"
     3  
     4  import (
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/golangci/go-tools/lint"
     9  	"github.com/golangci/go-tools/lint/lintutil"
    10  	"github.com/golangci/go-tools/simple"
    11  	"github.com/golangci/go-tools/staticcheck"
    12  	"github.com/golangci/go-tools/unused"
    13  )
    14  
    15  func main() {
    16  	fmt.Fprintln(os.Stderr, "Megacheck has been deprecated. Please use staticcheck instead.")
    17  
    18  	var flags struct {
    19  		staticcheck struct {
    20  			enabled   bool
    21  			generated bool
    22  		}
    23  		gosimple struct {
    24  			enabled   bool
    25  			generated bool
    26  		}
    27  		unused struct {
    28  			enabled      bool
    29  			constants    bool
    30  			fields       bool
    31  			functions    bool
    32  			types        bool
    33  			variables    bool
    34  			wholeProgram bool
    35  			reflection   bool
    36  		}
    37  	}
    38  	fs := lintutil.FlagSet("megacheck")
    39  	fs.BoolVar(&flags.gosimple.enabled,
    40  		"simple.enabled", true, "Deprecated: use -checks instead")
    41  	fs.BoolVar(&flags.gosimple.generated,
    42  		"simple.generated", false, "Check generated code")
    43  
    44  	fs.BoolVar(&flags.staticcheck.enabled,
    45  		"staticcheck.enabled", true, "Deprecated: use -checks instead")
    46  	fs.BoolVar(&flags.staticcheck.generated,
    47  		"staticcheck.generated", false, "Check generated code (only applies to a subset of checks)")
    48  
    49  	fs.BoolVar(&flags.unused.enabled,
    50  		"unused.enabled", true, "Deprecated: use -checks instead")
    51  	fs.BoolVar(&flags.unused.constants,
    52  		"unused.consts", true, "Report unused constants")
    53  	fs.BoolVar(&flags.unused.fields,
    54  		"unused.fields", true, "Report unused fields")
    55  	fs.BoolVar(&flags.unused.functions,
    56  		"unused.funcs", true, "Report unused functions and methods")
    57  	fs.BoolVar(&flags.unused.types,
    58  		"unused.types", true, "Report unused types")
    59  	fs.BoolVar(&flags.unused.variables,
    60  		"unused.vars", true, "Report unused variables")
    61  	fs.BoolVar(&flags.unused.wholeProgram,
    62  		"unused.exported", false, "Treat arguments as a program and report unused exported identifiers")
    63  	fs.BoolVar(&flags.unused.reflection,
    64  		"unused.reflect", true, "Consider identifiers as used when it's likely they'll be accessed via reflection")
    65  
    66  	fs.Bool("simple.exit-non-zero", true, "Deprecated: use -fail instead")
    67  	fs.Bool("staticcheck.exit-non-zero", true, "Deprecated: use -fail instead")
    68  	fs.Bool("unused.exit-non-zero", true, "Deprecated: use -fail instead")
    69  
    70  	fs.Parse(os.Args[1:])
    71  
    72  	var checkers []lint.Checker
    73  
    74  	if flags.staticcheck.enabled {
    75  		sac := staticcheck.NewChecker()
    76  		sac.CheckGenerated = flags.staticcheck.generated
    77  		checkers = append(checkers, sac)
    78  	}
    79  
    80  	if flags.gosimple.enabled {
    81  		sc := simple.NewChecker()
    82  		sc.CheckGenerated = flags.gosimple.generated
    83  		checkers = append(checkers, sc)
    84  	}
    85  
    86  	if flags.unused.enabled {
    87  		var mode unused.CheckMode
    88  		if flags.unused.constants {
    89  			mode |= unused.CheckConstants
    90  		}
    91  		if flags.unused.fields {
    92  			mode |= unused.CheckFields
    93  		}
    94  		if flags.unused.functions {
    95  			mode |= unused.CheckFunctions
    96  		}
    97  		if flags.unused.types {
    98  			mode |= unused.CheckTypes
    99  		}
   100  		if flags.unused.variables {
   101  			mode |= unused.CheckVariables
   102  		}
   103  		uc := unused.NewChecker(mode)
   104  		uc.WholeProgram = flags.unused.wholeProgram
   105  		uc.ConsiderReflection = flags.unused.reflection
   106  		checkers = append(checkers, unused.NewLintChecker(uc))
   107  	}
   108  
   109  	lintutil.ProcessFlagSet(checkers, fs)
   110  }