From 0d627d46134a756860beaf825a618313e4133de3 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 4 Dec 2017 13:28:52 -0300 Subject: [PATCH 1/4] Add solhint support --- ale_linters/solidity/solhint.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ale_linters/solidity/solhint.vim diff --git a/ale_linters/solidity/solhint.vim b/ale_linters/solidity/solhint.vim new file mode 100644 index 00000000..cab2c18a --- /dev/null +++ b/ale_linters/solidity/solhint.vim @@ -0,0 +1,29 @@ +" 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], + \ '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', +\}) From 3e1bd8d922c2be22fdaa24ce2d11bafa636375a7 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 4 Dec 2017 14:23:34 -0300 Subject: [PATCH 2/4] Update documentation --- README.md | 2 +- doc/ale-solidity.txt | 8 ++++++++ doc/ale.txt | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25fb72b0..94083486 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,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/doc/ale-solidity.txt b/doc/ale-solidity.txt index 3dea123e..4b74a27a 100644 --- a/doc/ale-solidity.txt +++ b/doc/ale-solidity.txt @@ -2,6 +2,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* diff --git a/doc/ale.txt b/doc/ale.txt index 04f187dc..e44ff24f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -186,6 +186,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| @@ -334,7 +335,7 @@ Notes: * Scala: `scalac`, `scalastyle` * Slim: `slim-lint` * SML: `smlnj` -* Solidity: `solium` +* Solidity: `solhint, solium` * Stylus: `stylelint` * SQL: `sqlint` * Swift: `swiftlint`, `swiftformat` From 57e1b03435c94cd93748a87ee9fbd285452d91ca Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 4 Dec 2017 14:23:46 -0300 Subject: [PATCH 3/4] Add test for solhint handler --- test/handler/test_solhint_handler.vader | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/handler/test_solhint_handler.vader diff --git a/test/handler/test_solhint_handler.vader b/test/handler/test_solhint_handler.vader new file mode 100644 index 00000000..43e3505c --- /dev/null +++ b/test/handler/test_solhint_handler.vader @@ -0,0 +1,54 @@ +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 (compiler-fixed)', + \ 'type': 'W', + \ }, + \ { + \ 'lnum': 4, + \ 'col': 8, + \ 'text': 'Use double quotes for string literals (quotes)', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 5, + \ 'col': 8, + \ 'text': 'Use double quotes for string literals (quotes)', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 13, + \ 'col': 3, + \ 'text': 'Expected indentation of 4 spaces but found 2 (indent)', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 14, + \ 'col': 3, + \ 'text': 'Expected indentation of 4 spaces but found 2 (indent)', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 47, + \ 'col': 3, + \ 'text': 'Function order is incorrect, public function can not go after internal function. (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)', + \ ]) From 85e0bd33141a05216848e525b3e86b6698aa38cd Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 5 Dec 2017 16:02:15 -0300 Subject: [PATCH 4/4] Extract error code from message --- ale_linters/solidity/solhint.vim | 5 +++-- test/handler/test_solhint_handler.vader | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ale_linters/solidity/solhint.vim b/ale_linters/solidity/solhint.vim index cab2c18a..519fd49d 100644 --- a/ale_linters/solidity/solhint.vim +++ b/ale_linters/solidity/solhint.vim @@ -5,7 +5,7 @@ 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:pattern = '\v^[^:]+: line (\d+), col (\d+), (Error|Warning) - (.*) \((.*)\)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) @@ -14,7 +14,8 @@ function! ale_linters#solidity#solhint#Handle(buffer, lines) abort \ 'lnum': l:match[1] + 0, \ 'col': l:match[2] + 0, \ 'text': l:match[4], - \ 'type': l:isError ? 'E' : 'W' + \ 'code': l:match[5], + \ 'type': l:isError ? 'E' : 'W', \}) endfor diff --git a/test/handler/test_solhint_handler.vader b/test/handler/test_solhint_handler.vader index 43e3505c..a3ed5d57 100644 --- a/test/handler/test_solhint_handler.vader +++ b/test/handler/test_solhint_handler.vader @@ -10,37 +10,43 @@ Execute(The vint handler should parse error messages correctly): \ { \ 'lnum': 1, \ 'col': 17, - \ 'text': 'Compiler version must be fixed (compiler-fixed)', + \ 'text': 'Compiler version must be fixed', + \ 'code': 'compiler-fixed', \ 'type': 'W', \ }, \ { \ 'lnum': 4, \ 'col': 8, - \ 'text': 'Use double quotes for string literals (quotes)', + \ 'text': 'Use double quotes for string literals', + \ 'code': 'quotes', \ 'type': 'E', \ }, \ { \ 'lnum': 5, \ 'col': 8, - \ 'text': 'Use double quotes for string literals (quotes)', + \ 'text': 'Use double quotes for string literals', + \ 'code': 'quotes', \ 'type': 'E', \ }, \ { \ 'lnum': 13, \ 'col': 3, - \ 'text': 'Expected indentation of 4 spaces but found 2 (indent)', + \ '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 (indent)', + \ '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. (func-order)', + \ 'text': 'Function order is incorrect, public function can not go after internal function.', + \ 'code': 'func-order', \ 'type': 'E', \ }, \ ],