2018-03-31 10:55:20 -04:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: Brakeman, a static analyzer for Rails security
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
call ale#Set('ruby_brakeman_options', '')
|
|
|
|
call ale#Set('ruby_brakeman_executable', 'brakeman')
|
|
|
|
call ale#Set('ruby_brakeman_options', '')
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
|
|
|
let l:sep = has('win32') ? '\' : '/'
|
|
|
|
" Brakeman always outputs paths relative to the Rails app root
|
|
|
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
|
|
|
|
|
|
|
for l:warning in get(l:json, 'warnings', [])
|
|
|
|
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, {
|
|
|
|
\ 'filename': l:rails_root . l:sep . l:warning.file,
|
|
|
|
\ 'lnum': l:line,
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ 'text': l:text,
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
|
|
|
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
|
|
|
|
|
|
|
if l:rails_root is? ''
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
let l:executable = ale#Var(a:buffer, 'ruby_brakeman_executable')
|
|
|
|
|
|
|
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'brakeman')
|
|
|
|
\ . ' -f json -q '
|
2018-03-31 10:55:20 -04:00
|
|
|
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
|
|
|
\ . ' -p ' . ale#Escape(l:rails_root)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('ruby', {
|
|
|
|
\ 'name': 'brakeman',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'ruby_brakeman_executable')},
|
|
|
|
\ 'command': function('ale_linters#ruby#brakeman#GetCommand'),
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale_linters#ruby#brakeman#Handle',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|