summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/cairo/starknet.vim37
-rw-r--r--doc/ale-cairo.txt15
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md2
-rw-r--r--test/handler/test_starknet_handler.vader36
-rw-r--r--test/linter/test_starknet.vader13
7 files changed, 107 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',
+\})
diff --git a/doc/ale-cairo.txt b/doc/ale-cairo.txt
new file mode 100644
index 00000000..0a78e68a
--- /dev/null
+++ b/doc/ale-cairo.txt
@@ -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'
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 8db54406..d66b9a02 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -95,6 +95,8 @@ Notes:
* `flawfinder`
* `gcc` (`cc`)
* `uncrustify`
+* Cairo
+ * `starknet`
* Chef
* `cookstyle`
* `foodcritic`!!
diff --git a/doc/ale.txt b/doc/ale.txt
index 448c937c..cabca300 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2775,6 +2775,8 @@ documented in additional help files.
cspell................................|ale-c-cspell|
flawfinder............................|ale-c-flawfinder|
uncrustify............................|ale-c-uncrustify|
+ cairo...................................|ale-cairo-options|
+ starknet..............................|ale-cairo-starknet|
chef....................................|ale-chef-options|
cookstyle.............................|ale-chef-cookstyle|
foodcritic............................|ale-chef-foodcritic|
diff --git a/supported-tools.md b/supported-tools.md
index 785c21d5..235f211e 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -104,6 +104,8 @@ formatting.
* [flawfinder](https://www.dwheeler.com/flawfinder/)
* [gcc](https://gcc.gnu.org/)
* [uncrustify](https://github.com/uncrustify/uncrustify)
+* Cairo
+ * [starknet](https://starknet.io/docs)
* Chef
* [cookstyle](https://docs.chef.io/cookstyle.html)
* [foodcritic](http://www.foodcritic.io/) :floppy_disk:
diff --git a/test/handler/test_starknet_handler.vader b/test/handler/test_starknet_handler.vader
new file mode 100644
index 00000000..767cb211
--- /dev/null
+++ b/test/handler/test_starknet_handler.vader
@@ -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',
+ \ ' ^*^',
+ \ ])
diff --git a/test/linter/test_starknet.vader b/test/linter/test_starknet.vader
new file mode 100644
index 00000000..368ab702
--- /dev/null
+++ b/test/linter/test_starknet.vader
@@ -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'