summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-09-20 09:30:59 +0100
committerGitHub <noreply@github.com>2018-09-20 09:30:59 +0100
commitaa5c82b1718f44d04f6dd11bc63f6eeed2089d9d (patch)
tree42ff87e4bc6a6d41d6cdd24909d88df64bdd1b0c /autoload
parent560749cf9e9d66afb7b15563b6f23eaf782a162a (diff)
parent532686102ef3bdf00b00340964d2dfe4bb7f875e (diff)
downloadale-aa5c82b1718f44d04f6dd11bc63f6eeed2089d9d.zip
Merge pull request #1932 from rhysd/shfmt-default-indent
shfmt: Use Vim's indent config as default indent width
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fixers/shfmt.vim17
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