]> git.madduck.net Git - etc/vim.git/blob - ale_linters/json/jsonlint.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 / json / jsonlint.vim
1 " Author: KabbAmine <amine.kabb@gmail.com>, David Sierra <https://github.com/davidsierradz>
2
3 call ale#Set('json_jsonlint_executable', 'jsonlint')
4 call ale#Set('json_jsonlint_use_global', get(g:, 'ale_use_global_executables', 0))
5
6 function! ale_linters#json#jsonlint#GetExecutable(buffer) abort
7     return ale#path#FindExecutable(a:buffer, 'json_jsonlint', [
8     \   'node_modules/.bin/jsonlint',
9     \   'node_modules/jsonlint/lib/cli.js',
10     \])
11 endfunction
12
13 function! ale_linters#json#jsonlint#GetCommand(buffer) abort
14     let l:executable = ale_linters#json#jsonlint#GetExecutable(a:buffer)
15
16     return ale#node#Executable(a:buffer, l:executable)
17     \   . ' --compact -'
18 endfunction
19
20 function! ale_linters#json#jsonlint#Handle(buffer, lines) abort
21     " Matches patterns like the following:
22     " line 2, col 15, found: 'STRING' - expected: 'EOF', '}', ',', ']'.
23     let l:pattern = '^line \(\d\+\), col \(\d*\), \(.\+\)$'
24     let l:output = []
25
26     for l:match in ale#util#GetMatches(a:lines, l:pattern)
27         call add(l:output, {
28         \   'lnum': l:match[1] + 0,
29         \   'col': l:match[2] + 0,
30         \   'text': l:match[3],
31         \})
32     endfor
33
34     return l:output
35 endfunction
36
37 call ale#linter#Define('json', {
38 \   'name': 'jsonlint',
39 \   'executable': function('ale_linters#json#jsonlint#GetExecutable'),
40 \   'output_stream': 'stderr',
41 \   'command': function('ale_linters#json#jsonlint#GetCommand'),
42 \   'callback': 'ale_linters#json#jsonlint#Handle',
43 \})