ale/ale_linters/sh/shellcheck.vim

60 lines
2.0 KiB
VimL
Raw Normal View History

2016-10-03 08:18:27 -04:00
" Author: w0rp <devw0rp@gmail.com>
" Description: This file adds support for using the shellcheck linter with
" shell scripts.
2017-10-02 12:11:54 -04:00
" This global variable can be set with a string of comma-separated error
2016-10-03 08:18:27 -04:00
" codes to exclude from shellcheck. For example:
"
" let g:ale_sh_shellcheck_exclusions = 'SC2002,SC2004'
let g:ale_sh_shellcheck_exclusions =
\ get(g:, 'ale_sh_shellcheck_exclusions', get(g:, 'ale_linters_sh_shellcheck_exclusions', ''))
2016-10-03 08:18:27 -04:00
let g:ale_sh_shellcheck_executable =
\ get(g:, 'ale_sh_shellcheck_executable', 'shellcheck')
let g:ale_sh_shellcheck_options =
\ get(g:, 'ale_sh_shellcheck_options', '')
function! ale_linters#sh#shellcheck#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'sh_shellcheck_executable')
endfunction
function! ale_linters#sh#shellcheck#GetDialectArgument(buffer) abort
let l:shell_type = ale#handlers#sh#GetShellType(a:buffer)
if !empty(l:shell_type)
return l:shell_type
endif
" If there's no hashbang, try using Vim's buffer variables.
if get(b:, 'is_bash')
return 'bash'
elseif get(b:, 'is_sh')
return 'sh'
elseif get(b:, 'is_kornshell')
return 'ksh'
endif
return ''
endfunction
function! ale_linters#sh#shellcheck#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'sh_shellcheck_options')
let l:exclude_option = ale#Var(a:buffer, 'sh_shellcheck_exclusions')
let l:dialect = ale_linters#sh#shellcheck#GetDialectArgument(a:buffer)
return ale#path#BufferCdString(a:buffer)
\ . ale#Escape(ale_linters#sh#shellcheck#GetExecutable(a:buffer))
\ . (!empty(l:dialect) ? ' -s ' . l:dialect : '')
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . (!empty(l:exclude_option) ? ' -e ' . l:exclude_option : '')
\ . ' -x -f gcc -'
endfunction
call ale#linter#Define('sh', {
2016-10-03 08:18:27 -04:00
\ 'name': 'shellcheck',
\ 'executable_callback': 'ale_linters#sh#shellcheck#GetExecutable',
\ 'command_callback': 'ale_linters#sh#shellcheck#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
2016-10-03 08:18:27 -04:00
\})