From a79af6f8944dfac737cd399387c304d0ad0ef90d Mon Sep 17 00:00:00 2001 From: Jorengarenar Date: Fri, 24 Nov 2023 19:05:17 +0100 Subject: [PATCH 1/4] Fix chktex highlighting wrong column when using tabs instead of spaces Fixes #723 chktex implemented feature request [1] for allowing setting options from the command line. Thanks to that we can tell it to treat tab character as of one space width, i.e. one char. That means, after we translate the output back to Vim columns, we get correct numbers. [1]: https://savannah.nongnu.org/bugs/?56486 --- ale_linters/tex/chktex.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ale_linters/tex/chktex.vim b/ale_linters/tex/chktex.vim index 160baf0d09..e16a274752 100644 --- a/ale_linters/tex/chktex.vim +++ b/ale_linters/tex/chktex.vim @@ -16,6 +16,8 @@ function! ale_linters#tex#chktex#GetCommand(buffer) abort 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' + " Avoid bug of reporting wrong column when using tabs (issue #723) + let l:command .= ' -s TabSize=1' if !empty(l:chktex_config) let l:command .= ' -l ' . ale#Escape(l:chktex_config) From 724c2791ac56b72f2a51c9ff8c191fce5473386f Mon Sep 17 00:00:00 2001 From: Jorengarenar Date: Sun, 17 Dec 2023 00:02:26 +0100 Subject: [PATCH 2/4] Add test_tex_chktex.vader --- test/linter/test_tex_chktex.vader | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/linter/test_tex_chktex.vader diff --git a/test/linter/test_tex_chktex.vader b/test/linter/test_tex_chktex.vader new file mode 100644 index 0000000000..3522b44715 --- /dev/null +++ b/test/linter/test_tex_chktex.vader @@ -0,0 +1,25 @@ +Before: + call ale#assert#SetUpLinterTest('tex', 'chktex') + +After: + call ale#assert#TearDownLinterTest() + +Execute(Executable should default to chktex): + 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' From c6c44664d356d21c7096c89b58ddc4e5e4790caf Mon Sep 17 00:00:00 2001 From: Jorengarenar Date: Sun, 17 Dec 2023 00:35:59 +0100 Subject: [PATCH 3/4] Use functions to set g: variables in ale_linters/tex/chktex.vim --- ale_linters/tex/chktex.vim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ale_linters/tex/chktex.vim b/ale_linters/tex/chktex.vim index e16a274752..8f5d56a165 100644 --- a/ale_linters/tex/chktex.vim +++ b/ale_linters/tex/chktex.vim @@ -1,11 +1,8 @@ " Author: Andrew Balmos - " 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 @@ -50,7 +47,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' \}) From c911d90871499755ba94797882f522d1ce421669 Mon Sep 17 00:00:00 2001 From: Jorengarenar Date: Sun, 17 Dec 2023 00:55:12 +0100 Subject: [PATCH 4/4] Update ale_linters#tex#chktex#GetCommand() to use '%e' --- ale_linters/tex/chktex.vim | 19 +++++++++---------- test/linter/test_tex_chktex.vader | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ale_linters/tex/chktex.vim b/ale_linters/tex/chktex.vim index 8f5d56a165..7708b1eaec 100644 --- a/ale_linters/tex/chktex.vim +++ b/ale_linters/tex/chktex.vim @@ -5,24 +5,23 @@ 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:command .= ' -s TabSize=1' + 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 diff --git a/test/linter/test_tex_chktex.vader b/test/linter/test_tex_chktex.vader index 3522b44715..7052c36738 100644 --- a/test/linter/test_tex_chktex.vader +++ b/test/linter/test_tex_chktex.vader @@ -4,17 +4,19 @@ Before: After: call ale#assert#TearDownLinterTest() -Execute(Executable should default to chktex): +Execute(The default command should be correct): AssertLinter 'chktex', \ ale#Escape('chktex') - \ . ' -v0 -p stdin -q -s TabSize=1 -I' + \ . ' -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' + \ . ' -v0 -p stdin -q -s TabSize=1' + \ . ' -I' Execute(The options should be configurable): let b:ale_tex_chktex_options = '--something'