Skip to content

Commit 93dc3a6

Browse files
author
Keith Smiley
authored
Merge pull request #106 from keith/ks/ale-checkers
Add ale support
2 parents d9c641c + d609724 commit 93dc3a6

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

ale_linters/swift/swiftlint.vim

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function! ale_linters#swift#swiftlint#GetExecutable(buffer)
2+
if get(g:, 'ale_swift_swiftlint_use_defaults', 0) || filereadable('.swiftlint.yml')
3+
return 'swiftlint'
4+
endif
5+
6+
return ''
7+
endfunction
8+
9+
function! ale_linters#swift#swiftlint#Handle(buffer, lines)
10+
" Match and ignore file path (anything but ':')
11+
" Match and capture line number
12+
" Match and capture optional column number
13+
" Match and capture warning level ('error' or 'warning')
14+
" Match and capture anything in the message
15+
let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\)\?:\?\s*\(\w\+\):\s*\(.*\)$'
16+
let l:output = []
17+
18+
for l:line in a:lines
19+
let l:match = matchlist(l:line, l:pattern)
20+
21+
if len(l:match) == 0
22+
continue
23+
endif
24+
25+
let l:line_number = l:match[1]
26+
let l:column = l:match[2]
27+
let l:type = toupper(l:match[3][0])
28+
let l:text = l:match[4]
29+
30+
call add(l:output, {
31+
\ 'bufnr': a:buffer,
32+
\ 'lnum': l:line_number,
33+
\ 'vcol': 0,
34+
\ 'col': l:column,
35+
\ 'text': l:text,
36+
\ 'type': l:type,
37+
\ })
38+
endfor
39+
40+
return l:output
41+
endfunction
42+
43+
call ale#linter#Define('swift', {
44+
\ 'name': 'swiftlint',
45+
\ 'executable_callback': 'ale_linters#swift#swiftlint#GetExecutable',
46+
\ 'command': 'swiftlint lint --use-stdin',
47+
\ 'callback': 'ale_linters#swift#swiftlint#Handle',
48+
\ })

ale_linters/swift/swiftpm.vim

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
if !exists('g:ale_swift_swiftpm_executable')
2+
let g:ale_swift_swiftpm_executable = 'swift'
3+
endif
4+
5+
if !exists('g:ale_swift_swiftpm_arguments')
6+
let g:ale_swift_swiftpm_arguments = 'build'
7+
endif
8+
9+
function! ale_linters#swift#swiftpm#GetExecutable(buffer)
10+
if !filereadable('Package.swift')
11+
return ''
12+
endif
13+
14+
return g:ale_swift_swiftpm_executable
15+
endfunction
16+
17+
function! ale_linters#swift#swiftpm#GetCommand(buffer)
18+
return g:ale_swift_swiftpm_executable
19+
\ . ' '
20+
\ . g:ale_swift_swiftpm_arguments
21+
endfunction
22+
23+
function! ale_linters#swift#swiftpm#Handle(buffer, lines)
24+
" Match and ignore file path (anything but :)
25+
" Match and capture line number
26+
" Match and capture column number
27+
" Match and capture anything in the message
28+
let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\s*error:\s*\(.*\)$'
29+
let l:output = []
30+
31+
for l:line in a:lines
32+
let l:match = matchlist(l:line, l:pattern)
33+
34+
if len(l:match) == 0
35+
continue
36+
endif
37+
38+
let l:line_number = l:match[1]
39+
let l:column = l:match[2]
40+
let l:text = l:match[3]
41+
42+
call add(l:output, {
43+
\ 'bufnr': a:buffer,
44+
\ 'lnum': l:line_number,
45+
\ 'vcol': 0,
46+
\ 'col': l:column,
47+
\ 'text': l:text,
48+
\ 'type': 'E',
49+
\ })
50+
endfor
51+
52+
return l:output
53+
endfunction
54+
55+
call ale#linter#Define('swift', {
56+
\ 'name': 'swiftpm',
57+
\ 'executable_callback': 'ale_linters#swift#swiftpm#GetExecutable',
58+
\ 'command_callback': 'ale_linters#swift#swiftpm#GetCommand',
59+
\ 'callback': 'ale_linters#swift#swiftpm#Handle',
60+
\ })

0 commit comments

Comments
 (0)