]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/ruby/reek.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:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / ruby / reek.vim
1 " Author: Eddie Lebow https://github.com/elebow
2 " Description: Reek, a code smell detector for Ruby files
3
4 call ale#Set('ruby_reek_show_context', 0)
5 call ale#Set('ruby_reek_show_wiki_link', 0)
6 call ale#Set('ruby_reek_options', '')
7 call ale#Set('ruby_reek_executable', 'reek')
8
9 function! ale_linters#ruby#reek#GetCommand(buffer, version) abort
10     let l:executable = ale#Var(a:buffer, 'ruby_reek_executable')
11
12     " Tell reek what the filename is if the version of reek is new enough.
13     let l:display_name_args = ale#semver#GTE(a:version, [5, 0, 0])
14     \   ? ' --stdin-filename %s'
15     \   : ''
16
17     return ale#ruby#EscapeExecutable(l:executable, 'reek')
18     \   . ' -f json --no-progress --no-color --force-exclusion'
19     \   . l:display_name_args
20 endfunction
21
22 function! s:GetDocumentationLink(error) abort
23     return get(a:error, 'documentation_link', get(a:error, 'wiki_link', ''))
24 endfunction
25
26 function! s:BuildText(buffer, error) abort
27     let l:parts = []
28
29     if ale#Var(a:buffer, 'ruby_reek_show_context')
30         call add(l:parts, a:error.context)
31     endif
32
33     call add(l:parts, a:error.message)
34
35     if ale#Var(a:buffer, 'ruby_reek_show_wiki_link')
36         call add(l:parts, '[' . s:GetDocumentationLink(a:error) . ']')
37     endif
38
39     return join(l:parts, ' ')
40 endfunction
41
42 function! ale_linters#ruby#reek#Handle(buffer, lines) abort
43     let l:output = []
44
45     for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
46         for l:location in l:error.lines
47             call add(l:output, {
48             \    'lnum': l:location,
49             \    'type': 'W',
50             \    'text': s:BuildText(a:buffer, l:error),
51             \    'code': l:error.smell_type,
52             \})
53         endfor
54     endfor
55
56     return l:output
57 endfunction
58
59 call ale#linter#Define('ruby', {
60 \   'name': 'reek',
61 \   'executable': {b -> ale#Var(b, 'ruby_reek_executable')},
62 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
63 \       buffer,
64 \       ale#Var(buffer, 'ruby_reek_executable'),
65 \       '%e --version',
66 \       function('ale_linters#ruby#reek#GetCommand'),
67 \   )},
68 \    'callback': 'ale_linters#ruby#reek#Handle',
69 \})