add textlint support for markdown (#1383)

This commit is contained in:
Hideaki Tokida 2018-03-19 02:28:26 +09:00 committed by w0rp
parent c112ee9dff
commit 1b1e53ef61
5 changed files with 85 additions and 2 deletions

View File

@ -121,7 +121,7 @@ formatting.
| Lua | [luac](https://www.lua.org/manual/5.1/luac.html), [luacheck](https://github.com/mpeterv/luacheck) | | Lua | [luac](https://www.lua.org/manual/5.1/luac.html), [luacheck](https://github.com/mpeterv/luacheck) |
| Mail | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Mail | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
| Make | [checkmake](https://github.com/mrtazz/checkmake) | | Make | [checkmake](https://github.com/mrtazz/checkmake) |
| Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [prettier](https://github.com/prettier/prettier), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [prettier](https://github.com/prettier/prettier), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) , [textlint](https://textlint.github.io/)|
| MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) |
| Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! | | Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! |
| nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) | | nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) |

View File

@ -0,0 +1,23 @@
" Author: tokida https://rouger.info
" Description: textlint, a proofreading tool (https://textlint.github.io/)
function! ale_linters#markdown#textlint#GetCommand(buffer) abort
let l:cmd_path = ale#path#FindNearestFile(a:buffer, '.textlintrc')
if !empty(l:cmd_path)
return 'textlint'
\ . ' -c '
\ . l:cmd_path
\ . ' -f json %t'
endif
return ''
endfunction
call ale#linter#Define('markdown', {
\ 'name': 'textlint',
\ 'executable': 'textlint',
\ 'command_callback': 'ale_linters#markdown#textlint#GetCommand',
\ 'callback': 'ale#handlers#textlint#HandleTextlintOutput',
\})

View File

@ -0,0 +1,19 @@
" Author: tokida https://rouger.info
" Description: Redpen, a proofreading tool (http://redpen.cc)
function! ale#handlers#textlint#HandleTextlintOutput(buffer, lines) abort
let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {'messages': []})
let l:output = []
for l:err in l:res.messages
call add(l:output, {
\ 'text': l:err.message,
\ 'type': 'W',
\ 'code': l:err.ruleId,
\ 'lnum': l:err.line,
\ 'col' : l:err.column
\})
endfor
return l:output
endfunction

View File

@ -344,7 +344,7 @@ Notes:
* Lua: `luac`, `luacheck` * Lua: `luac`, `luacheck`
* Mail: `alex`!!, `proselint`, `vale` * Mail: `alex`!!, `proselint`, `vale`
* Make: `checkmake` * Make: `checkmake`
* Markdown: `alex`!!, `mdl`, `prettier`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good` * Markdown: `alex`!!, `mdl`, `prettier`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good`, `textlint`
* MATLAB: `mlint` * MATLAB: `mlint`
* Nim: `nim check`!! * Nim: `nim check`!!
* nix: `nix-instantiate` * nix: `nix-instantiate`

View File

@ -0,0 +1,41 @@
Before:
runtime! ale_linters/markdown/textlint.vim
After:
call ale#linter#Reset()
Execute(textlint handler should handle errors output):
AssertEqual
\ [
\ {
\ 'lnum': 16,
\ 'col': 50,
\ 'text': 'Found possibly misspelled word "NeoVim".',
\ 'type': 'W',
\ 'code': 'preset-japanese/no-doubled-joshi',
\ },
\ ],
\ ale#handlers#textlint#HandleTextlintOutput(bufnr(''), [
\ '[',
\ ' {',
\ ' "filePath": "test.md",',
\ ' "messages": [',
\ ' {',
\ ' "type": "lint",',
\ ' "ruleId": "preset-japanese/no-doubled-joshi",',
\ ' "index": 1332,',
\ ' "line": 16,',
\ ' "column": 50,',
\ ' "severity": 2,',
\ ' "message": "Found possibly misspelled word \"NeoVim\"."',
\ ' }',
\ ' ]',
\ ' }',
\ ']',
\ ])
Execute(textlint handler should no error output):
AssertEqual
\ [],
\ ale#handlers#textlint#HandleTextlintOutput(bufnr(''), [
\ ])