add initial files
This commit is contained in:
parent
a1e6df987c
commit
4ed520a219
2 changed files with 81 additions and 0 deletions
44
ale_linters/vala/vala_lint.vim
Normal file
44
ale_linters/vala/vala_lint.vim
Normal file
|
@ -0,0 +1,44 @@
|
|||
" Author: Atsuya Takagi <asoftonight@gmail.com>
|
||||
" Description: A linter for Vala using Vala-Lint.
|
||||
|
||||
function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
|
||||
return 'io.elementary.vala-lint'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
|
||||
let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
|
||||
let l:output = []
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if len(l:match) == 0
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:line = l:match[1] + 0
|
||||
let l:column = l:match[2] + 0
|
||||
let l:type = 'E'
|
||||
let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
let l:code = l:match[5]
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:line,
|
||||
\ 'col': l:column,
|
||||
\ 'text': l:text,
|
||||
\ 'type': l:type,
|
||||
\ 'code': l:code,
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('vala', {
|
||||
\ 'name': 'vala-lint',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'executable': 'io.elementary.vala-lint',
|
||||
\ 'command': function('ale_linters#vala#vala_lint#GetCommand'),
|
||||
\ 'callback': 'ale_linters#vala#vala_lint#Handle',
|
||||
\ 'lint_file': 1,
|
||||
\})
|
37
test/handler/test_vala_lint_handler.vader
Normal file
37
test/handler/test_vala_lint_handler.vader
Normal file
|
@ -0,0 +1,37 @@
|
|||
Before:
|
||||
runtime ale_linters/vala/vala_lint.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The Vala-Lint handler should parse lines correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 18,
|
||||
\ 'col': 18,
|
||||
\ 'text': 'Expected space before paren',
|
||||
\ 'code': 'space-before-paren',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 64,
|
||||
\ 'col': 37,
|
||||
\ 'text': 'Expected space before paren',
|
||||
\ 'code': 'space-before-paren',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 73,
|
||||
\ 'col': 37,
|
||||
\ 'text': 'Expected space before paren',
|
||||
\ 'code': 'space-before-paren',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#vala#vala_lint#Handle(bufnr(''), [
|
||||
\ 'Application.vala',
|
||||
\ ' 18.18 error Expected space before paren space-before-paren',
|
||||
\ ' 64.37 error Expected space before paren space-before-paren',
|
||||
\ ' 73.37 error Expected space before paren space-before-paren',
|
||||
\ ])
|
Reference in a new issue