cairo support (#4256)

* cairo support

* supported languages txt

* add cairo to ale.txt
This commit is contained in:
0xHyoga 2022-07-22 06:05:08 +02:00 committed by GitHub
parent 5ef26c32da
commit 0ea53870b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 0 deletions

View File

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

15
doc/ale-cairo.txt Normal file
View File

@ -0,0 +1,15 @@
===============================================================================
ALE Cairo Integration *ale-cairo-options*
===============================================================================
starknet *ale-cairo-starknet*
g:ale_cairo_starknet_executable *g:ale_cairo_starknet_executable*
*b:ale_cairo_starknet_executable*
Default: `'starknet-compile'`
Overrides the starknet-compile binary after installing the cairo-language.
For more information read 'https://starknet.io/docs/quickstart.html'

View File

@ -95,6 +95,8 @@ Notes:
* `flawfinder` * `flawfinder`
* `gcc` (`cc`) * `gcc` (`cc`)
* `uncrustify` * `uncrustify`
* Cairo
* `starknet`
* Chef * Chef
* `cookstyle` * `cookstyle`
* `foodcritic`!! * `foodcritic`!!

View File

@ -2775,6 +2775,8 @@ documented in additional help files.
cspell................................|ale-c-cspell| cspell................................|ale-c-cspell|
flawfinder............................|ale-c-flawfinder| flawfinder............................|ale-c-flawfinder|
uncrustify............................|ale-c-uncrustify| uncrustify............................|ale-c-uncrustify|
cairo...................................|ale-cairo-options|
starknet..............................|ale-cairo-starknet|
chef....................................|ale-chef-options| chef....................................|ale-chef-options|
cookstyle.............................|ale-chef-cookstyle| cookstyle.............................|ale-chef-cookstyle|
foodcritic............................|ale-chef-foodcritic| foodcritic............................|ale-chef-foodcritic|

View File

@ -104,6 +104,8 @@ formatting.
* [flawfinder](https://www.dwheeler.com/flawfinder/) * [flawfinder](https://www.dwheeler.com/flawfinder/)
* [gcc](https://gcc.gnu.org/) * [gcc](https://gcc.gnu.org/)
* [uncrustify](https://github.com/uncrustify/uncrustify) * [uncrustify](https://github.com/uncrustify/uncrustify)
* Cairo
* [starknet](https://starknet.io/docs)
* Chef * Chef
* [cookstyle](https://docs.chef.io/cookstyle.html) * [cookstyle](https://docs.chef.io/cookstyle.html)
* [foodcritic](http://www.foodcritic.io/) :floppy_disk: * [foodcritic](http://www.foodcritic.io/) :floppy_disk:

View File

@ -0,0 +1,36 @@
Before:
runtime ale_linters/cairo/starknet.vim
After:
call ale#linter#Reset()
Execute(The starknet handler should handle error messages correctly):
AssertEqual
\ [
\ {
\ 'lnum': 3,
\ 'col': 6,
\ 'text': 'Could not find module "starkware.cairo.commo.cairo_builtins". Searched in the following paths:',
\ 'type': 'E',
\ },
\ ],
\ ale_linters#cairo#starknet#Handle(bufnr(''), [
\ 'contract.cairo:3:6: Could not find module "starkware.cairo.commo.cairo_builtins". Searched in the following paths:',
\ 'from starkware.cairo.commo.cairo_builtins import HashBuiltin',
\ ' ^**********************************^',
\ ])
AssertEqual
\ [
\ {
\ 'lnum': 21,
\ 'col': 2,
\ 'text': 'Unsupported decorator: "vie".',
\ 'type': 'E',
\ },
\ ],
\ ale_linters#cairo#starknet#Handle(bufnr(''), [
\ 'contract.cairo:21:2: Unsupported decorator: "vie".',
\ '@vie',
\ ' ^*^',
\ ])

View File

@ -0,0 +1,13 @@
Before:
call ale#assert#SetUpLinterTest('cairo', 'starknet')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct):
AssertLinter 'starknet-compile', 'starknet-compile %s'
Execute(Extra options should be supported):
let g:ale_cairo_starknet_options = '--config'
AssertLinter 'starknet-compile', 'starknet-compile --config %s'