Skip to content

Commit

Permalink
Support multiple prefixes to group them together and/or a regex daixi…
Browse files Browse the repository at this point in the history
…ang0#107

Signed-off-by: Author Name <luw2007@gmail.com>
  • Loading branch information
luw2007 committed Jan 16, 2023
1 parent 33a14c3 commit 8db20a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/section/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func TestParse(t *testing.T) {
expectedSection: nil,
expectedError: errors.New("invalid params: prefix("),
},
{
input: []string{"prefix(domainA;domainB)"},
expectedSection: SectionList{Custom{"domainA;domainB"}},
expectedError: nil,
},
}
for _, test := range testCases {
parsedSection, err := Parse(test.input)
Expand Down
7 changes: 5 additions & 2 deletions pkg/section/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ type Custom struct {
const CustomType = "custom"

func (c Custom) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity {
if strings.HasPrefix(spec.Path, c.Prefix) {
return specificity.Match{Length: len(c.Prefix)}
for _, prefix := range strings.Split(c.Prefix, ";") {
if strings.HasPrefix(spec.Path, prefix) {
return specificity.Match{Length: len(prefix)}
}
}

return specificity.MisMatch{}
}

Expand Down

0 comments on commit 8db20a1

Please sign in to comment.