From 1aea6a34ff22c9e79d20a018b4d46000c208caf2 Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Sun, 16 Jul 2017 14:35:43 +0300 Subject: [PATCH] Add SyntaxErl linter These changes add [SyntaxErl][1] integration. SyntaxErl is a syntax checker tool for Erlang. [1]: https://github.com/ten0s/syntaxerl --- README.md | 2 +- ale_linters/erlang/syntaxerl.vim | 38 +++++++++++++++++++++++ doc/ale-erlang.txt | 11 +++++++ doc/ale.txt | 1 + test/handler/test_syntaxerl_handler.vader | 24 ++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 ale_linters/erlang/syntaxerl.vim create mode 100644 test/handler/test_syntaxerl_handler.vader diff --git a/README.md b/README.md index 38ad43e..6a66e95 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ name. That seems to be the fairest way to arrange this table. | 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/erubi) | -| Erlang | [erlc](http://erlang.org/doc/man/erlc.html) | +| Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) | | Fortran | [gcc](https://gcc.gnu.org/) | | FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) | | 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/erlang/syntaxerl.vim b/ale_linters/erlang/syntaxerl.vim new file mode 100644 index 0000000..dd53d8e --- /dev/null +++ b/ale_linters/erlang/syntaxerl.vim @@ -0,0 +1,38 @@ +" Author: Dmitri Vereshchagin +" Description: SyntaxErl linter for Erlang files + +call ale#Set('erlang_syntaxerl_executable', 'syntaxerl') + + +function! ale_linters#erlang#syntaxerl#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'erlang_syntaxerl_executable') +endfunction + + +function! ale_linters#erlang#syntaxerl#GetCommand(buffer) abort + return ale_linters#erlang#syntaxerl#GetExecutable(a:buffer) . ' %t' +endfunction + + +function! ale_linters#erlang#syntaxerl#Handle(buffer, lines) abort + let l:pattern = '\v\C:(\d+):( warning:)? (.+)' + let l:loclist = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:loclist, { + \ 'lnum': l:match[1] + 0, + \ 'text': l:match[3], + \ 'type': empty(l:match[2]) ? 'E' : 'W', + \}) + endfor + + return l:loclist +endfunction + + +call ale#linter#Define('erlang', { +\ 'name': 'syntaxerl', +\ 'executable_callback': 'ale_linters#erlang#syntaxerl#GetExecutable', +\ 'command_callback': 'ale_linters#erlang#syntaxerl#GetCommand', +\ 'callback': 'ale_linters#erlang#syntaxerl#Handle', +\}) diff --git a/doc/ale-erlang.txt b/doc/ale-erlang.txt index 9e44623..ad3c1e5 100644 --- a/doc/ale-erlang.txt +++ b/doc/ale-erlang.txt @@ -14,5 +14,16 @@ g:ale_erlang_erlc_options *g:ale_erlang_erlc_options* or `-pa`. +------------------------------------------------------------------------------- +syntaxerl *ale-erlang-syntaxerl* + +g:ale_erlang_syntaxerl_executable *g:ale_erlang_syntaxerl_executable* + *b:ale_erlang_syntaxerl_executable* + Type: |String| + Default: `'syntaxerl'` + + This variable can be changed to specify the syntaxerl executable. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 642d388..9ebe8a6 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -33,6 +33,7 @@ CONTENTS *ale-contents* cmakelint...........................|ale-cmake-cmakelint| erlang................................|ale-erlang-options| erlc................................|ale-erlang-erlc| + syntaxerl...........................|ale-erlang-syntaxerl| fortran...............................|ale-fortran-options| gcc.................................|ale-fortran-gcc| fusionscript..........................|ale-fuse-options| diff --git a/test/handler/test_syntaxerl_handler.vader b/test/handler/test_syntaxerl_handler.vader new file mode 100644 index 0000000..1308ec8 --- /dev/null +++ b/test/handler/test_syntaxerl_handler.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/erlang/syntaxerl.vim + +After: + call ale#linter#Reset() + +Execute: + AssertEqual + \ [ + \ { + \ 'lnum': 42, + \ 'text': "syntax error before: ','", + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 42, + \ 'text': 'function foo/0 is unused', + \ 'type': 'W', + \ }, + \ ], + \ ale_linters#erlang#syntaxerl#Handle(42, [ + \ "/tmp/v2wDixk/1/module.erl:42: syntax error before: ','", + \ '/tmp/v2wDixk/2/module.erl:42: warning: function foo/0 is unused', + \ ])