summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-11-16 10:19:32 +0000
committerGitHub <noreply@github.com>2017-11-16 10:19:32 +0000
commitf90a2d54744d7bfe985b0cd48a00012afecdc754 (patch)
tree1f893e61a746d359b858a3eade8fc350b9ad84ab /ale_linters
parentee07be5f59611510ed21880f5d895393e954d418 (diff)
parentad7ea3630758af51f6be826fcd453dfc42a6cd75 (diff)
downloadale-f90a2d54744d7bfe985b0cd48a00012afecdc754.zip
Merge pull request #1114 from elebow/eruby-strip-rails-flavoring
Strip Rails flavoring from eRuby when in a Rails project. Fixes #580.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/eruby/erb.vim25
-rw-r--r--ale_linters/eruby/erubis.vim18
-rw-r--r--ale_linters/eruby/erubylint.vim11
3 files changed, 40 insertions, 14 deletions
diff --git a/ale_linters/eruby/erb.vim b/ale_linters/eruby/erb.vim
new file mode 100644
index 00000000..5d0b4003
--- /dev/null
+++ b/ale_linters/eruby/erb.vim
@@ -0,0 +1,25 @@
+" Author: Matthias Guenther - https://wikimatze.de, Eddie Lebow https://github.com/elebow
+" Description: ERB from the Ruby standard library, for eruby/erb files
+
+function! ale_linters#eruby#erb#GetCommand(buffer) abort
+ let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
+
+ if empty(l:rails_root)
+ return 'erb -P -x %t | ruby -c'
+ endif
+
+ " Rails-flavored eRuby does not comply with the standard as understood by
+ " ERB, 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 erb -e ' . ale#Escape('puts ERB.new($stdin.read.gsub(%{<%=},%{<%}), nil, %{-}).src') . ' | ruby -c'
+endfunction
+
+call ale#linter#Define('eruby', {
+\ 'name': 'erb',
+\ 'aliases': ['erubylint'],
+\ 'executable': 'erb',
+\ 'output_stream': 'stderr',
+\ 'command_callback': 'ale_linters#eruby#erb#GetCommand',
+\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
+\})
+
diff --git a/ale_linters/eruby/erubis.vim b/ale_linters/eruby/erubis.vim
index be9332df..ac356aeb 100644
--- a/ale_linters/eruby/erubis.vim
+++ b/ale_linters/eruby/erubis.vim
@@ -1,11 +1,23 @@
-" Author: Jake Zimmerman <jake@zimmerman.io>
+" Author: Jake Zimmerman <jake@zimmerman.io>, Eddie Lebow https://github.com/elebow
" Description: eruby checker using `erubis`, instead of `erb`
+function! ale_linters#eruby#erubis#GetCommand(buffer) abort
+ let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
+
+ if empty(l:rails_root)
+ return 'erubis -x %t | ruby -c'
+ endif
+
+ " Rails-flavored eRuby does not comply with the standard as understood by
+ " Erubis, 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 erubis -e ' . ale#Escape('puts Erubis::Eruby.new($stdin.read.gsub(%{<%=},%{<%})).src') . ' | ruby -c'
+endfunction
+
call ale#linter#Define('eruby', {
\ 'name': 'erubis',
\ 'executable': 'erubis',
\ 'output_stream': 'stderr',
-\ 'command': 'erubis -x %t | ruby -c',
+\ 'command_callback': 'ale_linters#eruby#erubis#GetCommand',
\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
\})
-
diff --git a/ale_linters/eruby/erubylint.vim b/ale_linters/eruby/erubylint.vim
deleted file mode 100644
index 2ff03c32..00000000
--- a/ale_linters/eruby/erubylint.vim
+++ /dev/null
@@ -1,11 +0,0 @@
-" Author: Matthias Guenther - https://wikimatze.de
-" Description: erb-lint for eruby/erb files
-
-call ale#linter#Define('eruby', {
-\ 'name': 'erubylint',
-\ 'executable': 'erb',
-\ 'output_stream': 'stderr',
-\ 'command': 'erb -P -x %t | ruby -c',
-\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors',
-\})
-