From 3f33dc7d9832b7aed085d44b8ef76fd1c1eb90a5 Mon Sep 17 00:00:00 2001 From: wisut hantanong Date: Sat, 22 Apr 2017 19:23:23 +0700 Subject: [PATCH] Haskell: add ghc-mod linter --- README.md | 2 +- ale_linters/haskell/ghc-mod.vim | 16 +++++++++++++++ doc/ale.txt | 2 +- test/handler/test_ghc_mod_handler.vader | 27 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 ale_linters/haskell/ghc-mod.vim create mode 100644 test/handler/test_ghc_mod_handler.vader diff --git a/README.md b/README.md index d3fb431..d824a14 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ name. That seems to be the fairest way to arrange this table. | 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) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | -| Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools) | +| Haskell | [ghc](https://www.haskell.org/ghc/), [ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools) | | HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/) | | Java | [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) | | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) diff --git a/ale_linters/haskell/ghc-mod.vim b/ale_linters/haskell/ghc-mod.vim new file mode 100644 index 0000000..d3d2364 --- /dev/null +++ b/ale_linters/haskell/ghc-mod.vim @@ -0,0 +1,16 @@ +" Author: wizzup +" Description: ghc-mod for Haskell files + +call ale#linter#Define('haskell', { +\ 'name': 'ghc-mod', +\ 'executable': 'ghc-mod', +\ 'command': 'ghc-mod check %t', +\ 'callback': 'ale#handlers#haskell#HandleGHCFormat', +\}) + +call ale#linter#Define('haskell', { +\ 'name': 'stack-ghc-mod', +\ 'executable': 'stack', +\ 'command': 'stack exec ghc-mod check %t', +\ 'callback': 'ale#handlers#haskell#HandleGHCFormat', +\}) diff --git a/doc/ale.txt b/doc/ale.txt index d4d7517..c5411fc 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -136,7 +136,7 @@ The following languages and tools are supported. * Go: 'gofmt', 'go vet', 'golint', 'go build', 'gosimple', 'staticcheck' * Haml: 'hamllint' * Handlebars: 'ember-template-lint' -* Haskell: 'ghc', 'hlint', 'hdevtools' +* Haskell: 'ghc', 'ghc-mod', 'hlint', 'hdevtools' * HTML: 'HTMLHint', 'proselint', 'tidy' * Java: 'javac' * JavaScript: 'eslint', 'jscs', 'jshint', 'flow', 'xo' diff --git a/test/handler/test_ghc_mod_handler.vader b/test/handler/test_ghc_mod_handler.vader new file mode 100644 index 0000000..f9b44b3 --- /dev/null +++ b/test/handler/test_ghc_mod_handler.vader @@ -0,0 +1,27 @@ +Execute(HandleGhcFormat should handle ghc-mod problems): + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 1, + \ 'type': 'E', + \ 'text': 'Failed to load interface for ‘Missing’Use -v to see a list of the files searched for.', + \ }, + \ { + \ 'lnum': 2, + \ 'col': 1, + \ 'type': 'E', + \ 'text': ' Suggestion: Use camelCaseFound: my_variable = ...Why not: myVariable = ...', + \ }, + \ { + \ 'lnum': 6, + \ 'col': 1, + \ 'type': 'E', + \ 'text': ' Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ', + \ }, + \ ], + \ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [ + \ 'check1.hs:2:1:Failed to load interface for ‘Missing’Use -v to see a list of the files searched for.', + \ 'check2.hs:2:1: Suggestion: Use camelCaseFound: my_variable = ...Why not: myVariable = ...', + \ 'check2.hs:6:1: Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ', + \ ])