Skip to content

Commit

Permalink
ruleset: export RegexpListItem.Exclude
Browse files Browse the repository at this point in the history
This allows to have other parsing mechanisms and still use NewRegexpMatcherFromList().
  • Loading branch information
mmatczuk committed Dec 20, 2023
1 parent e63db25 commit 7fc8ae9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ruleset/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *RegexpMatcher) match(s string) bool {

type RegexpListItem struct {
*regexp.Regexp
exclude bool
Exclude bool
}

func ParseRegexpListItem(val string) (RegexpListItem, error) {
Expand All @@ -87,7 +87,7 @@ func ParseRegexpListItem(val string) (RegexpListItem, error) {
}

func (r RegexpListItem) String() string {
if r.exclude {
if r.Exclude {
return "-" + r.Regexp.String()
}
return r.Regexp.String()
Expand All @@ -96,7 +96,7 @@ func (r RegexpListItem) String() string {
func NewRegexpMatcherFromList(l []RegexpListItem) (*RegexpMatcher, error) {
var include, exclude []*regexp.Regexp
for i := range l {
if l[i].exclude {
if l[i].Exclude {
exclude = append(exclude, l[i].Regexp)
} else {
include = append(include, l[i].Regexp)
Expand Down
6 changes: 3 additions & 3 deletions ruleset/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestParseRegexpListItem(t *testing.T) {
input: "-foo",
expected: RegexpListItem{
Regexp: regexp.MustCompile("foo"),
exclude: true,
Exclude: true,
},
},
}
Expand All @@ -160,8 +160,8 @@ func TestParseRegexpListItem(t *testing.T) {
if r.Regexp.String() != tc.expected.Regexp.String() {
t.Errorf("expected regexp %q, got %q", tc.expected.Regexp.String(), r.Regexp.String())
}
if r.exclude != tc.expected.exclude {
t.Errorf("expected exclude %v, got %v", tc.expected.exclude, r.exclude)
if r.Exclude != tc.expected.Exclude {
t.Errorf("expected exclude %v, got %v", tc.expected.Exclude, r.Exclude)
}
})
}
Expand Down

0 comments on commit 7fc8ae9

Please sign in to comment.