Skip to content

Commit

Permalink
fix: workaround blk.Line inconsistency
Browse files Browse the repository at this point in the history
Fixes #473.
  • Loading branch information
jdkato committed Sep 7, 2023
1 parent 61ddbe8 commit 4e2c064
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions testdata/features/checks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -6,3 +6,4 @@ Vocab = Cap
BasedOnStyles = proselint

Bugs.Newline = YES
Bugs.URLCtx = YES
7 changes: 6 additions & 1 deletion testdata/fixtures/checks/Substitution/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ The congressman voted to pass the bill.
The linuxptp resource.

The `linuxptp` resource.
The linuxptp resource.
The linuxptp resource.

term
https://abc.com/term

https://abc.com/term
5 changes: 5 additions & 0 deletions testdata/styles/Bugs/URLCtx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends: substitution
message: Use '%s' instead of '%s'
level: error
swap:
"term": Term

0 comments on commit 4e2c064

Please sign in to comment.