Skip to content

Commit

Permalink
fix: remove init flagset
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 2, 2024
1 parent edc3520 commit c34372d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions errorlint/analysis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package errorlint

import (
"flag"
"go/ast"
"go/types"
"sort"
Expand All @@ -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)
Expand Down

0 comments on commit c34372d

Please sign in to comment.