diff --git a/internal/core/file.go b/internal/core/file.go index 2e426405..3e8203a3 100755 --- a/internal/core/file.go +++ b/internal/core/file.go @@ -202,7 +202,13 @@ 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 idx == blk.Line { + // 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. + // + // At the very least, this change includes a representative test case + // and a temporary fix. + exact := len(l) > loc[1] && l[loc[0]:loc[1]] == a.Match + if exact || idx == blk.Line { length := utf8.RuneCountInString(l) pos, substring := initialPosition(l, blk.Text, a) @@ -216,7 +222,7 @@ func (f *File) assignLoc(ctx string, blk nlp.Block, pad int, a Alert) (int, []in loc[1] = 1 } - return blk.Line + 1, loc + return idx + 1, loc } } return blk.Line + 1, a.Span diff --git a/testdata/features/checks.feature b/testdata/features/checks.feature index 775d9e1a..49f96b46 100755 --- a/testdata/features/checks.feature +++ b/testdata/features/checks.feature @@ -79,6 +79,7 @@ Feature: Checks """ test.md:5:5:Bugs.Newline:Use 'test' rather than 'linuxptp'. test.md:8:5:Bugs.Newline:Use 'test' rather than 'linuxptp'. + test.md:10:1:Bugs.URLCtx:Use 'Term' instead of 'term' """ Scenario: Sequence diff --git a/testdata/fixtures/checks/Substitution/.vale.ini b/testdata/fixtures/checks/Substitution/.vale.ini index c485b085..c721e17d 100644 --- a/testdata/fixtures/checks/Substitution/.vale.ini +++ b/testdata/fixtures/checks/Substitution/.vale.ini @@ -6,3 +6,4 @@ Vocab = Cap BasedOnStyles = proselint Bugs.Newline = YES +Bugs.URLCtx = YES diff --git a/testdata/fixtures/checks/Substitution/test.md b/testdata/fixtures/checks/Substitution/test.md index d3ab043c..2b2ede15 100644 --- a/testdata/fixtures/checks/Substitution/test.md +++ b/testdata/fixtures/checks/Substitution/test.md @@ -5,4 +5,9 @@ The congressman voted to pass the bill. The linuxptp resource. The `linuxptp` resource. -The linuxptp resource. \ No newline at end of file +The linuxptp resource. + +term +https://abc.com/term + +https://abc.com/term \ No newline at end of file diff --git a/testdata/styles/Bugs/URLCtx.yml b/testdata/styles/Bugs/URLCtx.yml new file mode 100644 index 00000000..5a3f3415 --- /dev/null +++ b/testdata/styles/Bugs/URLCtx.yml @@ -0,0 +1,5 @@ +extends: substitution +message: Use '%s' instead of '%s' +level: error +swap: + "term": Term