From 26005242744c6d88f0ec728964754909f4a73d94 Mon Sep 17 00:00:00 2001 From: Evan Borden Date: Thu, 23 Aug 2018 18:14:59 -0400 Subject: [PATCH] Add stylish-haskell as a fixer (#1837) * Add stylish-haskell as a fixer `stylish-haskell` is a common formatting tool for the haskell toolchain. It is not as advanced as `brittany` or `hindent`, but it is commonly used for formatting of imports and data declarations. This adds it as a fixer in ALE. --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 ++++ autoload/ale/fixers/stylish_haskell.vim | 15 ++++++++++++ doc/ale-haskell.txt | 10 ++++++++ doc/ale.txt | 3 ++- .../test_stylish_haskell_fixer_callback.vader | 24 +++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/stylish_haskell.vim create mode 100644 test/fixers/test_stylish_haskell_fixer_callback.vader diff --git a/README.md b/README.md index 5bfe24ba..8c4f8138 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ formatting. | Hack | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/hhvm/tree/master/hphp/hack/hackfmt), [hhast](https://github.com/hhvm/hhast) (disabled by default; see `:help ale-integration-hack`) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | -| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [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), [hie](https://github.com/haskell/haskell-ide-engine) | +| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stylish-haskell](https://github.com/jaspervdj/stylish-haskell), [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), [hie](https://github.com/haskell/haskell-ide-engine) | | HTML | [alex](https://github.com/wooorm/alex) !!, [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), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index ef287358..60de4a46 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -170,6 +170,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['haskell'], \ 'description': 'Fix Haskell files with brittany.', \ }, +\ 'stylish-haskell': { +\ 'function': 'ale#fixers#stylish_haskell#Fix', +\ 'suggested_filetypes': ['haskell'], +\ 'description': 'Refactor Haskell files with stylish-haskell.', +\ }, \ 'refmt': { \ 'function': 'ale#fixers#refmt#Fix', \ 'suggested_filetypes': ['reason'], diff --git a/autoload/ale/fixers/stylish_haskell.vim b/autoload/ale/fixers/stylish_haskell.vim new file mode 100644 index 00000000..a352312f --- /dev/null +++ b/autoload/ale/fixers/stylish_haskell.vim @@ -0,0 +1,15 @@ +" Author: eborden +" Description: Integration of stylish-haskell formatting with ALE. +" +call ale#Set('haskell_stylish_haskell_executable', 'stylish-haskell') + +function! ale#fixers#stylish_haskell#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'haskell_stylish_haskell_executable') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' --inplace' + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt index 379cd987..9bc9263a 100644 --- a/doc/ale-haskell.txt +++ b/doc/ale-haskell.txt @@ -78,6 +78,16 @@ g:ale_haskell_stack_build_options *g:ale_haskell_stack_build_options* We default to using `'--fast'`. Since Stack generates binaries, your programs will be slower unless you separately rebuild them outside of ALE. +=============================================================================== +stylish-haskell *ale-haskell-stylish-haskell* + +g:ale_haskell_stylish_haskell_executable + *g:ale_haskell_stylish_haskell_executable* + *b:ale_haskell_stylish_haskell_executable* + Type: |String| + Default: `'stylish-haskell'` + + This variable can be changed to use a different executable for stylish-haskell. =============================================================================== hie *ale-haskell-hie* diff --git a/doc/ale.txt b/doc/ale.txt index 416a48ff..2d3efa34 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -111,6 +111,7 @@ CONTENTS *ale-contents* hdevtools...........................|ale-haskell-hdevtools| hfmt................................|ale-haskell-hfmt| stack-build.........................|ale-haskell-stack-build| + stylish-haskell.....................|ale-haskell-stylish-haskell| hie.................................|ale-haskell-hie| html..................................|ale-html-options| htmlhint............................|ale-html-htmlhint| @@ -380,7 +381,7 @@ Notes: * Hack: `hack`, `hackfmt`, `hhast` * Haml: `haml-lint` * Handlebars: `ember-template-lint` -* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`, `hie` +* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stylish-haskell`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`, `hie` * HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good` * Idris: `idris` * Java: `checkstyle`, `javac`, `google-java-format`, `PMD` diff --git a/test/fixers/test_stylish_haskell_fixer_callback.vader b/test/fixers/test_stylish_haskell_fixer_callback.vader new file mode 100644 index 00000000..755d3430 --- /dev/null +++ b/test/fixers/test_stylish_haskell_fixer_callback.vader @@ -0,0 +1,24 @@ +Before: + Save g:ale_haskell_stylish_haskell_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_haskell_stylish_haskell_executable = 'xxxinvalid' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The stylish-haskell callback should return the correct default values): + call ale#test#SetFilename('../haskell_files/testfile.hs') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' --inplace' + \ . ' %t', + \ }, + \ ale#fixers#stylish_haskell#Fix(bufnr(''))