mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-14 06:01:50 +08:00
feat(rstcheck): Add automatic --config support with version check (#5095)
* Add automatic --config support for rstcheck >= 3.4.0 * Add tests for rstcheck Co-authored-by: PsickOSSH <PsickOSSH@protonmail.com> Co-authored-by: w0rp <devw0rp@gmail.com>
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
" Author: John Nduli https://github.com/jnduli
|
" Authors:
|
||||||
" Description: Rstcheck for reStructuredText files
|
" John Nduli https://github.com/jnduli,
|
||||||
|
" Michael Goerz https://github.com/goerz
|
||||||
|
|
||||||
|
call ale#Set('rst_rstcheck_executable', 'rstcheck')
|
||||||
|
call ale#Set('rst_rstcheck_options', '')
|
||||||
|
|
||||||
|
function! ale_linters#rst#rstcheck#GetExecutable(buffer) abort
|
||||||
|
return ale#Var(a:buffer, 'rst_rstcheck_executable')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#rst#rstcheck#Handle(buffer, lines) abort
|
function! ale_linters#rst#rstcheck#Handle(buffer, lines) abort
|
||||||
" matches: 'bad_rst.rst:1: (SEVERE/4) Title overline & underline
|
" matches: 'bad_rst.rst:1: (SEVERE/4) Title overline & underline
|
||||||
@@ -21,11 +29,35 @@ function! ale_linters#rst#rstcheck#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#rst#rstcheck#GetCommand(buffer, version) abort
|
||||||
|
let l:executable = ale_linters#rst#rstcheck#GetExecutable(a:buffer)
|
||||||
|
let l:options = ale#Var(a:buffer, 'rst_rstcheck_options')
|
||||||
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||||
|
let l:exec_args = ale#Pad(l:options)
|
||||||
|
|
||||||
|
if ale#semver#GTE(a:version, [3, 4, 0])
|
||||||
|
let l:exec_args .= ' --config ' . ale#Escape(l:dir)
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#Escape(l:executable)
|
||||||
|
\ . l:exec_args
|
||||||
|
\ . ' %t'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#rst#rstcheck#GetCommandWithVersionCheck(buffer) abort
|
||||||
|
return ale#semver#RunWithVersionCheck(
|
||||||
|
\ a:buffer,
|
||||||
|
\ ale_linters#rst#rstcheck#GetExecutable(a:buffer),
|
||||||
|
\ '%e --version',
|
||||||
|
\ function('ale_linters#rst#rstcheck#GetCommand')
|
||||||
|
\)
|
||||||
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('rst', {
|
call ale#linter#Define('rst', {
|
||||||
\ 'name': 'rstcheck',
|
\ 'name': 'rstcheck',
|
||||||
\ 'executable': 'rstcheck',
|
\ 'executable': 'rstcheck',
|
||||||
\ 'cwd': '%s:h',
|
\ 'cwd': '%s:h',
|
||||||
\ 'command': 'rstcheck %t',
|
\ 'command': function('ale_linters#rst#rstcheck#GetCommandWithVersionCheck'),
|
||||||
\ 'callback': 'ale_linters#rst#rstcheck#Handle',
|
\ 'callback': 'ale_linters#rst#rstcheck#Handle',
|
||||||
\ 'output_stream': 'both',
|
\ 'output_stream': 'both',
|
||||||
\})
|
\})
|
||||||
|
|||||||
63
test/linter/test_rst_rstcheck.vader
Normal file
63
test/linter/test_rst_rstcheck.vader
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('rst', 'rstcheck')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The default command should include --config for rstcheck >= 3.4.0):
|
||||||
|
GivenCommandOutput ['rstcheck, version 3.4.0']
|
||||||
|
|
||||||
|
AssertLinter 'rstcheck', [
|
||||||
|
\ ale#Escape('rstcheck') . ' --version',
|
||||||
|
\ ale#Escape('rstcheck')
|
||||||
|
\ . ' --config '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p:h'))
|
||||||
|
\ . ' %t',
|
||||||
|
\]
|
||||||
|
|
||||||
|
Execute(The version check should be cached):
|
||||||
|
GivenCommandOutput ['rstcheck, version 3.4.0']
|
||||||
|
|
||||||
|
AssertLinter 'rstcheck', [
|
||||||
|
\ ale#Escape('rstcheck') . ' --version',
|
||||||
|
\ ale#Escape('rstcheck')
|
||||||
|
\ . ' --config '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p:h'))
|
||||||
|
\ . ' %t',
|
||||||
|
\]
|
||||||
|
|
||||||
|
GivenCommandOutput []
|
||||||
|
|
||||||
|
AssertLinter 'rstcheck', [
|
||||||
|
\ ale#Escape('rstcheck')
|
||||||
|
\ . ' --config '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p:h'))
|
||||||
|
\ . ' %t',
|
||||||
|
\]
|
||||||
|
|
||||||
|
Execute(The default command should not include --config for older versions):
|
||||||
|
call ale#semver#ResetVersionCache()
|
||||||
|
GivenCommandOutput ['rstcheck, version 3.3.0']
|
||||||
|
|
||||||
|
AssertLinter 'rstcheck', [
|
||||||
|
\ ale#Escape('rstcheck') . ' --version',
|
||||||
|
\ ale#Escape('rstcheck') . ' %t',
|
||||||
|
\]
|
||||||
|
|
||||||
|
Execute(The command executable and options should be configurable):
|
||||||
|
call ale#semver#ResetVersionCache()
|
||||||
|
let b:ale_rst_rstcheck_executable = 'rstcheck2'
|
||||||
|
let b:ale_rst_rstcheck_options = '--ignore-language=cpp'
|
||||||
|
GivenCommandOutput ['rstcheck2, version 3.4.0']
|
||||||
|
|
||||||
|
AssertLinter 'rstcheck', [
|
||||||
|
\ ale#Escape('rstcheck2') . ' --version',
|
||||||
|
\ ale#Escape('rstcheck2')
|
||||||
|
\ . ' --ignore-language=cpp'
|
||||||
|
\ . ' --config '
|
||||||
|
\ . ale#Escape(expand('#' . bufnr('') . ':p:h'))
|
||||||
|
\ . ' %t',
|
||||||
|
\]
|
||||||
|
|
||||||
|
Execute(The linter should run with the current buffer directory as cwd):
|
||||||
|
AssertLinterCwd '%s:h'
|
||||||
Reference in New Issue
Block a user