Skip to content

Commit

Permalink
Check chktex version instead of trying -S option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorenar committed Feb 26, 2024
1 parent 60b3d30 commit 96f85eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
17 changes: 13 additions & 4 deletions ale_linters/tex/chktex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
call ale#Set('tex_chktex_executable', 'chktex')
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 = ''

" Avoid bug when used without -p (last warning has gibberish for a filename)
let l:options .= ' -v0 -p stdin -q'

" Avoid bug of reporting wrong column when using tabs (issue #723)
if system('chktex -S') !~? 'invalid option'
if ale#semver#GTE(a:version, [1, 7, 7])
let l:options .= ' -S TabSize=1'
endif

Expand Down Expand Up @@ -49,7 +53,12 @@ endfunction

call ale#linter#Define('tex', {
\ 'name': 'chktex',
\ 'executable': {b -> ale#Var(b, 'tex_chktex_executable')},
\ 'command': function('ale_linters#tex#chktex#GetCommand'),
\ 'executable': function('ale_linters#tex#chktex#GetExecutable'),
\ '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'
\})
33 changes: 28 additions & 5 deletions test/linter/test_tex_chktex.vader
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
Before:
call ale#assert#SetUpLinterTest('tex', 'chktex')

GivenCommandOutput ['ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann']

After:
call ale#assert#TearDownLinterTest()

Execute(The default command should be correct):
AssertLinter 'chktex',
AssertLinter 'chktex', [
\ ale#Escape('chktex') . ' --version',
\ ale#Escape('chktex')
\ . ' -v0 -p stdin -q -S TabSize=1'
\ . ' -I'
\ . ' -v0 -p stdin -q'
\ . ' -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):
let g:ale_tex_chktex_executable = 'bin/foo'

AssertLinter 'bin/foo',
\ ale#Escape('bin/foo')
\ . ' -v0 -p stdin -q -S TabSize=1'
\ . ' -v0 -p stdin -q'
\ . ' -I'

Execute(The options should be configurable):
let b:ale_tex_chktex_options = '--something'

AssertLinter 'chktex',
\ ale#Escape('chktex')
\ . ' -v0 -p stdin -q -S TabSize=1'
\ . ' -v0 -p stdin -q'
\ . ' --something'

0 comments on commit 96f85eb

Please sign in to comment.