Add hlint refactoring as a fixer (#1836)

This commit is contained in:
Evan Borden
2018-08-23 18:23:54 -04:00
committed by w0rp
parent 2600524274
commit 707b539969
5 changed files with 57 additions and 0 deletions

View File

@@ -170,6 +170,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'Fix Haskell files with brittany.',
\ },
\ 'hlint': {
\ 'function': 'ale#fixers#hlint#Fix',
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'Refactor Haskell files with hlint.',
\ },
\ 'stylish-haskell': {
\ 'function': 'ale#fixers#stylish_haskell#Fix',
\ 'suggested_filetypes': ['haskell'],

View File

@@ -0,0 +1,16 @@
" Author: eborden <evan@evan-borden.com>
" Description: Integration of hlint refactor with ALE.
"
call ale#Set('haskell_hlint_executable', 'hlint')
function! ale#fixers#hlint#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'haskell_hlint_executable')
return {
\ 'command': ale#Escape(l:executable)
\ . ' --refactor'
\ . ' --refactor-options="--inplace"'
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@@ -67,6 +67,16 @@ g:ale_haskell_hfmt_executable *g:ale_haskell_hfmt_executable*
This variable can be changed to use a different executable for hfmt.
===============================================================================
hlint *ale-haskell-hlint*
g:ale_haskell_hlint_executable *g:ale_haskell_hlint_executable*
*b:ale_haskell_hlint_executable*
Type: |String|
Default: `'hlint'`
This variable can be changed to use a different executable for hlint.
===============================================================================
stack-build *ale-haskell-stack-build*

View File

@@ -110,6 +110,7 @@ CONTENTS *ale-contents*
cabal-ghc...........................|ale-haskell-cabal-ghc|
hdevtools...........................|ale-haskell-hdevtools|
hfmt................................|ale-haskell-hfmt|
hlint...............................|ale-haskell-hlint|
stack-build.........................|ale-haskell-stack-build|
stylish-haskell.....................|ale-haskell-stylish-haskell|
hie.................................|ale-haskell-hie|

View File

@@ -0,0 +1,25 @@
Before:
Save g:ale_haskell_hlint_executable
" Use an invalid global executable, so we don't match it.
let g:ale_haskell_hlint_executable = 'xxxinvalid'
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The hlint callback should return the correct default values):
call ale#test#SetFilename('../haskell_files/testfile.hs')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' --refactor'
\ . ' --refactor-options="--inplace"'
\ . ' %t',
\ },
\ ale#fixers#hlint#Fix(bufnr(''))