Skip to content

Commit e86418d

Browse files
committed
fix: filtering bugs
Use value from correct .Only config field when constructing filter for including symbol types, instead of .Exclude field value. Make symbol type filters return true for struct fields except for FilterUnexported.
1 parent 1176a1e commit e86418d

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

filter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func (f *filterSymbolTypes) Include(s Symbol) bool {
150150
return true
151151
}
152152

153+
if s.SymbolType() == SymbolStructField {
154+
return true
155+
}
156+
153157
_, ok := f.stMap[s.SymbolType()]
154158

155159
if f.action == Include {
@@ -187,6 +191,10 @@ func (f *filterMatchingIdents) Include(s Symbol) bool {
187191
return true
188192
}
189193

194+
if s.SymbolType() == SymbolStructField {
195+
return true
196+
}
197+
190198
match := f.pattern.MatchString(s.Ident())
191199

192200
if f.action == Include {

filter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var symbolTypes = []pkgdmp.SymbolType{
2020
pkgdmp.SymbolChanType,
2121
pkgdmp.SymbolArrayType,
2222
pkgdmp.SymbolFunc,
23+
pkgdmp.SymbolMethod,
2324
pkgdmp.SymbolStructField,
2425
}
2526

@@ -72,6 +73,7 @@ func TestFilterSymbolTypes(t *testing.T) {
7273
newSymbol(t, "myChan", pkgdmp.SymbolChanType),
7374
newSymbol(t, "MyArray", pkgdmp.SymbolArrayType),
7475
newSymbol(t, "MyFunc", pkgdmp.SymbolFunc),
76+
newSymbol(t, "MyMethod", pkgdmp.SymbolMethod),
7577
}
7678

7779
t.Run("returns true when all symbol types are included", func(t *testing.T) {

internal/cli/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func filtersFromCfg(cfg *Config) ([]pkgdmp.SymbolFilter, error) {
149149
}
150150

151151
if cfg.Only != "" {
152-
st, err := strToSymbolTypes(cfg.Exclude)
152+
st, err := strToSymbolTypes(cfg.Only)
153153
if err != nil {
154154
return nil, fmt.Errorf("parsing symbol types: %w", err)
155155
}

internal/cli/flags_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func TestParseFlags(t *testing.T) {
4444
},
4545
{
4646
name: "flags and directories",
47-
args: []string{"-unexported", "-no-docs", "-exclude=interfaces", "directory1", "directory2"},
47+
args: []string{"-unexported", "-no-docs", "-exclude=interface", "directory1", "directory2"},
4848
wantCfg: &cli.Config{
4949
Unexported: true,
5050
NoDocs: true,
51-
Exclude: "interfaces",
51+
Exclude: "interface",
5252
Dirs: []string{"directory1", "directory2"},
5353
Theme: "swapoff",
5454
},

0 commit comments

Comments
 (0)