mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
Add fourmolu fixer (#4501)
* Add fourmolu fixer Fourmolu is aversion of Ormolu that supports configuration. This fixer was modeled after the Ormolu one, but using the "stack executable" approach of the Brittany and Stylish Haskell fixers. * Sort supported-tools.md
This commit is contained in:
@@ -561,6 +561,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['haskell'],
|
||||
\ 'description': 'A formatter for Haskell source code.',
|
||||
\ },
|
||||
\ 'fourmolu': {
|
||||
\ 'function': 'ale#fixers#fourmolu#Fix',
|
||||
\ 'suggested_filetypes': ['haskell'],
|
||||
\ 'description': 'A formatter for Haskell source code.',
|
||||
\ },
|
||||
\ 'jsonnetfmt': {
|
||||
\ 'function': 'ale#fixers#jsonnetfmt#Fix',
|
||||
\ 'suggested_filetypes': ['jsonnet'],
|
||||
|
||||
20
autoload/ale/fixers/fourmolu.vim
Normal file
20
autoload/ale/fixers/fourmolu.vim
Normal file
@@ -0,0 +1,20 @@
|
||||
call ale#Set('haskell_fourmolu_executable', 'fourmolu')
|
||||
call ale#Set('haskell_fourmolu_options', '')
|
||||
|
||||
function! ale#fixers#fourmolu#GetExecutable(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'haskell_fourmolu_executable')
|
||||
|
||||
return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'fourmolu')
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#fourmolu#Fix(buffer) abort
|
||||
let l:executable = ale#fixers#fourmolu#GetExecutable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'haskell_fourmolu_options')
|
||||
|
||||
return {
|
||||
\ 'command': l:executable
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
\ . ' --stdin-input-file '
|
||||
\ . ale#Escape(@%),
|
||||
\}
|
||||
endfunction
|
||||
@@ -224,5 +224,25 @@ g:ale_haskell_ormolu_options *g:ale_haskell_ormolu_options*
|
||||
executable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
fourmolu *ale-haskell-fourmolu*
|
||||
|
||||
g:ale_haskell_fourmolu_executable *g:ale_haskell_fourmolu_executable*
|
||||
*b:ale_haskell_fourmolu_executable*
|
||||
Type: |String|
|
||||
Default: `'fourmolu'`
|
||||
|
||||
This variable can be changed to use a different executable for fourmolu.
|
||||
|
||||
|
||||
g:ale_haskell_fourmolu_options *g:ale_haskell_fourmolu_options*
|
||||
*b:ale_haskell_fourmolu_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be used to pass extra options to the underlying fourmolu
|
||||
executable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
||||
@@ -236,6 +236,7 @@ Notes:
|
||||
* `cabal-ghc`
|
||||
* `cspell`
|
||||
* `floskell`
|
||||
* `fourmolu`
|
||||
* `ghc`
|
||||
* `ghc-mod`
|
||||
* `hdevtools`
|
||||
|
||||
@@ -3019,6 +3019,7 @@ documented in additional help files.
|
||||
stylish-haskell.......................|ale-haskell-stylish-haskell|
|
||||
hie...................................|ale-haskell-hie|
|
||||
ormolu................................|ale-haskell-ormolu|
|
||||
fourmolu..............................|ale-haskell-fourmolu|
|
||||
hcl.....................................|ale-hcl-options|
|
||||
packer-fmt............................|ale-hcl-packer-fmt|
|
||||
terraform-fmt.........................|ale-hcl-terraform-fmt|
|
||||
|
||||
@@ -245,6 +245,7 @@ formatting.
|
||||
* [cabal-ghc](https://www.haskell.org/cabal/)
|
||||
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
||||
* [floskell](https://github.com/ennocramer/floskell)
|
||||
* [fourmolu](https://github.com/fourmolu/fourmolu)
|
||||
* [ghc](https://www.haskell.org/ghc/)
|
||||
* [ghc-mod](https://github.com/DanielG/ghc-mod)
|
||||
* [hdevtools](https://hackage.haskell.org/package/hdevtools)
|
||||
|
||||
29
test/fixers/test_fourmolu_fixer_callback.vader
Normal file
29
test/fixers/test_fourmolu_fixer_callback.vader
Normal file
@@ -0,0 +1,29 @@
|
||||
Before:
|
||||
Save g:ale_haskell_fourmolu_executable
|
||||
Save g:ale_haskell_fourmolu_options
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
Execute(The fourmolu callback should return the correct default values):
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('fourmolu')
|
||||
\ . ' --stdin-input-file '
|
||||
\ . ale#Escape(@%)
|
||||
\ },
|
||||
\ ale#fixers#fourmolu#Fix(bufnr(''))
|
||||
|
||||
Execute(The fourmolu executable and options should be configurable):
|
||||
let g:ale_haskell_fourmolu_executable = '/path/to/fourmolu'
|
||||
let g:ale_haskell_fourmolu_options = '-h'
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('/path/to/fourmolu')
|
||||
\ . ' -h'
|
||||
\ . ' --stdin-input-file '
|
||||
\ . ale#Escape(@%)
|
||||
\ },
|
||||
\ ale#fixers#fourmolu#Fix(bufnr(''))
|
||||
|
||||
Reference in New Issue
Block a user