linter/cypher: add cypher-lint

This commit is contained in:
Francisco Lopes 2019-02-03 03:04:23 -02:00
parent 4d426bf287
commit 626572a539
5 changed files with 57 additions and 0 deletions

View File

@ -211,6 +211,7 @@ formatting.
| XML | [xmllint](http://xmlsoft.org/xmllint.html) | | XML | [xmllint](http://xmlsoft.org/xmllint.html) |
| YAML | [prettier](https://github.com/prettier/prettier), [swaglint](https://github.com/byCedric/swaglint), [yamllint](https://yamllint.readthedocs.io/) | | YAML | [prettier](https://github.com/prettier/prettier), [swaglint](https://github.com/byCedric/swaglint), [yamllint](https://yamllint.readthedocs.io/) |
| YANG | [yang-lsp](https://github.com/theia-ide/yang-lsp) | | YANG | [yang-lsp](https://github.com/theia-ide/yang-lsp) |
| Cypher | [cypher-lint](https://github.com/cleishm/libcypher-parser) !! |
<a name="usage"></a> <a name="usage"></a>

View File

@ -0,0 +1,26 @@
" Author: Francisco Lopes <francisco@oblita.com>
" Description: Linting for Neo4j's Cypher
function! ale_linters#cypher#cypher_lint#Handle(buffer, lines) abort
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+): (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'text': l:match[4],
\ 'type': 'E',
\})
endfor
return l:output
endfunction
call ale#linter#Define('cypher', {
\ 'name': 'cypher_lint',
\ 'executable': 'cypher-lint',
\ 'command': 'cypher-lint %s',
\ 'output_stream': 'stderr',
\ 'callback': 'ale_linters#cypher#cypher_lint#Handle',
\})

View File

@ -532,6 +532,7 @@ Notes:
* XML: `xmllint` * XML: `xmllint`
* YAML: `prettier`, `swaglint`, `yamllint` * YAML: `prettier`, `swaglint`, `yamllint`
* YANG: `yang-lsp` * YANG: `yang-lsp`
* Cypher: `cypher-lint`!!
=============================================================================== ===============================================================================
3. Linting *ale-lint* 3. Linting *ale-lint*

View File

@ -0,0 +1,8 @@
Before:
call ale#assert#SetUpLinterTest('cypher', 'cypher_lint')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command and executable should be correct):
AssertLinter 'cypher-lint', 'cypher-lint %s'

View File

@ -0,0 +1,21 @@
Before:
runtime ale_linters/cypher/cypher_lint.vim
After:
call ale#linter#Reset()
Execute(The cypher-lint handler should handle errors for the current file correctly):
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'col': 75,
\ 'type': 'E',
\ 'text': "Invalid input ',': expected an identifier, shortestPath, allShortestPaths or '('",
\ },
\ ],
\ ale_linters#cypher#cypher_lint#Handle(bufnr(''), [
\ "shakespeare.cql:1:75: Invalid input ',': expected an identifier, shortestPath, allShortestPaths or '('",
\ "CREATE (shakespeare:Author {firstname:'William', lastname:'Shakespeare'}),,",
\ " ^",
\ ])