Skip to content

Commit

Permalink
fix: wrong message in cases with no index
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Aug 25, 2024
1 parent 2348d3a commit e7268ac
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/check/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func subMsg(s Substitution, index int, observed string) (string, error) {
expected = core.CapFirst(expected)
}

// TODO: Why do we need to check for this?
//
// This feels like a bug in `regexp2`.
hasIndex := regexp2.MustCompileStd(`\$\d+`)
if !hasIndex.MatchStringStd(expected) {
return expected, nil
}

msg := s.msgMap[index]
if s.Ignorecase {
msg = `(?i)` + msg
Expand Down
1 change: 1 addition & 0 deletions testdata/features/checks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Feature: Checks
test2.md:3:1:demo.CapSub:Use 'Change to the `/etc` directory' instead of 'Change into the `/etc` directory'.
test2.md:7:1:demo.CapSub:Use 'Change to the `/home/user` directory' instead of 'Change into the `/home/user` directory'.
test2.md:9:1:demo.CapSub:Use 'Change to the `/etc/X11` directory' instead of 'Change into the `/etc/X11` directory'.
test2.md:11:6:Bugs.WrongExp:Use 'versus' instead of 'vs'.
"""

Scenario: Sequence
Expand Down
1 change: 1 addition & 0 deletions testdata/fixtures/checks/Substitution/.vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Bugs.SameCase = YES

[test2.md]
demo.CapSub = YES
Bugs.WrongExp = YES
4 changes: 3 additions & 1 deletion testdata/fixtures/checks/Substitution/test2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Within the home directory.

Change into the `/home/user` directory.

Change into the `/etc/X11` directory.
Change into the `/etc/X11` directory.

Blue vs red.
14 changes: 14 additions & 0 deletions testdata/styles/Bugs/WrongExp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
extends: substitution
message: "Use '%s' instead of '%s'."
ignorecase: false
level: error
nonword: true
action:
name: replace
swap:
'\b(?:[Ee]\.[Gg]\.)': for example
'\b(?:[Ii]\.[Ee]\.)': that is
'\b(?:[Ee][Tt][Cc]\.)': and so on
'\b(?:[Vv][Ss]\.)': versus
'\b(?:[Vv][Ss]\s)(?!Code)': versus

0 comments on commit e7268ac

Please sign in to comment.