summaryrefslogtreecommitdiff
path: root/ale_linters/ruby/rails_best_practices.vim
blob: 20cadca807e25bb4800ab58f89d2959e1cb91739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
" Author: Eddie Lebow https://github.com/elebow
" Description: rails_best_practices, a code metric tool for rails projects

call ale#Set('ruby_rails_best_practices_options', '')
call ale#Set('ruby_rails_best_practices_executable', 'rails_best_practices')

function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
    let l:output = []

    for l:warning in ale#util#FuzzyJSONDecode(a:lines, [])
        if !ale#path#IsBufferPath(a:buffer, l:warning.filename)
            continue
        endif

        call add(l:output, {
        \    'lnum': l:warning.line_number + 0,
        \    'type': 'W',
        \    'text': l:warning.message,
        \})
    endfor

    return l:output
endfunction

function! ale_linters#ruby#rails_best_practices#GetCommand(buffer) abort
    let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)

    if l:rails_root is? ''
        return ''
    endif

    let l:executable = ale#Var(a:buffer, 'ruby_rails_best_practices_executable')
    let l:output_file = ale#Has('win32') ? '%t ' : '/dev/stdout '
    let l:cat_file = ale#Has('win32') ? '; type %t' : ''

    return ale#handlers#ruby#EscapeExecutable(l:executable, 'rails_best_practices')
    \    . ' --silent -f json --output-file ' . l:output_file
    \    . ale#Var(a:buffer, 'ruby_rails_best_practices_options')
    \    . ale#Escape(l:rails_root)
    \    . l:cat_file
endfunction

call ale#linter#Define('ruby', {
\    'name': 'rails_best_practices',
\    'executable_callback': ale#VarFunc('ruby_rails_best_practices_executable'),
\    'command_callback': 'ale_linters#ruby#rails_best_practices#GetCommand',
\    'callback': 'ale_linters#ruby#rails_best_practices#Handle',
\    'lint_file': 1,
\})