summaryrefslogtreecommitdiff
path: root/ale_linters/eruby
diff options
context:
space:
mode:
authorEddie Lebow <elebow@users.noreply.github.com>2017-11-12 00:53:02 -0500
committerEddie Lebow <elebow@users.noreply.github.com>2018-01-16 00:38:35 -0500
commitaa29c91cdc9c5dc737e93c1f91080aa174363bef (patch)
tree95a892e98f4c5c6fdc0c64db0c72d1219796a18f /ale_linters/eruby
parent7ea3aba5e587f1993c0377ed270b5cbd823e3711 (diff)
downloadale-aa29c91cdc9c5dc737e93c1f91080aa174363bef.zip
[eruby] Add erubi linter
Erubi is yet another parser for eRuby. This is the default parser in Rails as of version 5.1. It supports some additional syntax with similar behavior to Rails' extensions to the language, though incompatible. Rails currently still recommends their own syntax, so GetCommand still has to do the translation introduced in https://github.com/w0rp/ale/pull/1114 . Erubi does not supply an executable—It is intended to be invoked only from within a Ruby program. In this case, a one-liner on the command line.
Diffstat (limited to 'ale_linters/eruby')
-rw-r--r--ale_linters/eruby/erubi.vim35
1 files changed, 35 insertions, 0 deletions
diff --git a/ale_linters/eruby/erubi.vim b/ale_linters/eruby/erubi.vim
new file mode 100644
index 00000000..6f2d3ac6
--- /dev/null
+++ b/ale_linters/eruby/erubi.vim
@@ -0,0 +1,35 @@
+" Author: Eddie Lebow https://github.com/elebow
+" Description: eruby checker using `erubi`
+
+function! ale_linters#eruby#erubi#CheckErubi(buffer) abort
+ return 'ruby -r erubi/capture_end -e ' . ale#Escape('""')
+endfunction
+
+function! ale_linters#eruby#erubi#GetCommand(buffer, check_erubi_output) abort
+ let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
+
+ if (!empty(a:check_erubi_output))
+ " 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',
+\ 'command_chain': [
+\ {'callback': 'ale_linters#eruby#erubi#CheckErubi'},
+\ {'callback': 'ale_linters#eruby#erubi#GetCommand', 'output_stream': 'stderr'},
+\ ],
+\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
+\})