summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHideaki Tokida <tokihide@gmail.com>2018-03-19 02:28:26 +0900
committerw0rp <w0rp@users.noreply.github.com>2018-03-18 17:28:26 +0000
commit1b1e53ef6101e98ff34044a127758513dbf662e4 (patch)
tree246b1739a7961809b827974a4487c938c5c46228
parentc112ee9dff2a44d733556dc9440f6d1c15f41f15 (diff)
downloadale-1b1e53ef6101e98ff34044a127758513dbf662e4.zip
add textlint support for markdown (#1383)
-rw-r--r--README.md2
-rw-r--r--ale_linters/markdown/textlint.vim23
-rw-r--r--autoload/ale/handlers/textlint.vim19
-rw-r--r--doc/ale.txt2
-rw-r--r--test/handler/test_textlint_handler.vader41
5 files changed, 85 insertions, 2 deletions
diff --git a/README.md b/README.md
index 69e4f43d..b73445f8 100644
--- a/README.md
+++ b/README.md
@@ -121,7 +121,7 @@ formatting.
| 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) |
| 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) |
| Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! |
| nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) |
diff --git a/ale_linters/markdown/textlint.vim b/ale_linters/markdown/textlint.vim
new file mode 100644
index 00000000..4899fb53
--- /dev/null
+++ b/ale_linters/markdown/textlint.vim
@@ -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',
+\})
diff --git a/autoload/ale/handlers/textlint.vim b/autoload/ale/handlers/textlint.vim
new file mode 100644
index 00000000..0aae57ef
--- /dev/null
+++ b/autoload/ale/handlers/textlint.vim
@@ -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
diff --git a/doc/ale.txt b/doc/ale.txt
index b9ac0875..e2ae04a5 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -344,7 +344,7 @@ Notes:
* Lua: `luac`, `luacheck`
* Mail: `alex`!!, `proselint`, `vale`
* 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`
* Nim: `nim check`!!
* nix: `nix-instantiate`
diff --git a/test/handler/test_textlint_handler.vader b/test/handler/test_textlint_handler.vader
new file mode 100644
index 00000000..c00d54de
--- /dev/null
+++ b/test/handler/test_textlint_handler.vader
@@ -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(''), [
+ \ ])