]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/ruby/brakeman.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 '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / ale_linters / ruby / brakeman.vim
1 " Author: Eddie Lebow https://github.com/elebow
2 " Description: Brakeman, a static analyzer for Rails security
3
4 call ale#Set('ruby_brakeman_options', '')
5 call ale#Set('ruby_brakeman_executable', 'brakeman')
6 call ale#Set('ruby_brakeman_options', '')
7
8 function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
9     let l:output = []
10     let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
11     let l:sep = has('win32') ? '\' : '/'
12     " Brakeman always outputs paths relative to the Rails app root
13     let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
14
15     for l:warning in get(l:json, 'warnings', [])
16         let l:text = l:warning.warning_type . ' ' . l:warning.message . ' (' . l:warning.confidence . ')'
17         let l:line = l:warning.line != v:null ? l:warning.line : 1
18
19         call add(l:output, {
20         \   'filename': l:rails_root . l:sep .  l:warning.file,
21         \   'lnum': l:line,
22         \   'type': 'W',
23         \   'text': l:text,
24         \})
25     endfor
26
27     return l:output
28 endfunction
29
30 function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
31     let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
32
33     if l:rails_root is? ''
34         return ''
35     endif
36
37     let l:executable = ale#Var(a:buffer, 'ruby_brakeman_executable')
38
39     return ale#ruby#EscapeExecutable(l:executable, 'brakeman')
40     \    . ' -f json -q '
41     \    . ale#Var(a:buffer, 'ruby_brakeman_options')
42     \    . ' -p ' . ale#Escape(l:rails_root)
43 endfunction
44
45 call ale#linter#Define('ruby', {
46 \    'name': 'brakeman',
47 \    'executable': {b -> ale#Var(b, 'ruby_brakeman_executable')},
48 \    'command': function('ale_linters#ruby#brakeman#GetCommand'),
49 \    'callback': 'ale_linters#ruby#brakeman#Handle',
50 \    'lint_file': 1,
51 \})