adds fixer support for hfmt (#1027)

Add support for fixing Haskell with hfmt
This commit is contained in:
Zack Kourouma 2017-10-24 14:29:04 -07:00 committed by w0rp
parent b172cd8b17
commit 07dad64acb
6 changed files with 58 additions and 2 deletions

View File

@ -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) |

View File

@ -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.

View File

@ -0,0 +1,16 @@
" Author: zack <zack@kourouma.me>
" 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

View File

@ -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*

View File

@ -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`

View File

@ -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(''))