From 981cb95d80714fd70b55d99f164c2d3158315206 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 16 Nov 2017 18:12:08 +0900 Subject: [PATCH 1/4] add redpen support --- ale_linters/markdown/redpen.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ale_linters/markdown/redpen.vim diff --git a/ale_linters/markdown/redpen.vim b/ale_linters/markdown/redpen.vim new file mode 100644 index 00000000..00a19a93 --- /dev/null +++ b/ale_linters/markdown/redpen.vim @@ -0,0 +1,32 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +function! ale_linters#markdown#redpen#HandleErrors(buffer, lines) abort + " Only one file was passed to redpen. So response array has only one + " element. + let l:res = json_decode(join(a:lines))[0] + let l:errors = [] + for l:err in l:res.errors + if has_key(l:err, 'startPosition') + let l:lnum = l:err.startPosition.lineNum + let l:col = l:err.startPosition.offset + else + let l:lnum = l:err.lineNum + let l:col = l:err.sentenceStartColumnNum + 1 + endif + call add(l:errors, { + \ 'lnum': l:lnum, + \ 'col': l:col, + \ 'text': l:err.message . ' (' . l:err.validator . ')', + \ 'type': 'W', + \}) + endfor + return l:errors +endfunction + +call ale#linter#Define('markdown', { +\ 'name': 'redpen', +\ 'executable': 'redpen', +\ 'command': 'redpen -r json %t', +\ 'callback': 'ale_linters#markdown#redpen#HandleErrors', +\}) From c9c52ef370f6abbcf60220e047faebd294bd738b Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 16 Nov 2017 18:36:53 +0900 Subject: [PATCH 2/4] add tests and doc for redpen support --- README.md | 2 +- doc/ale.txt | 2 +- test/handler/test_redpen_handler.vader | 65 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 test/handler/test_redpen_handler.vader diff --git a/README.md b/README.md index cf812aff..810b90e5 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ formatting. | Lua | [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Make | [checkmake](https://github.com/mrtazz/checkmake) | -| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale), [remark-lint](https://github.com/wooorm/remark-lint) !!, [write-good](https://github.com/btford/write-good) | +| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale), [remark-lint](https://github.com/wooorm/remark-lint) !!, [write-good](https://github.com/btford/write-good), [redpen](http://redpen.cc/) | | MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! | | nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) | diff --git a/doc/ale.txt b/doc/ale.txt index 9947d091..8e2e595d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -304,7 +304,7 @@ Notes: * Lua: `luacheck` * Mail: `proselint`, `vale` * Make: `checkmake` -* Markdown: `mdl`, `proselint`, `vale`, `remark-lint`, `write-good` +* Markdown: `mdl`, `proselint`, `vale`, `remark-lint`, `write-good`, `redpen` * MATLAB: `mlint` * Nim: `nim check`!! * nix: `nix-instantiate` diff --git a/test/handler/test_redpen_handler.vader b/test/handler/test_redpen_handler.vader new file mode 100644 index 00000000..2ea3a2ff --- /dev/null +++ b/test/handler/test_redpen_handler.vader @@ -0,0 +1,65 @@ +Before: + runtime! ale_linters/markdown/redpen.vim + +After: + call ale#linter#Reset() + +Execute(redpen handler should handle errors output): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'col': 9, + \ 'text': 'Found possibly misspelled word "plugin". (Spelling)', + \ 'type': 'W', + \ }, + \ { + \ 'lnum': 1, + \ 'col': 1, + \ 'text': 'Found possibly misspelled word "NeoVim". (Spelling)', + \ 'type': 'W', + \ }, + \ ], + \ ale_linters#markdown#redpen#HandleErrors(bufnr(''), [ + \ '[', + \ ' {', + \ ' "document": "test.md",', + \ ' "errors": [', + \ ' {', + \ ' "sentence": "ALE is a plugin for providing linting in NeoVim and Vim 8 while you edit your text files.",', + \ ' "endPosition": {', + \ ' "offset": 15,', + \ ' "lineNum": 1', + \ ' },', + \ ' "validator": "Spelling",', + \ ' "lineNum": 1,', + \ ' "sentenceStartColumnNum": 0,', + \ ' "message": "Found possibly misspelled word \"plugin\".",', + \ ' "startPosition": {', + \ ' "offset": 9,', + \ ' "lineNum": 1', + \ ' }', + \ ' },', + \ ' {', + \ ' "sentence": "ALE is a plugin for providing linting in NeoVim and Vim 8 while you edit your text files.",', + \ ' "validator": "Spelling",', + \ ' "lineNum": 1,', + \ ' "sentenceStartColumnNum": 0,', + \ ' "message": "Found possibly misspelled word \"NeoVim\".",', + \ ' }', + \ ' ]', + \ ' }', + \ ']', + \ ]) + +Execute(redpen handler should no error output): + AssertEqual + \ [], + \ ale_linters#markdown#redpen#HandleErrors(bufnr(''), [ + \ '[', + \ ' {', + \ ' "document": "test.md",', + \ ' "errors": []', + \ ' }', + \ ']', + \ ]) From f1314b285c7b489f7b879a1afd703b60a877a52e Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 16 Nov 2017 19:28:30 +0900 Subject: [PATCH 3/4] redpen: support end_lnum and end_col if possible --- ale_linters/markdown/redpen.vim | 29 ++++++++++++++------------ test/handler/test_redpen_handler.vader | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ale_linters/markdown/redpen.vim b/ale_linters/markdown/redpen.vim index 00a19a93..38fe2308 100644 --- a/ale_linters/markdown/redpen.vim +++ b/ale_linters/markdown/redpen.vim @@ -5,23 +5,26 @@ function! ale_linters#markdown#redpen#HandleErrors(buffer, lines) abort " Only one file was passed to redpen. So response array has only one " element. let l:res = json_decode(join(a:lines))[0] - let l:errors = [] + let l:output = [] for l:err in l:res.errors - if has_key(l:err, 'startPosition') - let l:lnum = l:err.startPosition.lineNum - let l:col = l:err.startPosition.offset - else - let l:lnum = l:err.lineNum - let l:col = l:err.sentenceStartColumnNum + 1 - endif - call add(l:errors, { - \ 'lnum': l:lnum, - \ 'col': l:col, + let l:item = { \ 'text': l:err.message . ' (' . l:err.validator . ')', \ 'type': 'W', - \}) + \} + if has_key(l:err, 'startPosition') + let l:item.lnum = l:err.startPosition.lineNum + let l:item.col = l:err.startPosition.offset + if has_key(l:err, 'endPosition') + let l:item.end_lnum = l:err.endPosition.lineNum + let l:item.end_col = l:err.endPosition.offset + endif + else + let l:item.lnum = l:err.lineNum + let l:item.col = l:err.sentenceStartColumnNum + 1 + endif + call add(l:output, l:item) endfor - return l:errors + return l:output endfunction call ale#linter#Define('markdown', { diff --git a/test/handler/test_redpen_handler.vader b/test/handler/test_redpen_handler.vader index 2ea3a2ff..a1ad65d1 100644 --- a/test/handler/test_redpen_handler.vader +++ b/test/handler/test_redpen_handler.vader @@ -10,6 +10,8 @@ Execute(redpen handler should handle errors output): \ { \ 'lnum': 1, \ 'col': 9, + \ 'end_lnum': 1, + \ 'end_col': 15, \ 'text': 'Found possibly misspelled word "plugin". (Spelling)', \ 'type': 'W', \ }, From e232ea07c23d3e6f1b6e621e896f27545e5b10c7 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 16 Nov 2017 19:42:51 +0900 Subject: [PATCH 4/4] redpen: fix trailing comma in test data --- test/handler/test_redpen_handler.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/handler/test_redpen_handler.vader b/test/handler/test_redpen_handler.vader index a1ad65d1..d0782d90 100644 --- a/test/handler/test_redpen_handler.vader +++ b/test/handler/test_redpen_handler.vader @@ -47,7 +47,7 @@ Execute(redpen handler should handle errors output): \ ' "validator": "Spelling",', \ ' "lineNum": 1,', \ ' "sentenceStartColumnNum": 0,', - \ ' "message": "Found possibly misspelled word \"NeoVim\".",', + \ ' "message": "Found possibly misspelled word \"NeoVim\"."', \ ' }', \ ' ]', \ ' }',