]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/hurl/hurlfmt.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / hurl / hurlfmt.vim
1 " Description: Hurl linter using hurlfmt --check.
2 " https://hurl.dev/
3
4 call ale#Set('hurl_hurlfmt_executable', 'hurlfmt')
5
6 function! ale_linters#hurl#hurlfmt#GetCommand(buffer) abort
7     return '%e'
8     \   . ' --check --no-color '
9 endfunction
10
11 function! ale_linters#hurl#hurlfmt#HandleOutput(buffer, lines) abort
12     " Matches patterns:
13     "
14     " error: Parsing space
15     " --> test.hurl:11:48
16     " |
17     " 8   | header "Content-Type"= "application/json; charset=utf-8"
18     " |                      ^ expecting a space
19     " |
20     "
21     " error: Parsing URL
22     " --> test.hurl:11:48
23     " |
24     " 11  | PUT https://jsonplaceholder.typicode.com/posts/{post_id}}
25     " |                                                ^ illegal character <{>
26     " |
27     "
28     " Note: hurlfmt seems to report always the first error only so we assume
29     " there is only one error to make parsing easier.
30     let l:output = []
31
32     if empty(a:lines)
33         return l:output
34     endif
35
36     let l:pattern = '\v(error|warning): (.+) --\> (.+):(\d+):(\d+) .+ \^ (.+) |'
37     let l:lines = join(a:lines, ' ')
38
39     for l:match in ale#util#GetMatches(l:lines, l:pattern)
40         call add(l:output, {
41         \ 'bufnr': a:buffer,
42         \ 'lnum': match[4] + 0,
43         \ 'col': match[5] + 0,
44         \ 'end_col': match[5] + 0,
45         \ 'text': match[2] . ' : ' . match[6],
46         \ 'type': (match[1] is# 'error') ? 'E' : 'W'
47         \})
48     endfor
49
50     return l:output
51 endfunction
52
53 function! ale_linters#hurl#hurlfmt#GetType(severity) abort
54     if a:severity is? 'convention'
55     \|| a:severity is? 'warning'
56     \|| a:severity is? 'refactor'
57         return 'W'
58     endif
59
60     return 'E'
61 endfunction
62
63 call ale#linter#Define('hurl', {
64 \   'name': 'hurlfmt',
65 \   'output_stream': 'stderr',
66 \   'executable': {b -> ale#Var(b, 'hurl_hurlfmt_executable')},
67 \   'command': function('ale_linters#hurl#hurlfmt#GetCommand'),
68 \   'callback': 'ale_linters#hurl#hurlfmt#HandleOutput',
69 \})