diff --git a/errorlint/analysis.go b/errorlint/analysis.go index eb47112..26c174c 100644 --- a/errorlint/analysis.go +++ b/errorlint/analysis.go @@ -1,7 +1,6 @@ package errorlint import ( - "flag" "go/ast" "go/types" "sort" @@ -16,29 +15,27 @@ func NewAnalyzer(opts ...Option) *analysis.Analyzer { allowedMapAppend(allowedErrors) - return &analysis.Analyzer{ - Name: "errorlint", - Doc: "Source code linter for Go software that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.", - Run: run, - Flags: flagSet, + a := &analysis.Analyzer{ + Name: "errorlint", + Doc: "Source code linter for Go software that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.", + Run: run, } + + a.Flags.BoolVar(&checkComparison, "comparison", true, "Check for plain error comparisons") + a.Flags.BoolVar(&checkAsserts, "asserts", true, "Check for plain type assertions and type switches") + a.Flags.BoolVar(&checkErrorf, "errorf", false, "Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats") + a.Flags.BoolVar(&checkErrorfMulti, "errorf-multi", true, "Permit more than 1 %w verb, valid per Go 1.20 (Requires -errorf=true)") + + return a } var ( - flagSet flag.FlagSet checkComparison bool checkAsserts bool checkErrorf bool checkErrorfMulti bool ) -func init() { - flagSet.BoolVar(&checkComparison, "comparison", true, "Check for plain error comparisons") - flagSet.BoolVar(&checkAsserts, "asserts", true, "Check for plain type assertions and type switches") - flagSet.BoolVar(&checkErrorf, "errorf", false, "Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats") - flagSet.BoolVar(&checkErrorfMulti, "errorf-multi", true, "Permit more than 1 %w verb, valid per Go 1.20 (Requires -errorf=true)") -} - func run(pass *analysis.Pass) (interface{}, error) { var lints []analysis.Diagnostic extInfo := newTypesInfoExt(pass)