2017-11-12 05:53:02 +00:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: eruby checker using `erubi`
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
function! ale_linters#eruby#erubi#GetCommand(buffer, output, meta) abort
|
2017-11-12 05:53:02 +00:00
|
|
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
if !empty(a:output)
|
2017-11-12 05:53:02 +00:00
|
|
|
" The empty command in CheckErubi returns nothing if erubi runs and
|
|
|
|
" emits an error if erubi is not present
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
if empty(l:rails_root)
|
|
|
|
return 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read).src') . '< %t | ruby -c'
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Rails-flavored eRuby does not comply with the standard as understood by
|
|
|
|
" Erubi, so we'll have to do some substitution. This does not reduce the
|
|
|
|
" effectiveness of the linter---the translated code is still evaluated.
|
|
|
|
return 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read.gsub(%{<%=},%{<%}), nil, %{-}).src') . '< %t | ruby -c'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('eruby', {
|
|
|
|
\ 'name': 'erubi',
|
|
|
|
\ 'executable': 'ruby',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ 'command': {buffer -> ale#command#Run(
|
|
|
|
\ buffer,
|
|
|
|
\ 'ruby -r erubi/capture_end -e ' . ale#Escape('""'),
|
|
|
|
\ function('ale_linters#eruby#erubi#GetCommand'),
|
|
|
|
\ )},
|
2017-11-12 05:53:02 +00:00
|
|
|
\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
|
|
|
|
\})
|