Skip to content

Commit

Permalink
fix: add implicit (?-i) flags
Browse files Browse the repository at this point in the history
See #727.
  • Loading branch information
jdkato committed Nov 16, 2023
1 parent 653a72b commit 5d15589
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/check/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ func updateExceptions(previous []string, current map[string]struct{}) (*regexp2.
return len(previous[p]) > len(previous[q])
})

// NOTE: We need to add `(?-i)` to each term that doesn't already have it,
// otherwise any instance of the `(?i)` flag will be set for the entire
// expression.
for i, term := range previous {
if !strings.HasPrefix(term, "(?i)") {
previous[i] = fmt.Sprintf("(?-i)%s", term)
}
}

regex := makeRegexp(
"",
false,
Expand Down
1 change: 1 addition & 0 deletions testdata/features/misc.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Misc
test.md:17:11:Vale.Terms:Use 'Log4j' instead of 'log4j'.
test.md:19:1:Vale.Terms:Use 'ABCDEF' instead of 'ABCDEf'.
test.md:21:1:Vale.Terms:Use 'ABC-DEF' instead of 'ABC-DEf'.
test.md:23:1:Vale.Terms:Use 'PLuG' instead of 'plug'.
"""

Scenario: Multiple Vocabs
Expand Down
6 changes: 5 additions & 1 deletion testdata/fixtures/vocab/Basic/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ I use the log4j library.

ABCDEf

ABC-DEf
ABC-DEf

plug

Github
2 changes: 2 additions & 0 deletions testdata/fixtures/vocab/styles/Vocab/Basic/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Documentarians
Log4j
ABCDEF
ABC-DEF
PLuG
(?i)GitHub

0 comments on commit 5d15589

Please sign in to comment.