Add support for zeek (#3952)

This commit is contained in:
Benjamin Bannier 2021-10-24 14:05:55 +02:00 committed by GitHub
parent da331acc9e
commit 92f08b5af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 0 deletions

22
ale_linters/zeek/zeek.vim Normal file
View File

@ -0,0 +1,22 @@
" Author: Benjamin Bannier <bbannier@gmail.com>
" Description: Support for checking Zeek files.
"
call ale#Set('zeek_zeek_executable', 'zeek')
function! ale_linters#zeek#zeek#HandleErrors(buffer, lines) abort
let l:pattern = 'error in \v.*, line (\d+): (.*)$'
return map(ale#util#GetMatches(a:lines, l:pattern), "{
\ 'lnum': str2nr(v:val[1]),
\ 'text': v:val[2],
\}")
endfunction
call ale#linter#Define('zeek', {
\ 'name': 'zeek',
\ 'executable': {b -> ale#Var(b, 'zeek_zeek_executable')},
\ 'output_stream': 'stderr',
\ 'command': {-> '%e --parse-only %s'},
\ 'callback': 'ale_linters#zeek#zeek#HandleErrors',
\ 'lint_file': 1,
\})

View File

@ -601,6 +601,8 @@ Notes:
* `yamllint`
* YANG
* `yang-lsp`
* Zeek
* `zeek`!!
* Zig
* `zls`

23
doc/ale-zeek.txt Normal file
View File

@ -0,0 +1,23 @@
===============================================================================
ALE Zeek Integration *ale-zeek-options*
*ale-integration-zeek*
===============================================================================
Integration Information
Currently, the only supported linter for Zeek is zeek.
===============================================================================
zeek *ale-zeek-zeek*
g:ale_zeek_zeek_executable *g:ale_zeek_zeek_executable*
*b:ale_zeek_zeek_executable*
Type: |String|
Default: `'zeek'`
This variable can be modified to change the executable path for `zeek`.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -3114,6 +3114,8 @@ documented in additional help files.
yamllint..............................|ale-yaml-yamllint|
yang....................................|ale-yang-options|
yang-lsp..............................|ale-yang-lsp|
zeek....................................|ale-zeek-options|
zeek..................................|ale-zeek-zeek|
zig.....................................|ale-zig-options|
zls...................................|ale-zig-zls|

View File

@ -610,5 +610,7 @@ formatting.
* [yamllint](https://yamllint.readthedocs.io/)
* YANG
* [yang-lsp](https://github.com/theia-ide/yang-lsp)
* Zeek
* [zeek](http://zeek.org) :floppy_disk:
* Zig
* [zls](https://github.com/zigtools/zls)

View File

@ -0,0 +1,17 @@
Before:
runtime ale_linters/zeek/zeek.vim
After:
call ale#linter#Reset()
Execute(The zeek handler should parse input correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'text': 'unknown identifier bar, at or near "bar"'
\ },
\ ],
\ ale_linters#zeek#zeek#HandleErrors(bufnr(''), [
\ 'error in /tmp/foo.zeek, line 2: unknown identifier bar, at or near "bar"'
\ ])

View File

@ -0,0 +1,17 @@
Before:
call ale#assert#SetUpLinterTest('zeek', 'zeek')
let b:command_tail = ' --parse-only %s'
After:
call ale#assert#TearDownLinterTest()
unlet! b:command_tail
Execute(The default command should be correct):
AssertLinter 'zeek', ale#Escape('zeek') . b:command_tail
Execute(The zeek executable should be configurable, and escaped properly):
let g:ale_zeek_zeek_executable = 'executable with spaces'
AssertLinter 'executable with spaces', ale#Escape('executable with spaces') . b:command_tail