Add ormolu fixer.
This commit adds a fixer for the Haskell language, ormolu (https://github.com/tweag/ormolu). Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
557a1ed5da
commit
b496c4b164
7 changed files with 64 additions and 0 deletions
|
@ -380,6 +380,11 @@ let s:default_registry = {
|
|||
\ 'suggested_filetypes': ['dhall'],
|
||||
\ 'description': 'Fix Dhall files with dhall-format.',
|
||||
\ },
|
||||
\ 'ormolu': {
|
||||
\ 'function': 'ale#fixers#ormolu#Fix',
|
||||
\ 'suggested_filetypes': ['haskell'],
|
||||
\ 'description': 'A formatter for Haskell source code.',
|
||||
\ },
|
||||
\}
|
||||
|
||||
" Reset the function registry to the default entries.
|
||||
|
|
12
autoload/ale/fixers/ormolu.vim
Normal file
12
autoload/ale/fixers/ormolu.vim
Normal file
|
@ -0,0 +1,12 @@
|
|||
call ale#Set('haskell_ormolu_executable', 'ormolu')
|
||||
call ale#Set('haskell_ormolu_options', '')
|
||||
|
||||
function! ale#fixers#ormolu#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'haskell_ormolu_executable')
|
||||
let l:options = ale#Var(a:buffer, 'haskell_ormolu_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options),
|
||||
\}
|
||||
endfunction
|
|
@ -172,5 +172,25 @@ g:ale_haskell_hie_executable *g:ale_haskell_hie_executable*
|
|||
ide engine. i.e. `'hie-wrapper'`
|
||||
|
||||
|
||||
===============================================================================
|
||||
ormolu *ale-haskell-ormolu*
|
||||
|
||||
g:ale_haskell_ormolu_executable *g:ale_haskell_ormolu_executable*
|
||||
*b:ale_haskell_ormolu_executable*
|
||||
Type: |String|
|
||||
Default: `'ormolu'`
|
||||
|
||||
This variable can be changed to use a different executable for ormolu.
|
||||
|
||||
|
||||
g:ale_haskell_ormolu_options *g:ale_haskell_ormolu_options*
|
||||
*b:ale_haskell_ormolu_options*
|
||||
Type: String
|
||||
Default: ''
|
||||
|
||||
This variable can be used to pass extra options to the underlying ormolu
|
||||
executable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
|
|
@ -195,6 +195,7 @@ Notes:
|
|||
* `hie`
|
||||
* `hindent`
|
||||
* `hlint`
|
||||
* `ormolu`
|
||||
* `stack-build`!!
|
||||
* `stack-ghc`
|
||||
* `stylish-haskell`
|
||||
|
|
|
@ -2642,6 +2642,7 @@ documented in additional help files.
|
|||
stack-ghc.............................|ale-haskell-stack-ghc|
|
||||
stylish-haskell.......................|ale-haskell-stylish-haskell|
|
||||
hie...................................|ale-haskell-hie|
|
||||
ormolu................................|ale-haskell-ormolu|
|
||||
hcl.....................................|ale-hcl-options|
|
||||
terraform-fmt.........................|ale-hcl-terraform-fmt|
|
||||
html....................................|ale-html-options|
|
||||
|
|
|
@ -204,6 +204,7 @@ formatting.
|
|||
* [hie](https://github.com/haskell/haskell-ide-engine)
|
||||
* [hindent](https://hackage.haskell.org/package/hindent)
|
||||
* [hlint](https://hackage.haskell.org/package/hlint)
|
||||
* [ormolu](https://github.com/tweag/ormolu)
|
||||
* [stack-build](https://haskellstack.org/) :floppy_disk:
|
||||
* [stack-ghc](https://haskellstack.org/)
|
||||
* [stylish-haskell](https://github.com/jaspervdj/stylish-haskell)
|
||||
|
|
24
test/fixers/test_ormolu_fixer_callback.vader
Normal file
24
test/fixers/test_ormolu_fixer_callback.vader
Normal file
|
@ -0,0 +1,24 @@
|
|||
Before:
|
||||
Save g:ale_haskell_ormolu_executable
|
||||
Save g:ale_haskell_ormolu_options
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
Execute(The ormolu callback should return the correct default values):
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('ormolu')
|
||||
\ },
|
||||
\ ale#fixers#ormolu#Fix(bufnr(''))
|
||||
|
||||
Execute(The ormolu executable and options should be configurable):
|
||||
let g:ale_nix_nixpkgsfmt_executable = '/path/to/ormolu'
|
||||
let g:ale_nix_nixpkgsfmt_options = '-h'
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('/path/to/ormolu')
|
||||
\ . ' -h',
|
||||
\ },
|
||||
\ ale#fixers#nixpkgsfmt#Fix(bufnr(''))
|
Reference in a new issue