forked from github-mirrors/ale
Solidity solc linter compatible with 0.6/0.7/0.8 (#3763)
This commit is contained in:
parent
36fcb01e05
commit
87e079a9b2
|
@ -1,34 +1,52 @@
|
||||||
" Author: Karl Bartel <karl42@gmail.com> - http://karl.berlin/
|
" Author: Karl Bartel <karl42@gmail.com> - http://karl.berlin/
|
||||||
" Description: Report solc compiler errors in Solidity code
|
" Description: Report solc compiler errors in Solidity code
|
||||||
|
|
||||||
|
call ale#Set('solidity_solc_executable', 'solc')
|
||||||
call ale#Set('solidity_solc_options', '')
|
call ale#Set('solidity_solc_options', '')
|
||||||
|
|
||||||
function! ale_linters#solidity#solc#Handle(buffer, lines) abort
|
function! ale_linters#solidity#solc#Handle(buffer, lines) abort
|
||||||
" Matches patterns like the following:
|
" Matches patterns like the following:
|
||||||
" /path/to/file/file.sol:1:10: Error: Identifier not found or not unique.
|
" Error: Expected ';' but got '('
|
||||||
let l:pattern = '\v^[^:]+:(\d+):(\d+): (Error|Warning): (.*)$'
|
" --> /path/to/file/file.sol:1:10:)
|
||||||
|
let l:pattern = '\v(Error|Warning): (.*)$'
|
||||||
|
let l:line_and_column_pattern = '\v\.sol:(\d+):(\d+):'
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
for l:line in a:lines
|
||||||
let l:isError = l:match[3] is? 'error'
|
let l:match = matchlist(l:line, l:pattern)
|
||||||
call add(l:output, {
|
|
||||||
\ 'lnum': l:match[1] + 0,
|
if len(l:match) == 0
|
||||||
\ 'col': l:match[2] + 0,
|
let l:match = matchlist(l:line, l:line_and_column_pattern)
|
||||||
\ 'text': l:match[4],
|
|
||||||
\ 'type': l:isError ? 'E' : 'W',
|
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:isError = l:match[1] is? 'Error'
|
||||||
|
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'lnum': 0,
|
||||||
|
\ 'col': 0,
|
||||||
|
\ 'text': l:match[2],
|
||||||
|
\ 'type': l:isError ? 'E' : 'W',
|
||||||
|
\})
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#solidity#solc#GetCommand(buffer) abort
|
function! ale_linters#solidity#solc#GetCommand(buffer) abort
|
||||||
return 'solc' . ale#Pad(ale#Var(a:buffer, 'solidity_solc_options')) . ' %s'
|
let l:executable = ale#Var(a:buffer, 'solidity_solc_executable')
|
||||||
|
|
||||||
|
return l:executable . ale#Pad(ale#Var(a:buffer, 'solidity_solc_options')) . ' %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('solidity', {
|
call ale#linter#Define('solidity', {
|
||||||
\ 'name': 'solc',
|
\ 'name': 'solc',
|
||||||
\ 'executable': 'solc',
|
\ 'executable': {b -> ale#Var(b, 'solidity_solc_executable')},
|
||||||
\ 'command': function('ale_linters#solidity#solc#GetCommand'),
|
\ 'command': function('ale_linters#solidity#solc#GetCommand'),
|
||||||
\ 'callback': 'ale_linters#solidity#solc#Handle',
|
\ 'callback': 'ale_linters#solidity#solc#Handle',
|
||||||
\ 'output_stream': 'stderr',
|
\ 'output_stream': 'stderr',
|
||||||
|
|
|
@ -5,6 +5,12 @@ ALE Solidity Integration *ale-solidity-options*
|
||||||
===============================================================================
|
===============================================================================
|
||||||
solc *ale-solidity-solc*
|
solc *ale-solidity-solc*
|
||||||
|
|
||||||
|
g:ale_solidity_solc_executable *g:ale_solidity_solc_executable*
|
||||||
|
*b:ale_solidity_solc_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'solc'`
|
||||||
|
|
||||||
|
Override the invoked solc binary. For truffle/hardhat binaries.
|
||||||
|
|
||||||
g:ale_solidity_solc_options *g:ale_solidity_solc_options*
|
g:ale_solidity_solc_options *g:ale_solidity_solc_options*
|
||||||
*b:ale_solidity_solc_options*
|
*b:ale_solidity_solc_options*
|
||||||
|
@ -33,4 +39,3 @@ solium *ale-solidity-solium*
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,14 @@ Execute(Check solc output parsing):
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#solidity#solc#Handle(bufnr(''), [
|
\ ale_linters#solidity#solc#Handle(bufnr(''), [
|
||||||
\ 'raiden_contracts/data/source/raiden/Token.sol:40:48: Warning: This declaration shadows an existing declaration.',
|
\ 'Warning: This declaration shadows an existing declaration.',
|
||||||
\ ' function decimals() external view returns (uint8 decimals);',
|
\ ' --> /path/to/file.sol:40:48:',
|
||||||
\ ' ^------------^',
|
\ ' |',
|
||||||
\ '/home/karl/raiden-contracts/raiden_contracts/data/source/test/OneToNInternalsTest.sol:23:16: Error: Member "getSinleSignature" not found or not visible after argument-dependent lookup in type(contract OneToN).',
|
\ '40 | function decimals() external view returns (uint8 decimals);',
|
||||||
\ ' return OneToN.getSinleSignature(signatures, i);',
|
\ ' | ^------------^',
|
||||||
\ ' ^----------------------^',
|
\ 'Error: Member "getSinleSignature" not found or not visible after argument-dependent lookup in type(contract OneToN).',
|
||||||
|
\ ' --> /path/to/file.sol:23:16: ',
|
||||||
|
\ ' | ',
|
||||||
|
\ '23 | return OneToN.getSinleSignature(signatures, i);',
|
||||||
|
\ ' | ^----------------------^',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('solidity', 'solc')
|
||||||
|
let g:ale_solidity_solc_executable = 'solc-v0.8.4+commit.c7e474f2'
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The executable command should be configurable):
|
||||||
|
AssertLinter 'solc-v0.8.4+commit.c7e474f2', 'solc-v0.8.4+commit.c7e474f2 %s'
|
||||||
|
|
||||||
|
Execute(The options should be configurable):
|
||||||
|
let g:ale_solidity_solc_options = '--foobar'
|
||||||
|
|
||||||
|
AssertLinter 'solc-v0.8.4+commit.c7e474f2', 'solc-v0.8.4+commit.c7e474f2 --foobar %s'
|
Loading…
Reference in New Issue