mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Add hlint refactoring as a fixer (#1836)
This commit is contained in:
@@ -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'],
|
||||
|
||||
16
autoload/ale/fixers/hlint.vim
Normal file
16
autoload/ale/fixers/hlint.vim
Normal 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
|
||||
@@ -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*
|
||||
|
||||
|
||||
@@ -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|
|
||||
|
||||
25
test/fixers/test_hlint_fixer_callback.vader
Normal file
25
test/fixers/test_hlint_fixer_callback.vader
Normal 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(''))
|
||||
Reference in New Issue
Block a user