From 07dad64acb2ac67c3ccf5582995e3377d1479aa7 Mon Sep 17 00:00:00 2001 From: Zack Kourouma Date: Tue, 24 Oct 2017 14:29:04 -0700 Subject: [PATCH] adds fixer support for hfmt (#1027) Add support for fixing Haskell with hfmt --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/hfmt.vim | 16 +++++++++++++++ doc/ale-haskell.txt | 10 +++++++++ doc/ale.txt | 3 ++- test/fixers/test_hfmt_fixer_callback.vader | 24 ++++++++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/hfmt.vim create mode 100644 test/fixers/test_hfmt_fixer_callback.vader diff --git a/README.md b/README.md index 742712af..e803b907 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ formatting. | GraphQL | [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) | +| 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) | | HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/) | | 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 e17521f4..bbdcc430 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -117,6 +117,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['rust'], \ 'description': 'Fix Rust files with Rustfmt.', \ }, +\ 'hfmt': { +\ 'function': 'ale#fixers#hfmt#Fix', +\ 'suggested_filetypes': ['haskell'], +\ 'description': 'Fix Haskell files with hfmt.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/hfmt.vim b/autoload/ale/fixers/hfmt.vim new file mode 100644 index 00000000..ea061da4 --- /dev/null +++ b/autoload/ale/fixers/hfmt.vim @@ -0,0 +1,16 @@ +" Author: zack +" Description: Integration of hfmt with ALE. + +call ale#Set('haskell_hfmt_executable', 'hfmt') + +function! ale#fixers#hfmt#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'haskell_hfmt_executable') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' -w' + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction + diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt index bbf99fcf..4a490efc 100644 --- a/doc/ale-haskell.txt +++ b/doc/ale-haskell.txt @@ -20,6 +20,16 @@ g:ale_haskell_hdevtools_options *g:ale_haskell_hdevtools_options* This variable can be changed to modify flags given to hdevtools. +=============================================================================== +hfmt *ale-haskell-hfmt* + +g:ale_haskell_hfmt_executable *g:ale_haskell_hfmt_executable* + *b:ale_haskell_hfmt_executable* + Type: |String| + Default: `'hfmt'` + + This variable can be changed to use a different executable for hfmt. + =============================================================================== stack-build *ale-haskell-stack-build* diff --git a/doc/ale.txt b/doc/ale.txt index 2972381a..e0e85df8 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -72,6 +72,7 @@ CONTENTS *ale-contents* ember-template-lint.................|ale-handlebars-embertemplatelint| haskell...............................|ale-haskell-options| hdevtools...........................|ale-haskell-hdevtools| + hfmt................................|ale-haskell-hfmt| stack-build.........................|ale-haskell-stack-build| html..................................|ale-html-options| htmlhint............................|ale-html-htmlhint| @@ -255,7 +256,7 @@ Notes: * GraphQL: `gqlint` * Haml: `haml-lint` * Handlebars: `ember-template-lint` -* Haskell: `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools` +* Haskell: `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` * HTML: `HTMLHint`, `proselint`, `tidy` * Idris: `idris` * Java: `checkstyle`, `javac` diff --git a/test/fixers/test_hfmt_fixer_callback.vader b/test/fixers/test_hfmt_fixer_callback.vader new file mode 100644 index 00000000..69cd03f8 --- /dev/null +++ b/test/fixers/test_hfmt_fixer_callback.vader @@ -0,0 +1,24 @@ +Before: + Save g:ale_haskell_hfmt_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_haskell_hfmt_executable = 'xxxinvalid' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The hfmt callback should return the correct default values): + call ale#test#SetFilename('../haskell_files/testfile.hs') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' -w' + \ . ' %t', + \ }, + \ ale#fixers#hfmt#Fix(bufnr(''))