diff --git a/ale_linters/yara/yls.vim b/ale_linters/yara/yls.vim new file mode 100644 index 00000000..d8371a25 --- /dev/null +++ b/ale_linters/yara/yls.vim @@ -0,0 +1,18 @@ +" Author: TcM1911 +" Description: A language server for Yara. + +call ale#Set('yara_yls_executable', 'yls') + +function! ale_linters#yara#yls#FindProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git') + + return !empty(l:project_root) ? (ale#path#Upwards(l:project_root)[1]) : '' +endfunction + +call ale#linter#Define('yara', { +\ 'name': 'yls', +\ 'lsp': 'stdio', +\ 'executable': {b -> ale#Var(b, 'yara_yls_executable')}, +\ 'command': '%e -v', +\ 'project_root': function('ale_linters#yara#yls#FindProjectRoot'), +\}) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index d5f3d9f0..fb6219a6 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -737,6 +737,8 @@ Notes: * `yq` * YANG * `yang-lsp` +* Yara + * `yls` * Zeek * `zeek`!! * Zig diff --git a/doc/ale-yara.txt b/doc/ale-yara.txt new file mode 100644 index 00000000..6dd4abbe --- /dev/null +++ b/doc/ale-yara.txt @@ -0,0 +1,22 @@ +=============================================================================== +ALE Yara Integration *ale-yara-options* + *ale-integration-yara* + +=============================================================================== +Integration Information + + Currently, the only supported linter for yara is yls. + + +=============================================================================== +yls *ale-yara-yls* + +g:ale_yara_yls_executable *g:ale_yara_yls_executable* + *b:ale_yara_yls_executable* + Type: |String| + Default: `'yls'` + + This variable can be modified to change the executable path for `yls`. + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index b0154f59..302fbfa2 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3525,6 +3525,8 @@ documented in additional help files. yq....................................|ale-yaml-yq| yang....................................|ale-yang-options| yang-lsp..............................|ale-yang-lsp| + yara....................................|ale-yara-options| + yls...................................|ale-yara-yls| zeek....................................|ale-zeek-options| zeek..................................|ale-zeek-zeek| zig.....................................|ale-zig-options| diff --git a/supported-tools.md b/supported-tools.md index 60ae27be..d6477687 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -746,6 +746,8 @@ formatting. * [yq](https://github.com/mikefarah/yq) * YANG * [yang-lsp](https://github.com/theia-ide/yang-lsp) +* Yara + * [yls](https://github.com/avast/yls) * Zeek * [zeek](http://zeek.org) :floppy_disk: * Zig diff --git a/test/linter/test_yara_yls.vader b/test/linter/test_yara_yls.vader new file mode 100644 index 00000000..a59ab3c7 --- /dev/null +++ b/test/linter/test_yara_yls.vader @@ -0,0 +1,13 @@ +Before: + call ale#assert#SetUpLinterTest('yara', 'yls') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default executable path should be correct): + AssertLinter 'yls', ale#Escape('yls') . ' -v' + +Execute(The project root should be detected correctly): + call ale#test#SetFilename('../test-files/yara/dummy.yar') + + AssertLSPProject ale#path#Simplify(g:dir . '/../..') diff --git a/test/test-files/yara/dummy.yar b/test/test-files/yara/dummy.yar new file mode 100644 index 00000000..eb1e9359 --- /dev/null +++ b/test/test-files/yara/dummy.yar @@ -0,0 +1,5 @@ +rule dummy +{ + condition: + false +}