Add configurable options support for redpen linter (#5006)

Redpen linter previously had hardcoded command-line options and duplicated
linter definitions across all supported file types (asciidoc, markdown,
review, rst, tex, text). This refactoring centralizes the linter definition
and adds support for user-configurable options via g:ale_redpen_options.

Key changes:
- Created ale#handlers#redpen#DefineLinter() to eliminate code duplication
- Added ale#handlers#redpen#GetCommand() to support configurable options
- All file types now use shared configuration and command building
- Added comprehensive test coverage for option handling
- Updated documentation for all affected file types

This allows users to customize redpen behavior with additional command-line
options while maintaining backward compatibility and reducing maintenance
overhead.
This commit is contained in:
Jason Weir
2025-08-13 06:06:06 -06:00
committed by GitHub
parent ac691b0b89
commit 5dfd1fdb9a
13 changed files with 96 additions and 38 deletions

View File

@@ -1,9 +1,4 @@
" 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',
\})
call ale#handlers#redpen#DefineLinter('asciidoc')

View File

@@ -1,9 +1,4 @@
" Author: rhysd https://rhysd.github.io
" Description: Redpen, a proofreading tool (http://redpen.cc)
call ale#linter#Define('markdown', {
\ 'name': 'redpen',
\ 'executable': 'redpen',
\ 'command': 'redpen -f markdown -r json %t',
\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput',
\})
call ale#handlers#redpen#DefineLinter('markdown')

View File

@@ -1,9 +1,4 @@
" 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',
\})
call ale#handlers#redpen#DefineLinter('review')

View File

@@ -1,9 +1,4 @@
" 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',
\})
call ale#handlers#redpen#DefineLinter('rst')

View File

@@ -1,9 +1,4 @@
" 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',
\})
call ale#handlers#redpen#DefineLinter('tex')

View File

@@ -1,9 +1,4 @@
" Author: rhysd https://rhysd.github.io
" Description: Redpen, a proofreading tool (http://redpen.cc)
call ale#linter#Define('text', {
\ 'name': 'redpen',
\ 'executable': 'redpen',
\ 'command': 'redpen -f plain -r json %t',
\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput',
\})
call ale#handlers#redpen#DefineLinter('text')

View File

@@ -1,6 +1,8 @@
" Author: rhysd https://rhysd.github.io
" Description: Redpen, a proofreading tool (http://redpen.cc)
call ale#Set('redpen_options', '')
function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
" Only one file was passed to redpen. So response array has only one
" element.
@@ -63,3 +65,14 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
return l:output
endfunction
" Define the redpen linter for a given filetype.
function! ale#handlers#redpen#DefineLinter(filetype) abort
call ale#linter#Define(a:filetype, {
\ 'name': 'redpen',
\ 'executable': 'redpen',
\ 'command': {b -> 'redpen -f ' . a:filetype . ' -r json' . ale#Pad(ale#Var(b, 'redpen_options')) . ' %t'},
\ 'callback': 'ale#handlers#redpen#HandleRedpenOutput',
\})
endfunction

View File

@@ -20,5 +20,11 @@ textlint *ale-asciidoc-textlint*
See |ale-text-textlint|
===============================================================================
redpen *ale-asciidoc-redpen*
See |ale-redpen-options|
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@@ -225,5 +225,11 @@ write-good *ale-markdown-write-good*
See |ale-write-good-options|
===============================================================================
redpen *ale-markdown-redpen*
See |ale-redpen-options|
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@@ -111,5 +111,11 @@ g:ale_tex_texlab_config
let g:ale_tex_texlab_config = {"build":{"onSave":v:true}}
<
===============================================================================
redpen *ale-tex-redpen*
See |ale-redpen-options|
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@@ -51,5 +51,11 @@ write-good *ale-text-write-good*
See |ale-write-good-options|
===============================================================================
redpen *ale-text-redpen*
See |ale-redpen-options|
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@@ -30,7 +30,8 @@ CONTENTS *ale-contents*
7.2 Options for cspell................|ale-cspell-options|
7.3 Options for languagetool..........|ale-languagetool-options|
7.4 Options for write-good............|ale-write-good-options|
7.5 Other Linter/Fixer Options........|ale-other-integration-options|
7.5 Options for redpen................|ale-redpen-options|
7.6 Other Linter/Fixer Options........|ale-other-integration-options|
8. Commands/Keybinds....................|ale-commands|
9. API..................................|ale-api|
10. Special Thanks......................|ale-special-thanks|
@@ -3321,7 +3322,24 @@ g:ale_writegood_use_global
-------------------------------------------------------------------------------
7.6. Other Linter/Fixer Options *ale-other-integration-options*
7.6. Options for redpen *ale-redpen-options*
The options for `redpen` are shared between all filetypes, so options can
be configured once.
*ale-options.redpen_options*
*g:ale_redpen_options*
*b:ale_redpen_options*
redpen_options
g:ale_redpen_options
Type: |String|
Default: `''`
This variable can be set to pass additional options to redpen.
-------------------------------------------------------------------------------
7.7. Other Linter/Fixer Options *ale-other-integration-options*
ALE supports a very wide variety of tools. Other linter or fixer options are
documented in additional help files.
@@ -3342,6 +3360,7 @@ documented in additional help files.
cspell................................|ale-asciidoc-cspell|
write-good............................|ale-asciidoc-write-good|
textlint..............................|ale-asciidoc-textlint|
redpen................................|ale-asciidoc-redpen|
asm.....................................|ale-asm-options|
gcc...................................|ale-asm-gcc|
llvm_mc...............................|ale-asm-llvm_mc|
@@ -3665,6 +3684,7 @@ documented in additional help files.
remark-lint...........................|ale-markdown-remark-lint|
textlint..............................|ale-markdown-textlint|
write-good............................|ale-markdown-write-good|
redpen................................|ale-markdown-redpen|
mercury.................................|ale-mercury-options|
mmc...................................|ale-mercury-mmc|
nasm....................................|ale-nasm-options|
@@ -3916,6 +3936,7 @@ documented in additional help files.
lacheck...............................|ale-tex-lacheck|
latexindent...........................|ale-tex-latexindent|
texlab................................|ale-tex-texlab|
redpen................................|ale-tex-redpen|
texinfo.................................|ale-texinfo-options|
cspell................................|ale-texinfo-cspell|
write-good............................|ale-texinfo-write-good|
@@ -3923,6 +3944,7 @@ documented in additional help files.
cspell................................|ale-text-cspell|
textlint..............................|ale-text-textlint|
write-good............................|ale-text-write-good|
redpen................................|ale-text-redpen|
thrift..................................|ale-thrift-options|
thrift................................|ale-thrift-thrift|
thriftcheck...........................|ale-thrift-thriftcheck|

View File

@@ -0,0 +1,29 @@
Before:
" This is just one example of a language using the linter.
call ale#assert#SetUpLinterTest('markdown', 'redpen')
unlet! g:ale_redpen_options
call ale#Set('redpen_options', '')
After:
call ale#assert#TearDownLinterTest()
Execute(The options should be omitted by default):
AssertLinter
\ 'redpen',
\ 'redpen -f markdown -r json %t'
Execute(The options should be used in the command):
let g:ale_redpen_options = '--foo --bar'
AssertLinter
\ 'redpen',
\ 'redpen -f markdown -r json --foo --bar %t'
Execute(The command should work with different filetypes):
" Test with a different filetype
call ale#assert#SetUpLinterTest('text', 'redpen')
AssertLinter
\ 'redpen',
\ 'redpen -f text -r json %t'