]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/lua/luacheck.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / lua / luacheck.vim
1 " Author: Sol Bekic https://github.com/s-ol
2 " Description: luacheck linter for lua files
3
4 call ale#Set('lua_luacheck_executable', 'luacheck')
5 call ale#Set('lua_luacheck_options', '')
6
7 function! s:IsInRuntimepath(buffer) abort
8     let l:runtimepath_dirs = split(&runtimepath, ',')
9
10     for l:dir in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
11         for l:runtime_dir in l:runtimepath_dirs
12             if l:dir is# l:runtime_dir
13                 return 1
14             endif
15         endfor
16     endfor
17
18     return 0
19 endfunction
20
21 function! ale_linters#lua#luacheck#GetCommand(buffer) abort
22     let l:options = ale#Var(a:buffer, 'lua_luacheck_options')
23
24     " Add `--globals vim` by default if the file is in runtimepath.
25     if l:options !~# '--globals'
26         let l:in_runtime = getbufvar(a:buffer, 'ale_in_runtimepath', v:null)
27
28         if l:in_runtime is v:null
29             let l:in_runtime = s:IsInRuntimepath(a:buffer)
30             " Save the result of check this buffer so we only check once.
31             call setbufvar(a:buffer, 'ale_in_runtimepath', l:in_runtime)
32         endif
33
34         if l:in_runtime
35             if !empty(l:options)
36                 let l:options .= ' '
37             endif
38
39             let l:options .= '--globals vim'
40         endif
41     endif
42
43     return '%e' . ale#Pad(l:options)
44     \   . ' --formatter plain --codes --filename %s -'
45 endfunction
46
47 function! ale_linters#lua#luacheck#Handle(buffer, lines) abort
48     " Matches patterns line the following:
49     "
50     " artal.lua:159:17: (W111) shadowing definition of loop variable 'i' on line 106
51     " artal.lua:182:7: (W213) unused loop variable 'i'
52     let l:pattern = '^.*:\(\d\+\):\(\d\+\): (\([WE]\)\(\d\+\)) \(.\+\)$'
53     let l:output = []
54
55     for l:match in ale#util#GetMatches(a:lines, l:pattern)
56         if !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
57         \   && l:match[3] is# 'W'
58         \   && index(range(611, 614), str2nr(l:match[4])) >= 0
59             continue
60         endif
61
62         call add(l:output, {
63         \   'lnum': l:match[1] + 0,
64         \   'col': l:match[2] + 0,
65         \   'type': l:match[3],
66         \   'code': l:match[3] . l:match[4],
67         \   'text': l:match[5],
68         \})
69     endfor
70
71     return l:output
72 endfunction
73
74 call ale#linter#Define('lua', {
75 \   'name': 'luacheck',
76 \   'executable': {b -> ale#Var(b, 'lua_luacheck_executable')},
77 \   'command': function('ale_linters#lua#luacheck#GetCommand'),
78 \   'callback': 'ale_linters#lua#luacheck#Handle',
79 \})