Merge pull request #3519 from atsuya/feature/support-vala-lint

Add support for Vala-Lint
This commit is contained in:
Horacio Sanson 2021-01-23 01:24:24 +09:00 committed by GitHub
commit 9a1e91e075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 0 deletions

View file

@ -0,0 +1,66 @@
" Author: Atsuya Takagi <asoftonight@gmail.com>
" Description: A linter for Vala using Vala-Lint.
call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf')
call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint')
function! ale_linters#vala#vala_lint#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'vala_vala_lint_executable')
endfunction
function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer)
let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename')
let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename)
if !empty(l:config_path)
let l:command .= ' -c ' . l:config_path
endif
return l:command . ' %s'
endfunction
function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(error\|warn\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
let l:output = []
for l:line in a:lines
" remove color escape sequences since vala-lint doesn't support
" output without colors
let l:cleaned_line = substitute(l:line, '\e\[[0-9;]\+[mK]', '', 'g')
let l:match = matchlist(l:cleaned_line, l:pattern)
if len(l:match) == 0
continue
endif
let l:refined_type = l:match[3] is# 'warn' ? 'W' : 'E'
let l:cleaned_text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
let l:lnum = l:match[1] + 0
let l:column = l:match[2] + 0
let l:type = l:refined_type
let l:text = l:cleaned_text
let l:code = l:match[5]
call add(l:output, {
\ 'lnum': l:lnum,
\ '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': 'stdout',
\ 'executable': function('ale_linters#vala#vala_lint#GetExecutable'),
\ 'command': function('ale_linters#vala#vala_lint#GetCommand'),
\ 'callback': 'ale_linters#vala#vala_lint#Handle',
\ 'lint_file': 1,
\})

View file

@ -505,6 +505,7 @@ Notes:
* `typecheck`
* VALA
* `uncrustify`
* `vala_lint`!!
* Verilog
* `hdl-checker`
* `iverilog`

View file

@ -8,5 +8,26 @@ uncrustify *ale-vala-uncrustify*
See |ale-c-uncrustify| for information about the available options.
===============================================================================
Vala-Lint *ale-vala-vala-lint*
g:vala_vala_lint_executable *g:vala_vala_lint_executable*
*b:vala_vala_lint_executable*
Type: |String|
Default: `'io.elementary.vala-lint'`
This variable can be set to specify a Vala-Lint executable file.
g:vala_vala_lint_config_filename *g:vala_vala_lint_config_filename*
*b:vala_vala_lint_config_filename*
Type: |String|
Default: `'vala-lint.conf'`
This variable can be set to specify a Vala-Lint config filename. When a file
with the specified name was not found or this variable was set to empty,
Vala-Lint will be executed without specifying a config filename.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -514,6 +514,7 @@ formatting.
* typecheck
* VALA
* [uncrustify](https://github.com/uncrustify/uncrustify)
* [vala_lint](https://github.com/vala-lang/vala-lint) :floppy_disk:
* Verilog
* [hdl-checker](https://pypi.org/project/hdl-checker)
* [iverilog](https://github.com/steveicarus/iverilog)

View file

@ -0,0 +1,54 @@
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': 'W',
\ },
\ {
\ '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 warn Expected space before paren space-before-paren',
\ ' 73.37 error Expected space before paren space-before-paren',
\ ])
Execute(The Vala-Lint handler should ignore unknown error types):
AssertEqual
\ [
\ {
\ '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 test Expected space before paren space-before-paren',
\ ' 73.37 error Expected space before paren space-before-paren',
\ ])