]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/ruby/rails_best_practices.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 '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / ruby / rails_best_practices.vim
1 " Author: Eddie Lebow https://github.com/elebow
2 " Description: rails_best_practices, a code metric tool for rails projects
3
4 call ale#Set('ruby_rails_best_practices_options', '')
5 call ale#Set('ruby_rails_best_practices_executable', 'rails_best_practices')
6
7 function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
8     let l:output = []
9
10     for l:warning in ale#util#FuzzyJSONDecode(a:lines, [])
11         if !ale#path#IsBufferPath(a:buffer, l:warning.filename)
12             continue
13         endif
14
15         call add(l:output, {
16         \    'lnum': l:warning.line_number + 0,
17         \    'type': 'W',
18         \    'text': l:warning.message,
19         \})
20     endfor
21
22     return l:output
23 endfunction
24
25 function! ale_linters#ruby#rails_best_practices#GetCommand(buffer) abort
26     let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
27
28     if l:rails_root is? ''
29         return ''
30     endif
31
32     let l:executable = ale#Var(a:buffer, 'ruby_rails_best_practices_executable')
33     let l:output_file = has('win32') ? '%t ' : '/dev/stdout '
34     let l:cat_file = has('win32') ? '; type %t' : ''
35
36     return ale#ruby#EscapeExecutable(l:executable, 'rails_best_practices')
37     \    . ' --silent -f json --output-file ' . l:output_file
38     \    . ale#Var(a:buffer, 'ruby_rails_best_practices_options')
39     \    . ale#Escape(l:rails_root)
40     \    . l:cat_file
41 endfunction
42
43 call ale#linter#Define('ruby', {
44 \    'name': 'rails_best_practices',
45 \    'executable': {b -> ale#Var(b, 'ruby_rails_best_practices_executable')},
46 \    'command': function('ale_linters#ruby#rails_best_practices#GetCommand'),
47 \    'callback': 'ale_linters#ruby#rails_best_practices#Handle',
48 \    'lint_file': 1,
49 \})