forked from dense-analysis/ale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Scarb in
cairo
files (dense-analysis#4669)
* Add support for Scarb in `cairo` files * specify if linter should run on saved
- Loading branch information
1 parent
32ee703
commit 7171872
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
" Author: 0xhyoga <[email protected]>, | ||
" Description: scarb for cairo files | ||
|
||
function! ale_linters#cairo#scarb#GetScarbExecutable(bufnr) abort | ||
if ale#path#FindNearestFile(a:bufnr, 'Scarb.toml') isnot# '' | ||
return 'scarb' | ||
else | ||
" if there is no Scarb.toml file, we don't use scarb even if it exists, | ||
" so we return '', because executable('') apparently always fails | ||
return '' | ||
endif | ||
endfunction | ||
|
||
function! ale_linters#cairo#scarb#GetCommand(buffer, version) abort | ||
return 'scarb build' | ||
endfunction | ||
|
||
call ale#linter#Define('cairo', { | ||
\ 'name': 'scarb', | ||
\ 'executable': function('ale_linters#cairo#scarb#GetScarbExecutable'), | ||
\ 'command': {buffer -> ale#semver#RunWithVersionCheck( | ||
\ buffer, | ||
\ ale_linters#cairo#scarb#GetScarbExecutable(buffer), | ||
\ '%e --version', | ||
\ function('ale_linters#cairo#scarb#GetCommand'), | ||
\ )}, | ||
\ 'callback': 'ale#handlers#cairo#HandleCairoErrors', | ||
\ 'output_stream': 'both', | ||
\ 'lint_file': 1, | ||
\}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
" Author: 0xhyoga <[email protected]>, | ||
" Description: This file implements handlers specific to Cairo | ||
" | ||
function! ale#handlers#cairo#HandleCairoErrors(buffer, lines) abort | ||
" Matches patterns like the following: | ||
" Error: Expected ';' but got '(' | ||
" --> /path/to/file/file.cairo:1:10:) | ||
let l:pattern = '\v(error|warning): (.*)$' | ||
let l:line_and_column_pattern = '\v\.cairo:(\d+):(\d+)' | ||
let l:exclude_pattern = '\vcould not compile.*' | ||
let l:output = [] | ||
|
||
for l:line in a:lines | ||
let l:match = matchlist(l:line, l:pattern) | ||
|
||
if len(l:match) == 0 | ||
let l:match = matchlist(l:line, l:line_and_column_pattern) | ||
|
||
if len(l:match) > 0 | ||
let l:index = len(l:output) - 1 | ||
let l:output[l:index]['lnum'] = l:match[1] + 0 | ||
let l:output[l:index]['col'] = l:match[2] + 0 | ||
endif | ||
else | ||
let l:text = l:match[2] | ||
|
||
if l:text !~# l:exclude_pattern | ||
let l:isError = l:match[1] is? 'Error' | ||
|
||
call add(l:output, { | ||
\ 'lnum': 0, | ||
\ 'col': 0, | ||
\ 'text': l:text, | ||
\ 'type': l:isError ? 'E' : 'W', | ||
\}) | ||
endif | ||
endif | ||
endfor | ||
|
||
return l:output | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ Notes: | |
* `gcc` (`cc`) | ||
* `uncrustify` | ||
* Cairo | ||
* `scarb`!! | ||
* `starknet` | ||
* Chef | ||
* `cookstyle` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Before: | ||
runtime ale_linters/cairo/scarb.vim | ||
|
||
After: | ||
call ale#linter#Reset() | ||
|
||
Execute(Check scarb output parsing): | ||
AssertEqual | ||
\ [ | ||
\ { | ||
\ 'lnum': 40, | ||
\ 'col': 48, | ||
\ 'text': 'Skipped tokens. Expected: Const/Module/Use/FreeFunction/ExternFunction/ExternType/Trait/Impl/Struct/Enum/TypeAlias/InlineMacro or an attribute.', | ||
\ 'type': 'E', | ||
\ }, | ||
\ ], | ||
\ ale#handlers#cairo#HandleCairoErrors(bufnr(''), [ | ||
\ 'error: Skipped tokens. Expected: Const/Module/Use/FreeFunction/ExternFunction/ExternType/Trait/Impl/Struct/Enum/TypeAlias/InlineMacro or an attribute.', | ||
\ ' --> /path/to/file.cairo:40:48', | ||
\ ]) |