]> git.madduck.net Git - etc/vim.git/blob - ale_linters/yaml/swaglint.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / yaml / swaglint.vim
1 " Author: Matthew Turland <https://github.com/elazar>
2 " Description: This file adds support for linting Swagger / OpenAPI documents using swaglint
3
4 call ale#Set('yaml_swaglint_executable', 'swaglint')
5 call ale#Set('yaml_swaglint_use_global', get(g:, 'ale_use_global_executables', 0))
6
7 function! ale_linters#yaml#swaglint#Handle(buffer, lines) abort
8     let l:pattern = ': \([^\s]\+\) @ \(\d\+\):\(\d\+\) - \(.\+\)$'
9     let l:output = []
10
11     for l:match in ale#util#GetMatches(a:lines, l:pattern)
12         let l:obj = {
13         \   'type': l:match[1] is# 'error' ? 'E' : 'W',
14         \   'lnum': l:match[2] + 0,
15         \   'col': l:match[3] + 0,
16         \   'text': l:match[4],
17         \}
18
19         " Parse the code if it's there.
20         let l:code_match = matchlist(l:obj.text, '\v^(.+) \(([^ (]+)\)$')
21
22         if !empty(l:code_match)
23             let l:obj.text = l:code_match[1]
24             let l:obj.code = l:code_match[2]
25         endif
26
27         call add(l:output, l:obj)
28     endfor
29
30     return l:output
31 endfunction
32
33 call ale#linter#Define('yaml', {
34 \   'name': 'swaglint',
35 \   'executable': {b -> ale#path#FindExecutable(b, 'yaml_swaglint', [
36 \       'node_modules/.bin/swaglint',
37 \   ])},
38 \   'command': '%e -r compact --stdin',
39 \   'callback': 'ale_linters#yaml#swaglint#Handle',
40 \})