]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/solidity/solhint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / solidity / solhint.vim
1 " Authors: Franco Victorio <@fvictorio>, Henrique Barcelos <@hbarcelos>
2 " Description: Report errors in Solidity code with solhint
3
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))
7
8 function! ale_linters#solidity#solhint#Handle(buffer, lines) abort
9     let l:output = []
10
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)\/([^\]]+)\]$'
14
15     for l:match in ale#util#GetMatches(a:lines, l:lint_pattern)
16         let l:is_error = l:match[4] is? 'error'
17         call add(l:output, {
18         \   'lnum': l:match[1] + 0,
19         \   'col': l:match[2] + 0,
20         \   'text': l:match[3],
21         \   'code': l:match[5],
22         \   'type': l:is_error ? 'E' : 'W',
23         \})
24     endfor
25
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\]$'
29
30     for l:match in ale#util#GetMatches(a:lines, l:syntax_pattern)
31         call add(l:output, {
32         \   'lnum': l:match[1] + 0,
33         \   'col': l:match[2] + 0,
34         \   'text': l:match[3],
35         \   'code': 'Parse error',
36         \   'type': 'E',
37         \})
38     endfor
39
40     return l:output
41 endfunction
42
43 let s:executables = [
44 \   'node_modules/.bin/solhint',
45 \   'node_modules/solhint/solhint.js',
46 \   'solhint',
47 \]
48 let s:sep = has('win32') ? '\' : '/'
49
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)
56
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]
60     else
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') : ''
63     endif
64
65     return !empty(l:project_dir) ? l:project_dir : ''
66 endfunction
67
68 function! ale_linters#solidity#solhint#GetExecutable(buffer) abort
69     return ale#path#FindExecutable(a:buffer, 'solidity_solhint', s:executables)
70 endfunction
71
72 call ale#linter#Define('solidity', {
73 \   'name': 'solhint',
74 \   'output_stream': 'both',
75 \   'executable': function('ale_linters#solidity#solhint#GetExecutable'),
76 \   'cwd': function('ale_linters#solidity#solhint#GetCwd'),
77 \   'command': {b ->
78 \       ale#node#Executable(b, ale_linters#solidity#solhint#GetExecutable(b))
79 \       . ale#Pad(ale#Var(b, 'solidity_solhint_options'))
80 \       . ' --formatter unix %s'
81 \   },
82 \   'callback': 'ale_linters#solidity#solhint#Handle',
83 \})