mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Support for Zlint as Zig linter (#4923)
* feat: Add Zig zlint linter and handler for ALE * docs: Add zlint documentation to ALE Zig integration guide * docs: Updating docs for zlint support * tests: Adding tests for checking zlint executable and command * refactor: Move zlint configuration test to separate test file
This commit is contained in:
committed by
GitHub
parent
c4cedeea3f
commit
59c996c5b8
34
ale_linters/zig/zlint.vim
Normal file
34
ale_linters/zig/zlint.vim
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
" Author: Don Isaac
|
||||||
|
" Description: A linter for the Zig programming language
|
||||||
|
|
||||||
|
call ale#Set('zig_zlint_executable', 'zlint')
|
||||||
|
|
||||||
|
function! ale_linters#zig#zlint#Handle(buffer, lines) abort
|
||||||
|
" GitHub Actions format: ::severity file=file,line=line,col=col,title=code::message
|
||||||
|
let l:pattern = '::\([a-z]\+\) file=\([^,]\+\),line=\(\d\+\),col=\(\d\+\),title=\([^:]\+\)::\(.*\)'
|
||||||
|
let l:output = []
|
||||||
|
|
||||||
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'filename': l:match[2],
|
||||||
|
\ 'lnum': str2nr(l:match[3]),
|
||||||
|
\ 'col': str2nr(l:match[4]),
|
||||||
|
\ 'text': l:match[6],
|
||||||
|
\ 'type': l:match[1] =~? 'error\|fail' ? 'E' : 'W',
|
||||||
|
\ 'code': l:match[5],
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:output
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#zig#zlint#GetCommand(buffer) abort
|
||||||
|
return ale#Escape(ale#Var(a:buffer, 'zig_zlint_executable')) . ' %s -f gh'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('zig', {
|
||||||
|
\ 'name': 'zlint',
|
||||||
|
\ 'executable': {b -> ale#Var(b, "zig_zlint_executable")},
|
||||||
|
\ 'command': function('ale_linters#zig#zlint#GetCommand'),
|
||||||
|
\ 'callback': 'ale_linters#zig#zlint#Handle',
|
||||||
|
\})
|
||||||
@@ -758,6 +758,7 @@ Notes:
|
|||||||
* `zeek`!!
|
* `zeek`!!
|
||||||
* Zig
|
* Zig
|
||||||
* `zigfmt`
|
* `zigfmt`
|
||||||
|
* `zlint`
|
||||||
* `zls`
|
* `zls`
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ ALE Zig Integration *ale-zig-options*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
Integration Information
|
Integration Information
|
||||||
|
|
||||||
Currently, the only supported linter for zig is zls.
|
The following linters are supported for Zig:
|
||||||
|
|
||||||
|
* zlint (https://github.com/DonIsaac/zlint)
|
||||||
|
* zls (https://github.com/zigtools/zls)
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
@@ -19,6 +22,16 @@ g:ale_zig_zigfmt_executable *g:ale_zig_zigfmt_executable*
|
|||||||
The executable that will be run for the `zig fmt` fixer.
|
The executable that will be run for the `zig fmt` fixer.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
zlint *ale-zig-zlint*
|
||||||
|
|
||||||
|
g:ale_zig_zlint_executable *g:ale_zig_zlint_executable*
|
||||||
|
*b:ale_zig_zlint_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'zlint'`
|
||||||
|
|
||||||
|
This variable can be modified to change the executable path for `zlint`.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
zls *ale-zig-zls*
|
zls *ale-zig-zls*
|
||||||
|
|
||||||
|
|||||||
@@ -3546,6 +3546,7 @@ documented in additional help files.
|
|||||||
zeek..................................|ale-zeek-zeek|
|
zeek..................................|ale-zeek-zeek|
|
||||||
zig.....................................|ale-zig-options|
|
zig.....................................|ale-zig-options|
|
||||||
zigfmt................................|ale-zig-zigfmt|
|
zigfmt................................|ale-zig-zigfmt|
|
||||||
|
zlint.................................|ale-zig-zlint|
|
||||||
zls...................................|ale-zig-zls|
|
zls...................................|ale-zig-zls|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -767,4 +767,5 @@ formatting.
|
|||||||
* [zeek](http://zeek.org) :floppy_disk:
|
* [zeek](http://zeek.org) :floppy_disk:
|
||||||
* Zig
|
* Zig
|
||||||
* [zigfmt](https://github.com/ziglang/zig)
|
* [zigfmt](https://github.com/ziglang/zig)
|
||||||
|
* [zlint](https://github.com/DonIsaac/zlint)
|
||||||
* [zls](https://github.com/zigtools/zls)
|
* [zls](https://github.com/zigtools/zls)
|
||||||
|
|||||||
44
test/handler/test_zlint_handler.vader
Normal file
44
test/handler/test_zlint_handler.vader
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
Before:
|
||||||
|
runtime ale_linters/zig/zlint.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(The zlint handler should parse GitHub Actions format correctly):
|
||||||
|
" Create a temporary buffer
|
||||||
|
let buffer = bufnr('')
|
||||||
|
|
||||||
|
" Define input lines
|
||||||
|
let input_lines = [
|
||||||
|
\ '::warning file=test.zig,line=61,col=47,title=unsafe-undefined::`undefined` is missing a safety comment',
|
||||||
|
\ '',
|
||||||
|
\ '::error file=test2.zig,line=4,col=33,title=no-unresolved::Unresolved import to ''test3.zig''',
|
||||||
|
\ '',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
" Define expected output
|
||||||
|
let expected_output = [
|
||||||
|
\ {
|
||||||
|
\ 'filename': 'test.zig',
|
||||||
|
\ 'lnum': 61,
|
||||||
|
\ 'col': 47,
|
||||||
|
\ 'text': '`undefined` is missing a safety comment',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'code': 'unsafe-undefined'
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'filename': 'test2.zig',
|
||||||
|
\ 'lnum': 4,
|
||||||
|
\ 'col': 33,
|
||||||
|
\ 'text': 'Unresolved import to ''test3.zig''',
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'code': 'no-unresolved'
|
||||||
|
\ },
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
" Get actual output
|
||||||
|
let actual_output = ale_linters#zig#zlint#Handle(buffer, input_lines)
|
||||||
|
|
||||||
|
" Assert equality
|
||||||
|
AssertEqual expected_output, actual_output
|
||||||
|
|
||||||
19
test/linter/test_zig_zlint.vader
Normal file
19
test/linter/test_zig_zlint.vader
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('zig', 'zlint')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The zlint executable and command should be configured correctly):
|
||||||
|
" Set a custom executable path
|
||||||
|
let g:ale_zig_zlint_executable = '/custom/path/to/zlint'
|
||||||
|
|
||||||
|
" Create a buffer with Zig filetype
|
||||||
|
call ale#test#SetFilename('test.zig')
|
||||||
|
|
||||||
|
" Check the executable
|
||||||
|
AssertEqual '/custom/path/to/zlint', ale#Var(bufnr(''), 'zig_zlint_executable')
|
||||||
|
|
||||||
|
" Check the command
|
||||||
|
let cmd = ale_linters#zig#zlint#GetCommand(bufnr(''))
|
||||||
|
AssertEqual ale#Escape('/custom/path/to/zlint') . ' %s -f gh', cmd
|
||||||
Reference in New Issue
Block a user