File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -403,9 +403,18 @@ func (w *walker) advance(text string) int {
403403 pos := strings .Index (ctx , last )
404404 if pos < 0 {
405405 // Extraction rewrites text, so a line is not always a substring of the
406- // source; a single word from it usually still is.
407- if fields := strings .Fields (last ); len (fields ) > 0 {
408- pos = strings .Index (ctx , fields [len (fields )- 1 ])
406+ // source; a single word from it usually still is. The longest word,
407+ // though: the final one is as often a short `it.` that appears all
408+ // over the document, landing the block on someone else's line -- and
409+ // an alert placed by that line is an alert placed on the wrong text.
410+ longest := ""
411+ for _ , f := range strings .Fields (last ) {
412+ if len (f ) > len (longest ) {
413+ longest = f
414+ }
415+ }
416+ if longest != "" {
417+ pos = strings .Index (ctx , longest )
409418 }
410419 }
411420
Original file line number Diff line number Diff line change @@ -200,3 +200,34 @@ cases:
200200 test.md:3:32:T.Tok:'ZQX' in text
201201 test.md:5:6:T.Tok:'ZQX' in text
202202 test.md:5:18:T.Tok:'ZQX' in text
203+
204+ - name : styled-span-line
205+ about : a block located by a common final word (`it.`) landed on another
206+ line that happened to hold the same token, and the alert vanished into
207+ the dedup -- the block's longest word places it instead
208+ files :
209+ .vale.ini : |
210+ StylesPath = styles
211+ MinAlertLevel = suggestion
212+
213+ [*.md]
214+ T.Tok = YES
215+ styles/T/Tok.yml : |
216+ extends: existence
217+ message: "'%s' left in text"
218+ level: error
219+ nonword: true
220+ raw:
221+ - ZQX
222+ test.md : |
223+ A first paragraph in it.
224+
225+ See **bold prose with a ZQX in it** and *emphasis with a ZQX in it*.
226+
227+ - A list item with a ZQX in it.
228+ args : test.md
229+ exit : 1
230+ want : |
231+ test.md:3:25:T.Tok:'ZQX' left in text
232+ test.md:3:58:T.Tok:'ZQX' left in text
233+ test.md:5:22:T.Tok:'ZQX' left in text
You can’t perform that action at this time.
0 commit comments