Skip to content

Commit

Permalink
Allow shfmt fixer to use .editorconfig (dense-analysis#4244)
Browse files Browse the repository at this point in the history
* fix: added support for local solhint executable

* feat: added support for matching parse errors

* test: added test for solhint command callback and handler

* chore: removed command callback test

* refactor: made solhint handler structure closer to eslint

* refactor(shfmt-fixer): remove derivation of default CLI arguments
  • Loading branch information
hbarcelos authored and cyyever committed Jul 11, 2022
1 parent 5ba43e9 commit b36231b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 49 deletions.
18 changes: 2 additions & 16 deletions autoload/ale/fixers/shfmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,13 @@ scriptencoding utf-8
call ale#Set('sh_shfmt_executable', 'shfmt')
call ale#Set('sh_shfmt_options', '')

function! s:DefaultOption(buffer) abort
if getbufvar(a:buffer, '&expandtab') == 0
" Tab is used by default
return ''
endif

let l:tabsize = getbufvar(a:buffer, '&shiftwidth')

if l:tabsize == 0
let l:tabsize = getbufvar(a:buffer, '&tabstop')
endif

return ' -i ' . l:tabsize
endfunction

function! ale#fixers#shfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'sh_shfmt_executable')
let l:options = ale#Var(a:buffer, 'sh_shfmt_options')

return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? s:DefaultOption(a:buffer) : ' ' . l:options)
\ . ' -filename=%s'
\ . (empty(l:options) ? '' : ' ' . l:options)
\}
endfunction
34 changes: 1 addition & 33 deletions test/fixers/test_shfmt_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,14 @@ Execute(The shfmt callback should return 'shfmt' as default command):
\ ale#fixers#shfmt#Fix(bufnr('')).command =~# '^' . ale#Escape('shfmt'),
\ "Default command name is expected to be 'shfmt'"

Execute(The shfmt callback should return the command with no option as default when noexpandtab is set):
let g:ale_sh_shfmt_executable = 'shfmt'
let g:ale_sh_shfmt_options = ''
setlocal noexpandtab
AssertEqual
\ {
\ 'command': ale#Escape('shfmt'),
\ },
\ ale#fixers#shfmt#Fix(bufnr(''))

Execute(The shfmt callback should return the command specifying indent width by looking shiftwidth as default):
let g:ale_sh_shfmt_executable = 'shfmt'
let g:ale_sh_shfmt_options = ''
setlocal expandtab
setlocal shiftwidth=4
AssertEqual
\ {
\ 'command': ale#Escape('shfmt') . ' -i 4',
\ },
\ ale#fixers#shfmt#Fix(bufnr(''))

Execute(The shfmt callback should return the command specifying indent width by looking tabstop when shiftwidth is 0 as default):
let g:ale_sh_shfmt_executable = 'shfmt'
let g:ale_sh_shfmt_options = ''
setlocal expandtab
setlocal shiftwidth=0
setlocal tabstop=8
AssertEqual
\ {
\ 'command': ale#Escape('shfmt') . ' -i 8',
\ },
\ ale#fixers#shfmt#Fix(bufnr(''))

Execute(The shfmt executable and options should be configurable):
let g:ale_sh_shfmt_executable = 'foobar'
let g:ale_sh_shfmt_options = '--some-option'

AssertEqual
\ {
\ 'command': ale#Escape('foobar')
\ . ' -filename=%s'
\ . ' --some-option',
\ },
\ ale#fixers#shfmt#Fix(bufnr(''))

0 comments on commit b36231b

Please sign in to comment.