2017-05-05 09:05:53 +00:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: Brakeman, a static analyzer for Rails security
|
|
|
|
|
|
|
|
let g:ale_ruby_brakeman_options =
|
|
|
|
\ get(g:, 'ale_ruby_brakeman_options', '')
|
|
|
|
|
|
|
|
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
2017-07-01 14:18:21 +00:00
|
|
|
if len(a:lines) == 0
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
2017-05-05 09:05:53 +00:00
|
|
|
let l:result = json_decode(join(a:lines, ''))
|
|
|
|
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:warning in l:result.warnings
|
|
|
|
" Brakeman always outputs paths relative to the Rails app root
|
2017-07-12 09:43:47 +00:00
|
|
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
2017-05-05 09:05:53 +00:00
|
|
|
let l:warning_file = l:rails_root . '/' . l:warning.file
|
|
|
|
|
|
|
|
if !ale#path#IsBufferPath(a:buffer, l:warning_file)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:text = l:warning.warning_type . ' ' . l:warning.message . ' (' . l:warning.confidence . ')'
|
|
|
|
let l:line = l:warning.line != v:null ? l:warning.line : 1
|
|
|
|
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:line,
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ 'text': l:text,
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
|
2017-07-12 09:43:47 +00:00
|
|
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
2017-05-05 09:05:53 +00:00
|
|
|
|
|
|
|
if l:rails_root ==? ''
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 'brakeman -f json -q '
|
|
|
|
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
2017-06-21 21:33:34 +00:00
|
|
|
\ . ' -p ' . ale#Escape(l:rails_root)
|
2017-05-05 09:05:53 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('ruby', {
|
|
|
|
\ 'name': 'brakeman',
|
|
|
|
\ 'executable': 'brakeman',
|
|
|
|
\ 'command_callback': 'ale_linters#ruby#brakeman#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#ruby#brakeman#Handle',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|