From 44cd07d39c860c32016d85b4d4f0c8aec901064d Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 17 Nov 2017 15:21:18 +0900 Subject: [PATCH] redpen support for asciidoc, reST, LaTeX and Re:VIEW --- README.md | 7 +++--- ale_linters/asciidoc/redpen.vim | 9 ++++++++ ale_linters/markdown/redpen.vim | 30 ++------------------------ ale_linters/review/redpen.vim | 9 ++++++++ ale_linters/rst/redpen.vim | 9 ++++++++ ale_linters/tex/redpen.vim | 9 ++++++++ autoload/ale/handlers/redpen.vim | 29 +++++++++++++++++++++++++ doc/ale.txt | 7 +++--- test/handler/test_redpen_handler.vader | 4 ++-- 9 files changed, 77 insertions(+), 36 deletions(-) create mode 100644 ale_linters/asciidoc/redpen.vim create mode 100644 ale_linters/review/redpen.vim create mode 100644 ale_linters/rst/redpen.vim create mode 100644 ale_linters/tex/redpen.vim create mode 100644 autoload/ale/handlers/redpen.vim diff --git a/README.md b/README.md index ba1aca96..891692c7 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ formatting. | -------- | ----- | | ASM | [gcc](https://gcc.gnu.org) | | Ansible | [ansible-lint](https://github.com/willthames/ansible-lint) | -| AsciiDoc | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)| +| AsciiDoc | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good), [redpen](http://redpen.cc/)| | Awk | [gawk](https://www.gnu.org/software/gawk/)| | Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | | Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | @@ -109,7 +109,7 @@ formatting. | JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), prettier-eslint >= 4.2.0, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) | JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | -| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | +| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good), [redpen](http://redpen.cc/) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | @@ -132,7 +132,8 @@ formatting. | Python | [autopep8](https://github.com/hhatto/autopep8), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pyls](https://github.com/palantir/python-language-server), [pylint](https://www.pylint.org/) !!, [yapf](https://github.com/google/yapf) | | R | [lintr](https://github.com/jimhester/lintr) | | ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-reason-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [refmt](https://github.com/reasonml/reason-cli) | -| reStructuredText | [proselint](http://proselint.com/), [rstcheck](https://github.com/myint/rstcheck), [write-good](https://github.com/btford/write-good) | +| reStructuredText | [proselint](http://proselint.com/), [rstcheck](https://github.com/myint/rstcheck), [write-good](https://github.com/btford/write-good), [redpen](http://redpen.cc/) | +| Re:VIEW | [redpen](http://redpen.cc/) | | RPM spec | [rpmlint](https://github.com/rpm-software-management/rpmlint) (disabled by default; see `:help ale-integration-spec`) | | Ruby | [brakeman](http://brakemanscanner.org/) !!, [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) !!, [reek](https://github.com/troessner/reek), [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org) | | Rust | cargo !! (see `:help ale-integration-rust` for configuration instructions), [rls](https://github.com/rust-lang-nursery/rls), [rustc](https://www.rust-lang.org/), [rustfmt](https://github.com/rust-lang-nursery/rustfmt) | diff --git a/ale_linters/asciidoc/redpen.vim b/ale_linters/asciidoc/redpen.vim new file mode 100644 index 00000000..819e385f --- /dev/null +++ b/ale_linters/asciidoc/redpen.vim @@ -0,0 +1,9 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +call ale#linter#Define('asciidoc', { +\ 'name': 'redpen', +\ 'executable': 'redpen', +\ 'command': 'redpen -f asciidoc -r json %t', +\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput', +\}) diff --git a/ale_linters/markdown/redpen.vim b/ale_linters/markdown/redpen.vim index 38fe2308..ff2cbaf8 100644 --- a/ale_linters/markdown/redpen.vim +++ b/ale_linters/markdown/redpen.vim @@ -1,35 +1,9 @@ " 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:output = [] - for l:err in l:res.errors - 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:output -endfunction - call ale#linter#Define('markdown', { \ 'name': 'redpen', \ 'executable': 'redpen', -\ 'command': 'redpen -r json %t', -\ 'callback': 'ale_linters#markdown#redpen#HandleErrors', +\ 'command': 'redpen -f markdown -r json %t', +\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput', \}) diff --git a/ale_linters/review/redpen.vim b/ale_linters/review/redpen.vim new file mode 100644 index 00000000..0006cab9 --- /dev/null +++ b/ale_linters/review/redpen.vim @@ -0,0 +1,9 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +call ale#linter#Define('review', { +\ 'name': 'redpen', +\ 'executable': 'redpen', +\ 'command': 'redpen -f review -r json %t', +\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput', +\}) diff --git a/ale_linters/rst/redpen.vim b/ale_linters/rst/redpen.vim new file mode 100644 index 00000000..ac966c56 --- /dev/null +++ b/ale_linters/rst/redpen.vim @@ -0,0 +1,9 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +call ale#linter#Define('rst', { +\ 'name': 'redpen', +\ 'executable': 'redpen', +\ 'command': 'redpen -f rest -r json %t', +\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput', +\}) diff --git a/ale_linters/tex/redpen.vim b/ale_linters/tex/redpen.vim new file mode 100644 index 00000000..952a6004 --- /dev/null +++ b/ale_linters/tex/redpen.vim @@ -0,0 +1,9 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +call ale#linter#Define('tex', { +\ 'name': 'redpen', +\ 'executable': 'redpen', +\ 'command': 'redpen -f latex -r json %t', +\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput', +\}) diff --git a/autoload/ale/handlers/redpen.vim b/autoload/ale/handlers/redpen.vim new file mode 100644 index 00000000..89ad5fc7 --- /dev/null +++ b/autoload/ale/handlers/redpen.vim @@ -0,0 +1,29 @@ +" Author: rhysd https://rhysd.github.io +" Description: Redpen, a proofreading tool (http://redpen.cc) + +function! ale#handlers#redpen#HandleRedpenOutput(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:output = [] + for l:err in l:res.errors + 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:output +endfunction + diff --git a/doc/ale.txt b/doc/ale.txt index 697c592e..1d2bed31 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -264,7 +264,7 @@ Notes: * ASM: `gcc` * Ansible: `ansible-lint` -* AsciiDoc: `proselint`, `write-good` +* AsciiDoc: `proselint`, `write-good`, `redpen` * Awk: `gawk` * Bash: `shell` (-n flag), `shellcheck`, `shfmt` * Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt` @@ -301,7 +301,7 @@ Notes: * JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint` >= 4.2.0, `prettier-standard`, `standard`, `xo` * JSON: `jsonlint`, `prettier` * Kotlin: `kotlinc`, `ktlint` -* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good` +* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good`, `redpen` * Less: `lessc`, `prettier`, `stylelint` * LLVM: `llc` * Lua: `luacheck` @@ -324,7 +324,8 @@ Notes: * Python: `autopep8`, `flake8`, `isort`, `mypy`, `pycodestyle`, `pyls`, `pylint`!!, `yapf` * R: `lintr` * ReasonML: `merlin`, `ols`, `refmt` -* reStructuredText: `proselint`, `rstcheck`, `write-good` +* reStructuredText: `proselint`, `rstcheck`, `write-good`, `redpen` +* Re:VIEW: `redpen` * RPM spec: `rpmlint` * Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby` * Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|), `rustfmt` diff --git a/test/handler/test_redpen_handler.vader b/test/handler/test_redpen_handler.vader index d0782d90..32ff0ba1 100644 --- a/test/handler/test_redpen_handler.vader +++ b/test/handler/test_redpen_handler.vader @@ -22,7 +22,7 @@ Execute(redpen handler should handle errors output): \ 'type': 'W', \ }, \ ], - \ ale_linters#markdown#redpen#HandleErrors(bufnr(''), [ + \ ale#handlers#redpen#HandleRedpenOutput(bufnr(''), [ \ '[', \ ' {', \ ' "document": "test.md",', @@ -57,7 +57,7 @@ Execute(redpen handler should handle errors output): Execute(redpen handler should no error output): AssertEqual \ [], - \ ale_linters#markdown#redpen#HandleErrors(bufnr(''), [ + \ ale#handlers#redpen#HandleRedpenOutput(bufnr(''), [ \ '[', \ ' {', \ ' "document": "test.md",',