]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/crystal/ameba.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 / crystal / ameba.vim
1 " Author: Harrison Bachrach - https://github.com/HarrisonB
2 " Description: Ameba, a linter for crystal files
3
4 call ale#Set('crystal_ameba_executable', 'bin/ameba')
5
6 function! ale_linters#crystal#ameba#GetCommand(buffer) abort
7     let l:executable = ale#Var(a:buffer, 'crystal_ameba_executable')
8
9     return ale#Escape(l:executable)
10     \   . ' --format json '
11     \   .  ale#Escape(expand('#' . a:buffer . ':p'))
12 endfunction
13
14 " Handle output from ameba
15 function! ale_linters#crystal#ameba#HandleAmebaOutput(buffer, lines) abort
16     if len(a:lines) == 0
17         return []
18     endif
19
20     let l:errors = ale#util#FuzzyJSONDecode(a:lines[0], {})
21
22     if !has_key(l:errors, 'summary')
23     \|| l:errors['summary']['issues_count'] == 0
24     \|| empty(l:errors['sources'])
25         return []
26     endif
27
28     let l:output = []
29
30     for l:error in l:errors['sources'][0]['issues']
31         let l:start_col = str2nr(l:error['location']['column'])
32         let l:end_col = str2nr(l:error['end_location']['column'])
33
34         if !l:end_col
35             let l:end_col = l:start_col + 1
36         endif
37
38         call add(l:output, {
39         \   'lnum': str2nr(l:error['location']['line']),
40         \   'col': l:start_col,
41         \   'end_col': l:end_col,
42         \   'code': l:error['rule_name'],
43         \   'text': l:error['message'],
44         \   'type': 'W',
45         \})
46     endfor
47
48     return l:output
49 endfunction
50
51 call ale#linter#Define('crystal', {
52 \   'name': 'ameba',
53 \   'executable': {b -> ale#Var(b, 'crystal_ameba_executable')},
54 \   'command': function('ale_linters#crystal#ameba#GetCommand'),
55 \   'callback': 'ale_linters#crystal#ameba#HandleAmebaOutput',
56 \   'lint_file': 1,
57 \})