From e7268acc680e282496746bff466423aa0399d7ff Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Sun, 25 Aug 2024 00:31:29 -0700 Subject: [PATCH] fix: wrong message in cases with no index #877 --- internal/check/substitution.go | 8 ++++++++ testdata/features/checks.feature | 1 + testdata/fixtures/checks/Substitution/.vale.ini | 1 + testdata/fixtures/checks/Substitution/test2.md | 4 +++- testdata/styles/Bugs/WrongExp.yml | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 testdata/styles/Bugs/WrongExp.yml diff --git a/internal/check/substitution.go b/internal/check/substitution.go index 5098f6ce..e1aa0892 100644 --- a/internal/check/substitution.go +++ b/internal/check/substitution.go @@ -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 diff --git a/testdata/features/checks.feature b/testdata/features/checks.feature index 3f94d88c..93f3d30f 100755 --- a/testdata/features/checks.feature +++ b/testdata/features/checks.feature @@ -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 diff --git a/testdata/fixtures/checks/Substitution/.vale.ini b/testdata/fixtures/checks/Substitution/.vale.ini index 9dbd9988..353e0968 100644 --- a/testdata/fixtures/checks/Substitution/.vale.ini +++ b/testdata/fixtures/checks/Substitution/.vale.ini @@ -12,3 +12,4 @@ Bugs.SameCase = YES [test2.md] demo.CapSub = YES +Bugs.WrongExp = YES diff --git a/testdata/fixtures/checks/Substitution/test2.md b/testdata/fixtures/checks/Substitution/test2.md index 24913a5c..d85e2bd3 100644 --- a/testdata/fixtures/checks/Substitution/test2.md +++ b/testdata/fixtures/checks/Substitution/test2.md @@ -6,4 +6,6 @@ Within the home directory. Change into the `/home/user` directory. -Change into the `/etc/X11` directory. \ No newline at end of file +Change into the `/etc/X11` directory. + +Blue vs red. \ No newline at end of file diff --git a/testdata/styles/Bugs/WrongExp.yml b/testdata/styles/Bugs/WrongExp.yml new file mode 100644 index 00000000..c35d2cc3 --- /dev/null +++ b/testdata/styles/Bugs/WrongExp.yml @@ -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