summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--ale_linters/solidity/solhint.vim30
-rw-r--r--doc/ale-solidity.txt8
-rw-r--r--doc/ale.txt3
-rw-r--r--test/handler/test_solhint_handler.vader60
5 files changed, 101 insertions, 2 deletions
diff --git a/README.md b/README.md
index 89bcc255..94640c5f 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,7 @@ formatting.
| Scala | [scalac](http://scala-lang.org), [scalastyle](http://www.scalastyle.org) |
| Slim | [slim-lint](https://github.com/sds/slim-lint) |
| SML | [smlnj](http://www.smlnj.org/) |
-| Solidity | [solium](https://github.com/duaraghav8/Solium) |
+| Solidity | [solhint](https://github.com/protofire/solhint), [solium](https://github.com/duaraghav8/Solium) |
| Stylus | [stylelint](https://github.com/stylelint/stylelint) |
| SQL | [sqlint](https://github.com/purcell/sqlint) |
| Swift | [swiftlint](https://github.com/realm/SwiftLint), [swiftformat](https://github.com/nicklockwood/SwiftFormat) |
diff --git a/ale_linters/solidity/solhint.vim b/ale_linters/solidity/solhint.vim
new file mode 100644
index 00000000..519fd49d
--- /dev/null
+++ b/ale_linters/solidity/solhint.vim
@@ -0,0 +1,30 @@
+" Author: Franco Victorio - https://github.com/fvictorio
+" Description: Report errors in Solidity code with solhint
+
+function! ale_linters#solidity#solhint#Handle(buffer, lines) abort
+ " Matches patterns like the following:
+ " /path/to/file/file.sol: line 1, col 10, Error - 'addOne' is defined but never used. (no-unused-vars)
+
+ let l:pattern = '\v^[^:]+: line (\d+), col (\d+), (Error|Warning) - (.*) \((.*)\)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:isError = l:match[3] is? 'error'
+ call add(l:output, {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[4],
+ \ 'code': l:match[5],
+ \ 'type': l:isError ? 'E' : 'W',
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('solidity', {
+\ 'name': 'solhint',
+\ 'executable': 'solhint',
+\ 'command': 'solhint --formatter compact %t',
+\ 'callback': 'ale_linters#solidity#solhint#Handle',
+\})
diff --git a/doc/ale-solidity.txt b/doc/ale-solidity.txt
index 3dea123e..4b74a27a 100644
--- a/doc/ale-solidity.txt
+++ b/doc/ale-solidity.txt
@@ -3,6 +3,14 @@ ALE Solidity Integration *ale-solidity-options*
===============================================================================
+solhint *ale-solidity-solhint*
+
+ Solhint should work out-of-the-box. You can further configure it using a
+ `.solihint.json` file. See https://github.com/protofire/solhint for more
+ information.
+
+
+===============================================================================
solium *ale-solidity-solium*
Use of Solium linter for Solidity source code requires a .soliumrc.json
diff --git a/doc/ale.txt b/doc/ale.txt
index 8e8f5f4f..0ab72747 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -193,6 +193,7 @@ CONTENTS *ale-contents*
sml...................................|ale-sml-options|
smlnj...............................|ale-sml-smlnj|
solidity..............................|ale-solidity-options|
+ solhint.............................|ale-solidity-solhint|
solium..............................|ale-solidity-solium|
spec..................................|ale-spec-options|
rpmlint.............................|ale-spec-rpmlint|
@@ -342,7 +343,7 @@ Notes:
* Scala: `scalac`, `scalastyle`
* Slim: `slim-lint`
* SML: `smlnj`
-* Solidity: `solium`
+* Solidity: `solhint, solium`
* Stylus: `stylelint`
* SQL: `sqlint`
* Swift: `swiftlint`, `swiftformat`
diff --git a/test/handler/test_solhint_handler.vader b/test/handler/test_solhint_handler.vader
new file mode 100644
index 00000000..a3ed5d57
--- /dev/null
+++ b/test/handler/test_solhint_handler.vader
@@ -0,0 +1,60 @@
+Before:
+ runtime ale_linters/solidity/solhint.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(The vint handler should parse error messages correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 17,
+ \ 'text': 'Compiler version must be fixed',
+ \ 'code': 'compiler-fixed',
+ \ 'type': 'W',
+ \ },
+ \ {
+ \ 'lnum': 4,
+ \ 'col': 8,
+ \ 'text': 'Use double quotes for string literals',
+ \ 'code': 'quotes',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'lnum': 5,
+ \ 'col': 8,
+ \ 'text': 'Use double quotes for string literals',
+ \ 'code': 'quotes',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'lnum': 13,
+ \ 'col': 3,
+ \ 'text': 'Expected indentation of 4 spaces but found 2',
+ \ 'code': 'indent',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'lnum': 14,
+ \ 'col': 3,
+ \ 'text': 'Expected indentation of 4 spaces but found 2',
+ \ 'code': 'indent',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'lnum': 47,
+ \ 'col': 3,
+ \ 'text': 'Function order is incorrect, public function can not go after internal function.',
+ \ 'code': 'func-order',
+ \ 'type': 'E',
+ \ },
+ \ ],
+ \ ale_linters#solidity#solhint#Handle(bufnr(''), [
+ \ 'contracts/Bounty.sol: line 1, col 17, Warning - Compiler version must be fixed (compiler-fixed)',
+ \ 'contracts/Bounty.sol: line 4, col 8, Error - Use double quotes for string literals (quotes)',
+ \ 'contracts/Bounty.sol: line 5, col 8, Error - Use double quotes for string literals (quotes)',
+ \ 'contracts/Bounty.sol: line 13, col 3, Error - Expected indentation of 4 spaces but found 2 (indent)',
+ \ 'contracts/Bounty.sol: line 14, col 3, Error - Expected indentation of 4 spaces but found 2 (indent)',
+ \ 'contracts/Bounty.sol: line 47, col 3, Error - Function order is incorrect, public function can not go after internal function. (func-order)',
+ \ ])