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: David Mohundro <david@mohundro.com>, Gordon Fontenot <gordon@fonten.io>
2 " Description: swiftlint for swift files
4 call ale#Set('swift_swiftlint_executable', 'swiftlint')
5 call ale#Set('swift_swiftlint_use_global', get(g:, 'ale_use_global_executables', 0))
7 function! ale_linters#swift#swiftlint#GetExecutable(buffer) abort
8 return ale#path#FindExecutable(a:buffer, 'swift_swiftlint', [
9 \ 'Pods/SwiftLint/swiftlint',
10 \ 'ios/Pods/SwiftLint/swiftlint',
15 function! ale_linters#swift#swiftlint#GetCommand(buffer) abort
16 let l:executable = ale_linters#swift#swiftlint#GetExecutable(a:buffer)
17 let l:args = 'lint --use-stdin'
19 return ale#Escape(l:executable)
23 function! ale_linters#swift#swiftlint#Handle(buffer, lines) abort
24 let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
27 for l:match in ale#util#GetMatches(a:lines, l:pattern)
29 \ 'lnum': str2nr(l:match[2]),
30 \ 'type': l:match[4] is# 'error' ? 'E' : 'W',
34 if l:match[4] is# 'error'
36 elseif l:match[4] is# 'note'
41 let l:item.col = str2nr(l:match[3])
44 " If the filename is something like <stdin>, <nofile> or -, then
45 " this is an error for the file we checked.
46 if l:match[1] isnot# '-' && l:match[1][0] isnot# '<'
47 let l:item['filename'] = l:match[1]
50 " Parse the code if it's there.
51 let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^ (]+)\)$')
53 if !empty(l:code_match)
54 let l:item.text = l:code_match[1]
55 let l:item.code = l:code_match[2]
58 call add(l:output, l:item)
64 call ale#linter#Define('swift', {
65 \ 'name': 'swiftlint',
66 \ 'executable': function('ale_linters#swift#swiftlint#GetExecutable'),
67 \ 'command': function('ale_linters#swift#swiftlint#GetCommand'),
68 \ 'callback': 'ale_linters#swift#swiftlint#Handle',