summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-10-25 00:58:10 +0100
committerw0rp <devw0rp@gmail.com>2017-10-25 00:58:16 +0100
commit5029078df3d5d26d71d220d273a001a5aea9c416 (patch)
tree20aa774309874bf9e37e50fbe4e31d4c38aeb56a
parent94bdabb8c3c6445249c0e3bac5b7bcf159fd49f3 (diff)
downloadale-5029078df3d5d26d71d220d273a001a5aea9c416.zip
Set better highlights for write-good
-rw-r--r--autoload/ale/handlers/writegood.vim33
-rw-r--r--test/handler/test_write_good_handler.vader20
2 files changed, 40 insertions, 13 deletions
diff --git a/autoload/ale/handlers/writegood.vim b/autoload/ale/handlers/writegood.vim
index c26eb207..f9d452ea 100644
--- a/autoload/ale/handlers/writegood.vim
+++ b/autoload/ale/handlers/writegood.vim
@@ -31,19 +31,30 @@ function! ale#handlers#writegood#Handle(buffer, lines) abort
"
" "it is" is wordy or unneeded on line 20 at column 53
" "easily" can weaken meaning on line 154 at column 29
+ let l:marks_pattern = '\v^ *(\^+) *$'
let l:pattern = '\v^(".*"\s.*)\son\sline\s(\d+)\sat\scolumn\s(\d+)$'
let l:output = []
-
- for l:match in ale#util#GetMatches(a:lines, l:pattern)
- " Add the linter error. Note that we need to add 1 to the col because
- " write-good reports the column corresponding to the space before the
- " offending word or phrase.
- call add(l:output, {
- \ 'text': l:match[1],
- \ 'lnum': l:match[2] + 0,
- \ 'col': l:match[3] + 1,
- \ 'type': 'W',
- \})
+ let l:last_len = 0
+
+ for l:match in ale#util#GetMatches(a:lines, [l:marks_pattern, l:pattern])
+ if empty(l:match[2])
+ let l:last_len = len(l:match[1])
+ else
+ let l:col = l:match[3] + 1
+
+ " Add the linter error. Note that we need to add 1 to the col because
+ " write-good reports the column corresponding to the space before the
+ " offending word or phrase.
+ call add(l:output, {
+ \ 'text': l:match[1],
+ \ 'lnum': l:match[2] + 0,
+ \ 'col': l:col,
+ \ 'end_col': l:last_len ? (l:col + l:last_len - 1) : l:col,
+ \ 'type': 'W',
+ \})
+
+ let l:last_len = 0
+ endif
endfor
return l:output
diff --git a/test/handler/test_write_good_handler.vader b/test/handler/test_write_good_handler.vader
index b3eeb1b7..8bf4b223 100644
--- a/test/handler/test_write_good_handler.vader
+++ b/test/handler/test_write_good_handler.vader
@@ -4,9 +4,24 @@ Execute(The write-good handler should handle the example from the write-good REA
\ {
\ 'lnum': 1,
\ 'col': 1,
+ \ 'end_col': 2,
\ 'type': 'W',
\ 'text': '"So" adds no meaning',
- \ }
+ \ },
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 12,
+ \ 'end_col': 21,
+ \ 'type': 'W',
+ \ 'text': '"was stolen" may be passive voice',
+ \ },
+ \ {
+ \ 'lnum': 6,
+ \ 'col': 2,
+ \ 'end_col': 2,
+ \ 'type': 'W',
+ \ 'text': '"foo bar" bla',
+ \ },
\ ],
\ ale#handlers#writegood#Handle(bufnr(''), [
\ 'In /tmp/vBYivbZ/6/test.md',
@@ -17,5 +32,6 @@ Execute(The write-good handler should handle the example from the write-good REA
\ '-------------',
\ 'So the cat was stolen.',
\ ' ^^^^^^^^^^',
- \ '"was stolen" may be passive voice on line 1 at column 11 ',
+ \ '"was stolen" may be passive voice on line 1 at column 11',
+ \ '"foo bar" bla on line 6 at column 1',
\ ])