From edb3a0c5e4079708b915e6227541e4e1fae9f712 Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Tue, 28 Nov 2017 17:58:13 -0500 Subject: [PATCH 1/3] Add brittany for Haskell formatting `brittany` is one of the options for Haskell source formatting. This adds the necessary fixer files and documentation to support `brittany` in `ALE`. --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 ++++ autoload/ale/fixers/brittany.vim | 15 ++++++++++++ doc/ale-haskell.txt | 10 ++++++++ doc/ale.txt | 1 + .../fixers/test_brittany_fixer_callback.vader | 23 +++++++++++++++++++ 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 autoload/ale/fixers/brittany.vim create mode 100644 test/fixers/test_brittany_fixer_callback.vader diff --git a/README.md b/README.md index c5f63f3..c0589ee 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ formatting. | GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint) | | 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/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) | +| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) | | HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) | | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 4fb229b..dd63a80 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -134,6 +134,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['haskell'], \ 'description': 'Fix Haskell files with hfmt.', \ }, +\ 'brittany': { +\ 'function': 'ale#fixers#brittany#Fix', +\ 'suggested_filetypes': ['haskell'], +\ 'description': 'Fix Haskell files with brittany.', +\ }, \ 'refmt': { \ 'function': 'ale#fixers#refmt#Fix', \ 'suggested_filetypes': ['reason'], diff --git a/autoload/ale/fixers/brittany.vim b/autoload/ale/fixers/brittany.vim new file mode 100644 index 0000000..fed5eb8 --- /dev/null +++ b/autoload/ale/fixers/brittany.vim @@ -0,0 +1,15 @@ +" Author: eborden +" Description: Integration of brittany with ALE. + +call ale#Set('haskell_brittany_executable', 'brittany') + +function! ale#fixers#brittany#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'haskell_brittany_executable') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction + diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt index 4a490ef..0ea4037 100644 --- a/doc/ale-haskell.txt +++ b/doc/ale-haskell.txt @@ -2,6 +2,16 @@ ALE Haskell Integration *ale-haskell-options* +=============================================================================== +brittany *ale-haskell-brittany* + +g:ale_haskell_brittany_executable *g:ale_haskell_brittany_executable* + *b:ale_haskell_brittany_executable* + Type: |String| + Default: `'brittany'` + + This variable can be changed to use a different executable for brittany. + =============================================================================== hdevtools *ale-haskell-hdevtools* diff --git a/doc/ale.txt b/doc/ale.txt index 184912c..151351f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -79,6 +79,7 @@ CONTENTS *ale-contents* handlebars............................|ale-handlebars-options| ember-template-lint.................|ale-handlebars-embertemplatelint| haskell...............................|ale-haskell-options| + brittany............................|ale-haskell-brittany| hdevtools...........................|ale-haskell-hdevtools| hfmt................................|ale-haskell-hfmt| stack-build.........................|ale-haskell-stack-build| diff --git a/test/fixers/test_brittany_fixer_callback.vader b/test/fixers/test_brittany_fixer_callback.vader new file mode 100644 index 0000000..a0182b5 --- /dev/null +++ b/test/fixers/test_brittany_fixer_callback.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_haskell_brittany_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_haskell_brittany_executable = 'xxxinvalid' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The brittany callback should return the correct default values): + call ale#test#SetFilename('../haskell_files/testfile.hs') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' %t', + \ }, + \ ale#fixers#brittany#Fix(bufnr('')) From f66837818a161551dadff0a54eddfa3f639d61d8 Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Tue, 5 Dec 2017 15:04:02 -0500 Subject: [PATCH 2/3] Update doc/ale.txt to include brittany. --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index 151351f..28d0f9a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -300,7 +300,7 @@ Notes: * GraphQL: `eslint`, `gqlint` * Haml: `haml-lint` * Handlebars: `ember-template-lint` -* Haskell: `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` +* Haskell: `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `brittany`, `hfmt` * HTML: `HTMLHint`, `proselint`, `tidy`, `write-good` * Idris: `idris` * Java: `checkstyle`, `javac` From fbc8ac95539b6b1672e824a2df0422fdeb32f5c6 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 7 Dec 2017 19:01:13 +0000 Subject: [PATCH 3/3] Update ale.txt --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index 28d0f9a..5d5bd28 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -300,7 +300,7 @@ Notes: * GraphQL: `eslint`, `gqlint` * Haml: `haml-lint` * Handlebars: `ember-template-lint` -* Haskell: `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `brittany`, `hfmt` +* Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` * HTML: `HTMLHint`, `proselint`, `tidy`, `write-good` * Idris: `idris` * Java: `checkstyle`, `javac`