Add Ruby MRI linter (#453)
* Added ruby mri linter * Added to the list of supported linters * Async and now with 4 spaces * Vader tests for ruby * Match style choices * Vader test for the Ruby handler now works and passes
This commit is contained in:
parent
cc8eb05860
commit
4e40e8cb60
@ -94,7 +94,7 @@ name. That seems to be the fairest way to arrange this table.
|
||||
| Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) |
|
||||
| Python | [flake8](http://flake8.pycqa.org/en/latest/), [mypy](http://mypy-lang.org/), [pylint](https://www.pylint.org/) |
|
||||
| reStructuredText | [proselint](http://proselint.com/)|
|
||||
| Ruby | [rubocop](https://github.com/bbatsov/rubocop) |
|
||||
| Ruby | [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org) |
|
||||
| Rust | [rustc](https://www.rust-lang.org/), cargo (see `:help ale-integration-rust` for configuration instructions) |
|
||||
| SASS | [sass-lint](https://www.npmjs.com/package/sass-lint), [stylelint](https://github.com/stylelint/stylelint) |
|
||||
| SCSS | [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint) |
|
||||
|
40
ale_linters/ruby/ruby.vim
Normal file
40
ale_linters/ruby/ruby.vim
Normal file
@ -0,0 +1,40 @@
|
||||
" Author: Brandon Roehl - https://github.com/BrandonRoehl
|
||||
" Description: Ruby MRI for Ruby files
|
||||
|
||||
function! ale_linters#ruby#ruby#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" test.rb:3: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
|
||||
" test.rb:8: syntax error, unexpected keyword_end, expecting end-of-input
|
||||
let l:pattern = '\v^.+:(\d+): (warning: )?(.+)$'
|
||||
let l:column = '\v^(\s+)\^$'
|
||||
let l:output = []
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
if len(l:match) == 0
|
||||
let l:match = matchlist(l:line, l:column)
|
||||
if len(l:match) != 0
|
||||
let l:output[len(l:output) - 1]['col'] = len(l:match[1])
|
||||
endif
|
||||
else
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': 0,
|
||||
\ 'text': l:match[2] . l:match[3],
|
||||
\ 'type': empty(l:match[2]) ? 'E' : 'W',
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('ruby', {
|
||||
\ 'name': 'ruby',
|
||||
\ 'executable': 'ruby',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'command': 'ruby -w -c -T1 %t',
|
||||
\ 'callback': 'ale_linters#ruby#ruby#Handle',
|
||||
\})
|
39
test/handler/test_ruby_handler.vader
Normal file
39
test/handler/test_ruby_handler.vader
Normal file
@ -0,0 +1,39 @@
|
||||
Execute(The ruby handler should parse lines correctly and add the column if it can):
|
||||
runtime ale_linters/ruby/ruby.vim
|
||||
" Point Error
|
||||
" Warning
|
||||
" Line Error
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 6,
|
||||
\ 'bufnr': 255,
|
||||
\ 'col': 13,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'syntax error, unexpected '';'''
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 9,
|
||||
\ 'bufnr': 255,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'warning: statement not reached'
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 12,
|
||||
\ 'bufnr': 255,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'syntax error, unexpected end-of-input, expecting keyword_end'
|
||||
\ }
|
||||
\ ],
|
||||
\ ale_linters#ruby#ruby#Handle(255, [
|
||||
\ "test.rb:6: syntax error, unexpected ';'",
|
||||
\ " t = ;",
|
||||
\ " ^",
|
||||
\ "test.rb:9: warning: statement not reached",
|
||||
\ "test.rb:12: syntax error, unexpected end-of-input, expecting keyword_end",
|
||||
\ ])
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
Loading…
Reference in New Issue
Block a user