aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.vim/autoload/neomake/makers/ft/sh.vim
blob: 00889b91eeca932b75f0b2ac9b2d11fe355ef256 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
" vim: ts=4 sw=4 et

function! neomake#makers#ft#sh#EnabledMakers() abort
    return ['sh', 'shellcheck']
endfunction

let s:shellcheck = {
        \ 'args': ['-fgcc', '-x'],
        \ 'errorformat':
            \ '%f:%l:%c: %trror: %m [SC%n],' .
            \ '%f:%l:%c: %tarning: %m [SC%n],' .
            \ '%I%f:%l:%c: Note: %m [SC%n]',
        \ 'output_stream': 'stdout',
        \ 'short_name': 'SC',
        \ 'cwd': '%:h',
        \ }

function! neomake#makers#ft#sh#shellcheck() abort
    let maker = deepcopy(s:shellcheck)

    let line1 = getline(1)
    if match(line1, '\v^#!.*<%(sh|dash|bash|ksh)') < 0
                \ && match(line1, '\v^#\s*shellcheck\s+shell\=') < 0
        " shellcheck does not read the shebang by itself.
        let ext = expand('%:e')
        if ext ==# 'ksh'
            let maker.args += ['-s', 'ksh']
        elseif ext ==# 'sh'
            if exists('g:is_sh')
                let maker.args += ['-s', 'sh']
            elseif exists('g:is_posix') || exists('g:is_kornshell')
                let maker.args += ['-s', 'ksh']
            else
                let maker.args += ['-s', 'bash']
            endif
        else
            let maker.args += ['-s', 'bash']
        endif
    endif
    return maker
endfunction

function! neomake#makers#ft#sh#checkbashisms() abort
    return {
        \ 'args': ['-fx'],
        \ 'errorformat':
            \ '%-Gscript %f is already a bash script; skipping,' .
            \ '%Eerror: %f: %m\, opened in line %l,' .
            \ '%Eerror: %f: %m,' .
            \ '%Ecannot open script %f for reading: %m,' .
            \ '%Wscript %f %m,%C%.# lines,' .
            \ '%Wpossible bashism in %f line %l (%m):,%C%.%#,%Z.%#,' .
            \ '%-G%.%#',
        \ 'output_stream': 'stderr',
        \ }
endfunction

function! neomake#makers#ft#sh#sh() abort
    let shebang = matchstr(getline(1), '^#!\s*\zs.*$')
    if !empty(shebang)
        let l = split(shebang)
        let exe = l[0]
        let args = l[1:] + ['-n']
    else
        let exe = '/usr/bin/env'
        let args = ['sh', '-n']
    endif

    " NOTE: the format without "line" is used by dash.
    return {
        \ 'exe': exe,
        \ 'args': args,
        \ 'errorformat':
            \ '%E%f: line %l: %m,' .
            \ '%E%f: %l: %m',
        \ 'output_stream': 'stderr',
        \}
endfunction

function! neomake#makers#ft#sh#dash() abort
    return {
        \ 'args': ['-n'],
        \ 'errorformat': '%E%f: %l: %m',
        \ 'output_stream': 'stderr',
        \}
endfunction