From c55064881db1543aa6dbbf2490623064daa6b935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCnther?= Date: Tue, 25 Apr 2017 19:38:02 +0200 Subject: [PATCH] Add erb linter (#497) * Add eruby linter * Update README with erb linter * Fix example and contributions * Remove trailing newline * Fix for Vimscript style guide * Eruby-linter: codereview with @w0rp - read from stderro output_stream * Eruby-linter: codereview => add handler for ruby * Eruby-linter: codereview - eruby and ruby lint use the same ruby-handler (removes duplicated handling logic) * Eruby-linter: try to fix tests --- README.md | 1 + ale_linters/eruby/erubylint.vim | 11 +++++++++ ale_linters/ruby/ruby.vim | 31 +---------------------- autoload/ale/handlers/ruby.vim | 37 ++++++++++++++++++++++++++++ test/handler/test_ruby_handler.vader | 2 +- 5 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 ale_linters/eruby/erubylint.vim create mode 100644 autoload/ale/handlers/ruby.vim diff --git a/README.md b/README.md index a911552e..4274adc6 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ name. That seems to be the fairest way to arrange this table. | Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | | Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) | | Elm | [elm-make](https://github.com/elm-lang/elm-make) | +| Erb | [erb](https://github.com/jeremyevans/erubih) | | Erlang | [erlc](http://erlang.org/doc/man/erlc.html) | | Fortran | [gcc](https://gcc.gnu.org/) | | Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [gometalinter](https://github.com/alecthomas/gometalinter), [go build](https://golang.org/cmd/go/), [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple), [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) | diff --git a/ale_linters/eruby/erubylint.vim b/ale_linters/eruby/erubylint.vim new file mode 100644 index 00000000..2ff03c32 --- /dev/null +++ b/ale_linters/eruby/erubylint.vim @@ -0,0 +1,11 @@ +" 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', +\}) + diff --git a/ale_linters/ruby/ruby.vim b/ale_linters/ruby/ruby.vim index 1ed9d429..a9f7b51b 100644 --- a/ale_linters/ruby/ruby.vim +++ b/ale_linters/ruby/ruby.vim @@ -1,39 +1,10 @@ " 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, { - \ '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', +\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors', \}) diff --git a/autoload/ale/handlers/ruby.vim b/autoload/ale/handlers/ruby.vim new file mode 100644 index 00000000..106526b8 --- /dev/null +++ b/autoload/ale/handlers/ruby.vim @@ -0,0 +1,37 @@ +" Author: Matthias Guenther https://wikimatze.de +" +" Description: This file implements handlers specific to Ruby. + +function! s:HandleSyntaxError(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, { + \ '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 + +function! ale#handlers#ruby#HandleSyntaxErrors(buffer, lines) abort + return s:HandleSyntaxError(a:buffer, a:lines) +endfunction + diff --git a/test/handler/test_ruby_handler.vader b/test/handler/test_ruby_handler.vader index ed8b06e2..ba676501 100644 --- a/test/handler/test_ruby_handler.vader +++ b/test/handler/test_ruby_handler.vader @@ -24,7 +24,7 @@ Execute(The ruby handler should parse lines correctly and add the column if it c \ 'text': 'syntax error, unexpected end-of-input, expecting keyword_end' \ } \ ], - \ ale_linters#ruby#ruby#Handle(255, [ + \ ale#handlers#ruby#HandleSyntaxErrors(255, [ \ "test.rb:6: syntax error, unexpected ';'", \ " t = ;", \ " ^",