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:
Pat Brisbin 2023-04-22 09:05:50 -04:00 committed by GitHub
parent fdadaed2ba
commit 61248e1453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 0 deletions

View File

@ -561,6 +561,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'], \ 'suggested_filetypes': ['haskell'],
\ 'description': 'A formatter for Haskell source code.', \ 'description': 'A formatter for Haskell source code.',
\ }, \ },
\ 'fourmolu': {
\ 'function': 'ale#fixers#fourmolu#Fix',
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'A formatter for Haskell source code.',
\ },
\ 'jsonnetfmt': { \ 'jsonnetfmt': {
\ 'function': 'ale#fixers#jsonnetfmt#Fix', \ 'function': 'ale#fixers#jsonnetfmt#Fix',
\ 'suggested_filetypes': ['jsonnet'], \ 'suggested_filetypes': ['jsonnet'],

View 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

View File

@ -224,5 +224,25 @@ g:ale_haskell_ormolu_options *g:ale_haskell_ormolu_options*
executable. 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: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -236,6 +236,7 @@ Notes:
* `cabal-ghc` * `cabal-ghc`
* `cspell` * `cspell`
* `floskell` * `floskell`
* `fourmolu`
* `ghc` * `ghc`
* `ghc-mod` * `ghc-mod`
* `hdevtools` * `hdevtools`

View File

@ -3019,6 +3019,7 @@ documented in additional help files.
stylish-haskell.......................|ale-haskell-stylish-haskell| stylish-haskell.......................|ale-haskell-stylish-haskell|
hie...................................|ale-haskell-hie| hie...................................|ale-haskell-hie|
ormolu................................|ale-haskell-ormolu| ormolu................................|ale-haskell-ormolu|
fourmolu..............................|ale-haskell-fourmolu|
hcl.....................................|ale-hcl-options| hcl.....................................|ale-hcl-options|
packer-fmt............................|ale-hcl-packer-fmt| packer-fmt............................|ale-hcl-packer-fmt|
terraform-fmt.........................|ale-hcl-terraform-fmt| terraform-fmt.........................|ale-hcl-terraform-fmt|

View File

@ -245,6 +245,7 @@ formatting.
* [cabal-ghc](https://www.haskell.org/cabal/) * [cabal-ghc](https://www.haskell.org/cabal/)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell) * [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [floskell](https://github.com/ennocramer/floskell) * [floskell](https://github.com/ennocramer/floskell)
* [fourmolu](https://github.com/fourmolu/fourmolu)
* [ghc](https://www.haskell.org/ghc/) * [ghc](https://www.haskell.org/ghc/)
* [ghc-mod](https://github.com/DanielG/ghc-mod) * [ghc-mod](https://github.com/DanielG/ghc-mod)
* [hdevtools](https://hackage.haskell.org/package/hdevtools) * [hdevtools](https://hackage.haskell.org/package/hdevtools)

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