]> git.madduck.net Git - etc/vim.git/blob - ale_linters/elixir/credo.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 / elixir / credo.vim
1 " Author: hauleth - https://github.com/hauleth
2
3 function! ale_linters#elixir#credo#Handle(buffer, lines) abort
4     " Matches patterns line the following:
5     "
6     " lib/filename.ex:19:7: F: Pipe chain should start with a raw value.
7     let l:pattern = '\v:(\d+):?(\d+)?: (.): (.+)$'
8     let l:output = []
9
10     for l:match in ale#util#GetMatches(a:lines, l:pattern)
11         let l:type = l:match[3]
12         let l:text = l:match[4]
13
14         " Refactoring opportunities
15         if l:type is# 'F'
16             let l:type = 'W'
17         " Consistency
18         elseif l:type is# 'C'
19             let l:type = 'W'
20         " Software Design
21         elseif l:type is# 'D'
22             let l:type = 'I'
23         " Code Readability
24         elseif l:type is# 'R'
25             let l:type = 'I'
26         endif
27
28         call add(l:output, {
29         \   'bufnr': a:buffer,
30         \   'lnum': l:match[1] + 0,
31         \   'col': l:match[2] + 0,
32         \   'type': l:type,
33         \   'text': l:text,
34         \})
35     endfor
36
37     return l:output
38 endfunction
39
40 function! ale_linters#elixir#credo#GetMode() abort
41     if get(g:, 'ale_elixir_credo_strict', 0)
42         return '--strict'
43     else
44         return 'suggest'
45     endif
46 endfunction
47
48 function! ale_linters#elixir#credo#GetConfigFile() abort
49     let l:config_file = get(g:, 'ale_elixir_credo_config_file', '')
50
51     if empty(l:config_file)
52         return ''
53     endif
54
55     return ' --config-file ' . l:config_file
56 endfunction
57
58 function! ale_linters#elixir#credo#GetCommand(buffer) abort
59     return 'mix help credo && '
60     \ . 'mix credo ' . ale_linters#elixir#credo#GetMode()
61     \ . ale_linters#elixir#credo#GetConfigFile()
62     \ . ' --format=flycheck --read-from-stdin %s'
63 endfunction
64
65 call ale#linter#Define('elixir', {
66 \   'name': 'credo',
67 \   'executable': 'mix',
68 \   'cwd': function('ale#handlers#elixir#FindMixUmbrellaRoot'),
69 \   'command': function('ale_linters#elixir#credo#GetCommand'),
70 \   'callback': 'ale_linters#elixir#credo#Handle',
71 \})