All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Sumner Evans <sumner.evans98@gmail.com>
2 " Description: Error handling for errors in the write-good format.
4 function! ale#handlers#writegood#ResetOptions() abort
5 call ale#Set('writegood_options', '')
6 call ale#Set('writegood_executable', 'write-good')
7 call ale#Set('writegood_use_global', get(g:, 'ale_use_global_executables', 0))
10 " Reset the options so the tests can test how they are set.
11 call ale#handlers#writegood#ResetOptions()
13 function! ale#handlers#writegood#GetExecutable(buffer) abort
14 return ale#path#FindExecutable(a:buffer, 'writegood', [
15 \ 'node_modules/.bin/write-good',
16 \ 'node_modules/write-good/bin/write-good.js',
20 function! ale#handlers#writegood#GetCommand(buffer) abort
21 let l:executable = ale#handlers#writegood#GetExecutable(a:buffer)
22 let l:options = ale#Var(a:buffer, 'writegood_options')
24 return ale#node#Executable(a:buffer, l:executable)
25 \ . (!empty(l:options) ? ' ' . l:options : '')
29 function! ale#handlers#writegood#Handle(buffer, lines) abort
30 " Look for lines like the following.
32 " "it is" is wordy or unneeded on line 20 at column 53
33 " "easily" can weaken meaning on line 154 at column 29
34 let l:marks_pattern = '\v^ *(\^+) *$'
35 let l:pattern = '\v^(".*"\s.*)\son\sline\s(\d+)\sat\scolumn\s(\d+)$'
39 for l:match in ale#util#GetMatches(a:lines, [l:marks_pattern, l:pattern])
41 let l:last_len = len(l:match[1])
43 let l:col = l:match[3] + 1
45 " Add the linter error. Note that we need to add 1 to the col because
46 " write-good reports the column corresponding to the space before the
47 " offending word or phrase.
50 \ 'lnum': l:match[2] + 0,
52 \ 'end_col': l:last_len ? (l:col + l:last_len - 1) : l:col,
63 " Define the writegood linter for a given filetype.
64 function! ale#handlers#writegood#DefineLinter(filetype) abort
65 call ale#linter#Define(a:filetype, {
66 \ 'name': 'writegood',
67 \ 'aliases': ['write-good'],
68 \ 'executable': function('ale#handlers#writegood#GetExecutable'),
69 \ 'command': function('ale#handlers#writegood#GetCommand'),
70 \ 'callback': 'ale#handlers#writegood#Handle',