Fix chktex highlighting wrong column when using tabs instead of spaces (#4727)

* Fix '-s' to be '-S' when setting 'TabSize=1' for chktex

Fixes #4712
Closes #4725

* Check if chktex's -S option is available

* Check chktex version instead of trying -S option
This commit is contained in:
Jorengarenar 2024-02-27 00:54:14 +01:00 committed by GitHub
parent 00dcf52d6f
commit 9b8413a825
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 5 deletions

View File

@ -4,12 +4,20 @@
call ale#Set('tex_chktex_executable', 'chktex') call ale#Set('tex_chktex_executable', 'chktex')
call ale#Set('tex_chktex_options', '-I') call ale#Set('tex_chktex_options', '-I')
function! ale_linters#tex#chktex#GetCommand(buffer) abort function! ale_linters#tex#chktex#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'tex_chktex_executable')
endfunction
function! ale_linters#tex#chktex#GetCommand(buffer, version) abort
let l:options = '' let l:options = ''
" Avoid bug when used without -p (last warning has gibberish for a filename) " Avoid bug when used without -p (last warning has gibberish for a filename)
let l:options .= ' -v0 -p stdin -q' let l:options .= ' -v0 -p stdin -q'
" Avoid bug of reporting wrong column when using tabs (issue #723) " Avoid bug of reporting wrong column when using tabs (issue #723)
if ale#semver#GTE(a:version, [1, 7, 7])
let l:options .= ' -S TabSize=1'
endif
" Check for optional .chktexrc " Check for optional .chktexrc
let l:chktex_config = ale#path#FindNearestFile(a:buffer, '.chktexrc') let l:chktex_config = ale#path#FindNearestFile(a:buffer, '.chktexrc')
@ -45,7 +53,12 @@ endfunction
call ale#linter#Define('tex', { call ale#linter#Define('tex', {
\ 'name': 'chktex', \ 'name': 'chktex',
\ 'executable': {b -> ale#Var(b, 'tex_chktex_executable')}, \ 'executable': function('ale_linters#tex#chktex#GetExecutable'),
\ 'command': function('ale_linters#tex#chktex#GetCommand'), \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
\ buffer,
\ ale_linters#tex#chktex#GetExecutable(buffer),
\ '%e --version',
\ function('ale_linters#tex#chktex#GetCommand'),
\ )},
\ 'callback': 'ale_linters#tex#chktex#Handle' \ 'callback': 'ale_linters#tex#chktex#Handle'
\}) \})

View File

@ -1,14 +1,37 @@
Before: Before:
call ale#assert#SetUpLinterTest('tex', 'chktex') call ale#assert#SetUpLinterTest('tex', 'chktex')
GivenCommandOutput ['ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann']
After: After:
call ale#assert#TearDownLinterTest() call ale#assert#TearDownLinterTest()
Execute(The default command should be correct): Execute(The default command should be correct):
AssertLinter 'chktex', AssertLinter 'chktex', [
\ ale#Escape('chktex') . ' --version',
\ ale#Escape('chktex') \ ale#Escape('chktex')
\ . ' -v0 -p stdin -q' \ . ' -v0 -p stdin -q'
\ . ' -I' \ . ' -I',
\]
" The version check should be cached.
GivenCommandOutput []
AssertLinter 'chktex', [
\ ale#Escape('chktex')
\ . ' -v0 -p stdin -q'
\ . ' -I',
\]
" Try newer version
call ale#semver#ResetVersionCache()
GivenCommandOutput ['ChkTeX v1.7.8 - Copyright 1995-96 Jens T. Berger Thielemann']
AssertLinter 'chktex', [
\ ale#Escape('chktex') . ' --version',
\ ale#Escape('chktex')
\ . ' -v0 -p stdin -q'
\ . ' -S TabSize=1'
\ . ' -I',
\]
Execute(The executable should be configurable): Execute(The executable should be configurable):
let g:ale_tex_chktex_executable = 'bin/foo' let g:ale_tex_chktex_executable = 'bin/foo'