All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Authors: Franco Victorio <@fvictorio>, Henrique Barcelos <@hbarcelos>
2 " Description: Report errors in Solidity code with solhint
4 call ale#Set('solidity_solhint_options', '')
5 call ale#Set('solidity_solhint_executable', 'solhint')
6 call ale#Set('solidity_solhint_use_global', get(g:, 'ale_use_global_executables', 0))
8 function! ale_linters#solidity#solhint#Handle(buffer, lines) abort
11 " Matches lines like the following:
12 " contracts/Bounty.sol:14:3: Expected indentation of 4 spaces but found 2 [Error/indent]
13 let l:lint_pattern = '\v^[^:]+:(\d+):(\d+): %(Parse error: )@<!\ze(.*)\s+\[(Error|Warning)\/([^\]]+)\]$'
15 for l:match in ale#util#GetMatches(a:lines, l:lint_pattern)
16 let l:is_error = l:match[4] is? 'error'
18 \ 'lnum': l:match[1] + 0,
19 \ 'col': l:match[2] + 0,
22 \ 'type': l:is_error ? 'E' : 'W',
26 " Matches lines like the following:
27 " contracts/Bounty.sol:203:4: Parse error: no viable alternative at input '_loserStakeMultiplier}' [Error]
28 let l:syntax_pattern = '\v^[^:]+:(\d+):(\d+): Parse error: (.*)\s+\[Error\]$'
30 for l:match in ale#util#GetMatches(a:lines, l:syntax_pattern)
32 \ 'lnum': l:match[1] + 0,
33 \ 'col': l:match[2] + 0,
35 \ 'code': 'Parse error',
44 \ 'node_modules/.bin/solhint',
45 \ 'node_modules/solhint/solhint.js',
48 let s:sep = has('win32') ? '\' : '/'
50 " Given a buffer, return an appropriate working directory for solhint.
51 function! ale_linters#solidity#solhint#GetCwd(buffer) abort
52 " If solhint is installed in a directory which contains the buffer, assume
53 " it is the solhint project root. Otherwise, use nearest node_modules.
54 " Note: If node_modules not present yet, can't load local deps anyway.
55 let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables)
57 if !empty(l:executable)
58 let l:nmi = strridx(l:executable, 'node_modules')
59 let l:project_dir = l:executable[0:l:nmi - 2]
61 let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules')
62 let l:project_dir = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : ''
65 return !empty(l:project_dir) ? l:project_dir : ''
68 function! ale_linters#solidity#solhint#GetExecutable(buffer) abort
69 return ale#path#FindExecutable(a:buffer, 'solidity_solhint', s:executables)
72 call ale#linter#Define('solidity', {
74 \ 'output_stream': 'both',
75 \ 'executable': function('ale_linters#solidity#solhint#GetExecutable'),
76 \ 'cwd': function('ale_linters#solidity#solhint#GetCwd'),
78 \ ale#node#Executable(b, ale_linters#solidity#solhint#GetExecutable(b))
79 \ . ale#Pad(ale#Var(b, 'solidity_solhint_options'))
80 \ . ' --formatter unix %s'
82 \ 'callback': 'ale_linters#solidity#solhint#Handle',