Skip to content

Commit e9d6427

Browse files
committed
fix: support empty value for checks flag
1 parent 7d3c6b1 commit e9d6427

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

pkg/analyzer/analyzer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ func (m enabledChecksValue) String() string {
4545
}
4646

4747
func (m enabledChecksValue) Set(s string) error {
48+
ss := strings.FieldsFunc(s, func(c rune) bool { return c == ',' })
49+
if len(ss) == 0 {
50+
return nil
51+
}
52+
4853
for k := range m {
4954
delete(m, k)
5055
}
51-
ss := strings.FieldsFunc(s, func(c rune) bool { return c == ',' })
5256
for _, v := range ss {
5357
switch v {
5458
case checkTBegin, checkTFirst, checkTName, checkBBegin, checkBFirst, checkBName:

pkg/analyzer/analyzer_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,24 @@ func TestAllChecks(t *testing.T) {
1717

1818
log.SetFlags(log.LstdFlags | log.Lshortfile)
1919
testdata := analysistest.TestData()
20-
analysistest.Run(t, testdata, analyzer.NewAnalyzer(), "t", "b")
20+
21+
t.Run("without check flag", func(t *testing.T) {
22+
t.Parallel()
23+
24+
a := analyzer.NewAnalyzer()
25+
analysistest.Run(t, testdata, a, "t", "b")
26+
})
27+
28+
t.Run("empty checks flag", func(t *testing.T) {
29+
t.Parallel()
30+
31+
a := analyzer.NewAnalyzer()
32+
err := a.Flags.Set("checks", "")
33+
if err != nil {
34+
t.Fatalf("failed to set checks empty value: %s", err.Error())
35+
}
36+
analysistest.Run(t, testdata, a, "t", "b")
37+
})
2138
}
2239

2340
//go:generate go run github.com/kulti/thelper/scripts/generator --name t --check begin --path testdata/src

0 commit comments

Comments
 (0)