Skip to content

Commit cd7de2e

Browse files
ldezpolyfloyd
authored andcommitted
fix: remove init flagset
1 parent 7898ab5 commit cd7de2e

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

errorlint/analysis.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package errorlint
22

33
import (
4-
"flag"
54
"go/ast"
65
"go/types"
76
"sort"
@@ -16,29 +15,27 @@ func NewAnalyzer(opts ...Option) *analysis.Analyzer {
1615

1716
allowedMapAppend(allowedErrors)
1817

19-
return &analysis.Analyzer{
20-
Name: "errorlint",
21-
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.",
22-
Run: run,
23-
Flags: flagSet,
18+
a := &analysis.Analyzer{
19+
Name: "errorlint",
20+
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.",
21+
Run: run,
2422
}
23+
24+
a.Flags.BoolVar(&checkComparison, "comparison", true, "Check for plain error comparisons")
25+
a.Flags.BoolVar(&checkAsserts, "asserts", true, "Check for plain type assertions and type switches")
26+
a.Flags.BoolVar(&checkErrorf, "errorf", false, "Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats")
27+
a.Flags.BoolVar(&checkErrorfMulti, "errorf-multi", true, "Permit more than 1 %w verb, valid per Go 1.20 (Requires -errorf=true)")
28+
29+
return a
2530
}
2631

2732
var (
28-
flagSet flag.FlagSet
2933
checkComparison bool
3034
checkAsserts bool
3135
checkErrorf bool
3236
checkErrorfMulti bool
3337
)
3438

35-
func init() {
36-
flagSet.BoolVar(&checkComparison, "comparison", true, "Check for plain error comparisons")
37-
flagSet.BoolVar(&checkAsserts, "asserts", true, "Check for plain type assertions and type switches")
38-
flagSet.BoolVar(&checkErrorf, "errorf", false, "Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats")
39-
flagSet.BoolVar(&checkErrorfMulti, "errorf-multi", true, "Permit more than 1 %w verb, valid per Go 1.20 (Requires -errorf=true)")
40-
}
41-
4239
func run(pass *analysis.Pass) (interface{}, error) {
4340
var lints []analysis.Diagnostic
4441
extInfo := newTypesInfoExt(pass)

errorlint/testdata/src/issues/github-21.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
)
99

1010
func Test1() error {
11-
return fmt.Errorf("%[1]v %[1]v: %w", "value", errors.New("abc")) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
11+
return fmt.Errorf("%[1]v %[1]v: %w", "value", errors.New("abc"))
1212
}
1313

1414
func Test2() error {
15-
return fmt.Errorf("%[1]v: %[1]w", errors.New("abc")) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
15+
return fmt.Errorf("%[1]v: %[1]w", errors.New("abc"))
1616
}

0 commit comments

Comments
 (0)