diff options
author | Sumner Evans <sumner.evans98@gmail.com> | 2017-10-25 00:27:40 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-10-25 00:28:06 +0100 |
commit | 7ac07a30b8c54dd44da403830d4ed84992d18656 (patch) | |
tree | 4a69129eb8f72370cbb62cbce7b75648b3ecafad /autoload | |
parent | 1a5ef969a528c037b865828dedcd482a51d0e004 (diff) | |
download | ale-7ac07a30b8c54dd44da403830d4ed84992d18656.zip |
Fix #643 - Add support for write-good for many languages
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/handlers/writegood.vim | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/autoload/ale/handlers/writegood.vim b/autoload/ale/handlers/writegood.vim new file mode 100644 index 00000000..c26eb207 --- /dev/null +++ b/autoload/ale/handlers/writegood.vim @@ -0,0 +1,50 @@ +" Author: Sumner Evans <sumner.evans98@gmail.com> +" Description: Error handling for errors in the write-good format. + +function! ale#handlers#writegood#ResetOptions() abort + call ale#Set('writegood_options', '') + call ale#Set('writegood_executable', 'write-good') + call ale#Set('writegood_use_global', 0) +endfunction + +" Reset the options so the tests can test how they are set. +call ale#handlers#writegood#ResetOptions() + +function! ale#handlers#writegood#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'writegood', [ + \ 'node_modules/.bin/write-good', + \ 'node_modules/write-good/bin/write-good.js', + \]) +endfunction + +function! ale#handlers#writegood#GetCommand(buffer) abort + let l:executable = ale#handlers#writegood#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'writegood_options') + + return ale#node#Executable(a:buffer, l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' %t' +endfunction + +function! ale#handlers#writegood#Handle(buffer, lines) abort + " Look for lines like the following. + " + " "it is" is wordy or unneeded on line 20 at column 53 + " "easily" can weaken meaning on line 154 at column 29 + 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', + \}) + endfor + + return l:output +endfunction |