Merge pull request #1157 from elebow/eruby-add-erubi-linter

[eruby] Add erubi linter
This commit is contained in:
w0rp 2018-01-24 10:40:57 +00:00 committed by GitHub
commit 9849c79ff7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 9 deletions

View file

@ -96,7 +96,7 @@ formatting.
| Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) |
| Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma) !!|
| Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) |
| Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) |
| Erb | [erb](https://apidock.com/ruby/ERB), [erubi](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) |
| Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) |
| Fish | fish [-n flag](https://linux.die.net/man/1/fish)
| Fortran | [gcc](https://gcc.gnu.org/) |

View file

@ -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',
\})

View file

@ -1,17 +1,15 @@
===============================================================================
ALE Eruby Integration *ale-eruby-options*
There are two linters for `eruby` files:
There are three linters for `eruby` files:
- `erb`
- `erubis`
- `erubi`
If you don't know which one your project uses, it's probably `erb`.
To selectively enable one or the other, see |g:ale_linters|.
(Note that ALE already disables linters if the executable for that linter is
not found; thus, there's probably no need to disable one of these if you're
using the other one.)
`erb` is in the Ruby standard library and is mostly universal. `erubis` is the
default parser in Rails between 3.0 and 5.1. `erubi` is the default in Rails
5.1 and later. To selectively enable a subset, see |g:ale_linters|.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -306,7 +306,7 @@ Notes:
* Dockerfile: `hadolint`
* Elixir: `credo`, `dialyxir`, `dogma`!!
* Elm: `elm-format, elm-make`
* Erb: `erb`, `erubis`
* Erb: `erb`, `erubi`, `erubis`
* Erlang: `erlc`, `SyntaxErl`
* Fish: `fish` (-n flag)
* Fortran: `gcc`

View file

@ -0,0 +1,31 @@
Before:
runtime ale_linters/eruby/erubi.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
call ale#linter#Reset()
call ale#test#RestoreDirectory()
Execute(Executable should not contain any filter code by default):
call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/file.rb')
AssertEqual
\ 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read).src') . '< %t | ruby -c',
\ ale_linters#eruby#erubi#GetCommand(bufnr(''), [])
Execute(Executable should filter invalid eRuby when inside a Rails project):
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/app/views/my_great_view.html.erb')
AssertEqual
\ 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read.gsub(%{<%=},%{<%}), nil, %{-}).src') . '< %t | ruby -c',
\ ale_linters#eruby#erubi#GetCommand(bufnr(''), [])
Execute(Command should be blank if the first command in the chain return output):
let output_lines = [
\ "/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erubi/capture_end (LoadError)",
\ " from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'",
\]
AssertEqual
\ '',
\ ale_linters#eruby#erubi#GetCommand(bufnr(''), output_lines)