Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chktex highlighting wrong column when using tabs instead of spaces #4661

Merged
merged 4 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions ale_linters/tex/chktex.vim
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
" Author: Andrew Balmos - <[email protected]>
" Description: chktex for LaTeX files

let g:ale_tex_chktex_executable =
\ get(g:, 'ale_tex_chktex_executable', 'chktex')

let g:ale_tex_chktex_options =
\ get(g:, 'ale_tex_chktex_options', '-I')
call ale#Set('tex_chktex_executable', 'chktex')
call ale#Set('tex_chktex_options', '-I')

function! ale_linters#tex#chktex#GetCommand(buffer) abort
" Check for optional .chktexrc
let l:chktex_config = ale#path#FindNearestFile(
\ a:buffer,
\ '.chktexrc')
let l:options = ''

let l:command = ale#Var(a:buffer, 'tex_chktex_executable')
" Avoid bug when used without -p (last warning has gibberish for a filename)
let l:command .= ' -v0 -p stdin -q'
let l:options .= ' -v0 -p stdin -q'
" Avoid bug of reporting wrong column when using tabs (issue #723)
let l:options .= ' -s TabSize=1'

" Check for optional .chktexrc
let l:chktex_config = ale#path#FindNearestFile(a:buffer, '.chktexrc')

if !empty(l:chktex_config)
let l:command .= ' -l ' . ale#Escape(l:chktex_config)
let l:options .= ' -l ' . ale#Escape(l:chktex_config)
endif

let l:command .= ' ' . ale#Var(a:buffer, 'tex_chktex_options')
let l:options .= ' ' . ale#Var(a:buffer, 'tex_chktex_options')

return l:command
return '%e' . l:options
endfunction

function! ale_linters#tex#chktex#Handle(buffer, lines) abort
Expand All @@ -48,7 +46,7 @@ endfunction

call ale#linter#Define('tex', {
\ 'name': 'chktex',
\ 'executable': 'chktex',
\ 'executable': {b -> ale#Var(b, 'tex_chktex_executable')},
\ 'command': function('ale_linters#tex#chktex#GetCommand'),
\ 'callback': 'ale_linters#tex#chktex#Handle'
\})
27 changes: 27 additions & 0 deletions test/linter/test_tex_chktex.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Before:
call ale#assert#SetUpLinterTest('tex', 'chktex')

After:
call ale#assert#TearDownLinterTest()

Execute(The default command should be correct):
AssertLinter 'chktex',
\ 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'
\ . ' -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'
\ . ' --something'