Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for zeek #3952

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ale_linters/zeek/zeek.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" Author: Benjamin Bannier <[email protected]>
" 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,
\})
2 changes: 2 additions & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ Notes:
* `yamllint`
* YANG
* `yang-lsp`
* Zeek
* `zeek`!!
* Zig
* `zls`

Expand Down
23 changes: 23 additions & 0 deletions doc/ale-zeek.txt
Original file line number Diff line number Diff line change
@@ -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:

2 changes: 2 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|

Expand Down
2 changes: 2 additions & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions test/handler/test_zeek_handler.vader
Original file line number Diff line number Diff line change
@@ -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"'
\ ])
17 changes: 17 additions & 0 deletions test/linter/test_zeek.vader
Original file line number Diff line number Diff line change
@@ -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