From 1d33d2cacff9816ce487f9000675851041c25901 Mon Sep 17 00:00:00 2001 From: yasuhiroki Date: Tue, 20 Mar 2018 08:57:09 +0900 Subject: [PATCH] Support textlint for plaintext without textlintrc --- ale_linters/markdown/textlint.vim | 20 +++--------------- ale_linters/text/textlint.vim | 9 ++++++++ autoload/ale/handlers/textlint.vim | 33 ++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 ale_linters/text/textlint.vim diff --git a/ale_linters/markdown/textlint.vim b/ale_linters/markdown/textlint.vim index 4899fb53..26458506 100644 --- a/ale_linters/markdown/textlint.vim +++ b/ale_linters/markdown/textlint.vim @@ -1,23 +1,9 @@ -" Author: tokida https://rouger.info +" Author: tokida https://rouger.info, Yasuhiro Kiyota " 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', +\ 'executable_callback': 'ale#handlers#textlint#GetExecutable', +\ 'command_callback': 'ale#handlers#textlint#GetCommand', \ 'callback': 'ale#handlers#textlint#HandleTextlintOutput', \}) diff --git a/ale_linters/text/textlint.vim b/ale_linters/text/textlint.vim new file mode 100644 index 00000000..8fafdd7d --- /dev/null +++ b/ale_linters/text/textlint.vim @@ -0,0 +1,9 @@ +" Author: Yasuhiro Kiyota +" Description: textlint, a proofreading tool (https://textlint.github.io/) + +call ale#linter#Define('text', { +\ 'name': 'textlint', +\ 'executable_callback': 'ale#handlers#textlint#GetExecutable', +\ 'command_callback': 'ale#handlers#textlint#GetCommand', +\ 'callback': 'ale#handlers#textlint#HandleTextlintOutput', +\}) diff --git a/autoload/ale/handlers/textlint.vim b/autoload/ale/handlers/textlint.vim index 0aae57ef..80f68e10 100644 --- a/autoload/ale/handlers/textlint.vim +++ b/autoload/ale/handlers/textlint.vim @@ -1,5 +1,34 @@ -" Author: tokida https://rouger.info -" Description: Redpen, a proofreading tool (http://redpen.cc) +" Author: tokida https://rouger.info, Yasuhiro Kiyota +" Description: textlint, a proofreading tool (https://textlint.github.io/) + +call ale#Set('textlint_executable', 'textlint') +call ale#Set('textlint_use_global', 0) +call ale#Set('textlint_options', '') + +function! ale#handlers#textlint#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'textlint', [ + \ 'node_modules/.bin/textlint', + \ 'node_modules/textlint/bin/textlint.js', + \]) +endfunction + +function! ale#handlers#textlint#GetCommand(buffer) abort + let l:cmd_path = ale#path#FindNearestFile(a:buffer, '.textlintrc') + let l:options = ale#Var(a:buffer, 'textlint_options') + + if !empty(l:cmd_path) + return 'textlint' + \ . ' -c ' + \ . l:cmd_path + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' -f json %t' + endif + + return 'textlint' + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' -f json %t' +endfunction + function! ale#handlers#textlint#HandleTextlintOutput(buffer, lines) abort let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {'messages': []})