diff options
author | rhysd <lin90162@yahoo.co.jp> | 2018-09-18 15:41:33 +0900 |
---|---|---|
committer | rhysd <lin90162@yahoo.co.jp> | 2018-09-18 17:51:00 +0900 |
commit | 532686102ef3bdf00b00340964d2dfe4bb7f875e (patch) | |
tree | bf181ab52a5cfd0558e4339c8ca0ce2bc379a48d /autoload | |
parent | ddb3e6d57acfc9081f8c6846d896542014e3024b (diff) | |
download | ale-532686102ef3bdf00b00340964d2dfe4bb7f875e.zip |
shfmt: Use Vim's indent config as default indent width
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/shfmt.vim | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/autoload/ale/fixers/shfmt.vim b/autoload/ale/fixers/shfmt.vim index fc55f425..06e8da57 100644 --- a/autoload/ale/fixers/shfmt.vim +++ b/autoload/ale/fixers/shfmt.vim @@ -5,12 +5,27 @@ 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) ? '' : ' ' . l:options) + \ . (empty(l:options) ? s:DefaultOption(a:buffer) : ' ' . l:options) \} endfunction |