Add Yara yls support (#4886)

This adds Yara support to ALE using Avast's language server for Yara:
https://avast.github.io/yls/

A ".git" folder is used to determine the project_root so this means the
Yara rules must be in a git repo for the integration to work.

The server only have 1 optional argument (-v, --verbose). Since this is
the case, no additional configuration options are available.

---------

Co-authored-by: w0rp <w0rp@users.noreply.github.com>
This commit is contained in:
TcM1911
2025-03-11 12:18:29 +00:00
committed by GitHub
parent 0f71d4c494
commit f0c8eb4fa8
7 changed files with 64 additions and 0 deletions

18
ale_linters/yara/yls.vim Normal file
View File

@@ -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'),
\})

View File

@@ -737,6 +737,8 @@ Notes:
* `yq`
* YANG
* `yang-lsp`
* Yara
* `yls`
* Zeek
* `zeek`!!
* Zig

22
doc/ale-yara.txt Normal file
View File

@@ -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:

View File

@@ -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|

View File

@@ -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

View File

@@ -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 . '/../..')

View File

@@ -0,0 +1,5 @@
rule dummy
{
condition:
false
}