From ea31d7d6cb982aaec5e57368d68ffba4ef06aca8 Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Wed, 25 Sep 2024 06:00:23 -0700 Subject: [PATCH] fix: ensure `skip` dimensions are valid --- internal/core/file.go | 3 +++ testdata/fixtures/checks/Sequence/.vale.ini | 1 + testdata/styles/LanguageTool/AMBIG.yml | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100644 testdata/styles/LanguageTool/AMBIG.yml diff --git a/internal/core/file.go b/internal/core/file.go index e40109f4..aa6d7738 100755 --- a/internal/core/file.go +++ b/internal/core/file.go @@ -225,6 +225,9 @@ func (f *File) FindLoc(ctx, s string, pad, count int, a Alert) (int, []int) { func (f *File) assignLoc(ctx string, blk nlp.Block, pad int, a Alert) (int, []int) { loc := a.Span for idx, l := range strings.SplitAfter(ctx, "\n") { + if loc[0] < 0 || loc[1] < 0 { + continue + } // NOTE: This fixes #473, but the real issue is that `blk.Line` is // wrong. This seems related to `location.go#41`, but I'm not sure. // diff --git a/testdata/fixtures/checks/Sequence/.vale.ini b/testdata/fixtures/checks/Sequence/.vale.ini index 13ef14c5..8d137128 100644 --- a/testdata/fixtures/checks/Sequence/.vale.ini +++ b/testdata/fixtures/checks/Sequence/.vale.ini @@ -6,3 +6,4 @@ LanguageTool.OF_ALL_TIMES = YES LanguageTool.APOS_ARE = YES LanguageTool.Metadata = YES LanguageTool.ARE_USING = YES +LanguageTool.AMBIG = YES diff --git a/testdata/styles/LanguageTool/AMBIG.yml b/testdata/styles/LanguageTool/AMBIG.yml new file mode 100644 index 00000000..75993ff1 --- /dev/null +++ b/testdata/styles/LanguageTool/AMBIG.yml @@ -0,0 +1,10 @@ +--- +extends: sequence +message: "Avoid ambiguous pronouns" +level: warning +ignorecase: true +tokens: + - tag: NN|NNP|NNPS|NNS + skip: 7 + - tag: PRP|PRP$ + pattern: he|she|its?|they|his|her|their