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.
1 " Author: Sol Bekic https://github.com/s-ol
2 " Description: luacheck linter for lua files
4 call ale#Set('lua_luacheck_executable', 'luacheck')
5 call ale#Set('lua_luacheck_options', '')
7 function! s:IsInRuntimepath(buffer) abort
8 let l:runtimepath_dirs = split(&runtimepath, ',')
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
21 function! ale_linters#lua#luacheck#GetCommand(buffer) abort
22 let l:options = ale#Var(a:buffer, 'lua_luacheck_options')
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)
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)
39 let l:options .= '--globals vim'
43 return '%e' . ale#Pad(l:options)
44 \ . ' --formatter plain --codes --filename %s -'
47 function! ale_linters#lua#luacheck#Handle(buffer, lines) abort
48 " Matches patterns line the following:
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\+\)) \(.\+\)$'
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
63 \ 'lnum': l:match[1] + 0,
64 \ 'col': l:match[2] + 0,
66 \ 'code': l:match[3] . l:match[4],
74 call ale#linter#Define('lua', {
76 \ 'executable': {b -> ale#Var(b, 'lua_luacheck_executable')},
77 \ 'command': function('ale_linters#lua#luacheck#GetCommand'),
78 \ 'callback': 'ale_linters#lua#luacheck#Handle',