2017-07-12 09:43:47 +00:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: rails_best_practices, a code metric tool for rails projects
|
|
|
|
|
2018-07-15 17:24:53 +00:00
|
|
|
call ale#Set('ruby_rails_best_practices_options', '')
|
|
|
|
call ale#Set('ruby_rails_best_practices_executable', 'rails_best_practices')
|
2017-07-12 09:43:47 +00:00
|
|
|
|
|
|
|
function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2017-07-26 23:45:25 +00:00
|
|
|
for l:warning in ale#util#FuzzyJSONDecode(a:lines, [])
|
2017-07-12 09:43:47 +00:00
|
|
|
if !ale#path#IsBufferPath(a:buffer, l:warning.filename)
|
2017-07-26 23:45:25 +00:00
|
|
|
continue
|
2017-07-12 09:43:47 +00:00
|
|
|
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)
|
|
|
|
|
2017-08-08 07:39:13 +00:00
|
|
|
if l:rails_root is? ''
|
2017-07-12 09:43:47 +00:00
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2018-09-14 12:24:59 +00:00
|
|
|
let l:executable = ale#Var(a:buffer, 'ruby_rails_best_practices_executable')
|
2019-04-07 14:34:39 +00:00
|
|
|
let l:output_file = has('win32') ? '%t ' : '/dev/stdout '
|
|
|
|
let l:cat_file = has('win32') ? '; type %t' : ''
|
2017-07-12 09:43:47 +00:00
|
|
|
|
2019-08-13 05:52:13 +00:00
|
|
|
return ale#ruby#EscapeExecutable(l:executable, 'rails_best_practices')
|
2017-07-12 09:43:47 +00:00
|
|
|
\ . ' --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',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'ruby_rails_best_practices_executable')},
|
|
|
|
\ 'command': function('ale_linters#ruby#rails_best_practices#GetCommand'),
|
2017-07-12 09:43:47 +00:00
|
|
|
\ 'callback': 'ale_linters#ruby#rails_best_practices#Handle',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|