diff options
Diffstat (limited to 'ale_linters/cairo/starknet.vim')
-rw-r--r-- | ale_linters/cairo/starknet.vim | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ale_linters/cairo/starknet.vim b/ale_linters/cairo/starknet.vim new file mode 100644 index 00000000..990bda6d --- /dev/null +++ b/ale_linters/cairo/starknet.vim @@ -0,0 +1,37 @@ +" Author: 0xHyoga <0xHyoga@gmx.com> +" Description: Report starknet-compile errors in cairo code + +call ale#Set('cairo_starknet_executable', 'starknet-compile') +call ale#Set('cairo_starknet_options', '') + +function! ale_linters#cairo#starknet#Handle(buffer, lines) abort + " Error always on the first line + " e.g ex01.cairo:20:6: Could not find module 'contracts.utils.ex00_base'. Searched in the following paths: + let l:pattern = '\v\.cairo:(\d+):(\d+):+ (.*)' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': str2nr(l:match[1]), + \ 'col': str2nr(l:match[2]), + \ 'type': 'E', + \ 'text': l:match[3], + \}) + endfor + + return l:output +endfunction + +function! ale_linters#cairo#starknet#GetCommand(buffer) abort + let l:executable = ale#Var(a:buffer, 'cairo_starknet_executable') + + return l:executable . ale#Pad(ale#Var(a:buffer, 'cairo_starknet_options')) . ' %s' +endfunction + +call ale#linter#Define('cairo', { +\ 'name': 'starknet', +\ 'executable': {b -> ale#Var(b, 'cairo_starknet_executable')}, +\ 'command': function('ale_linters#cairo#starknet#GetCommand'), +\ 'callback': 'ale_linters#cairo#starknet#Handle', +\ 'output_stream': 'stderr', +\}) |