Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/lint/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,22 @@ func (w *walker) mapRun(at int, raw string) {
return
}

// A run that wraps inside a list item or blockquote has the item's
// indentation or `>` after each line break in the source, which raw does
// not. Searching for raw as written misses it, or finds a copy further
// down and drags the cursor past every run after it, leaving each of
// their alerts to be placed by searching the file. See #1227.
if strings.Contains(raw, "\n") {
if runs, end := wrappedRuns(raw, ctx, w.srcCursor); runs != nil {
for _, r := range runs {
r.At += at
w.spans = append(w.spans, r)
}
w.srcCursor = end
return
}
}

i := strings.Index(ctx[w.srcCursor:], raw)
if i < 0 {
w.mapWords(at, raw, ctx)
Expand Down
23 changes: 23 additions & 0 deletions internal/lint/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ func TestWrappedRuns(t *testing.T) {
}
}

// A run that wraps inside a list item is mapped where it is, not to a later
// copy outside the item, and the cursor stops there. See #1227.
func TestMapRunWrapped(t *testing.T) {
ctx := "- Hello there. This is some text,\n and this is some more.\n\nMore text, unrelated,\nand yet more.\n"
raw := ",\nand"

w := &walker{context: []byte(ctx)}
w.mapRun(5, raw)

want := []nlp.Run{{At: 5, Src: 32, N: 1}, {At: 7, Src: 36, N: 3}}
if !reflect.DeepEqual(w.spans, want) {
t.Fatalf("spans = %v, want %v", w.spans, want)
}
if w.srcCursor != 39 {
t.Errorf("srcCursor = %d, want 39", w.srcCursor)
}

w.mapRun(0, "More text")
if w.spans[len(w.spans)-1].Src != 60 {
t.Errorf("the run after the list item was placed at %d, want 60", w.spans[len(w.spans)-1].Src)
}
}

// A run the converter rewrote is mapped by its words, so a match in it is
// placed where the word is rather than wherever the text first appears.
func TestMapWords(t *testing.T) {
Expand Down
Loading