summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorengarenar <jorengarenar@outlook.com>2024-01-14 13:04:23 +0100
committerGitHub <noreply@github.com>2024-01-14 21:04:23 +0900
commit94f764631d6f04d3c9293399be2a7e941fc65f5d (patch)
tree9069a812966b75cc430da19710ca065f493a0137
parent3dbf0b2202e7e8e745468cce06cb27a9ce4ea264 (diff)
downloadale-94f764631d6f04d3c9293399be2a7e941fc65f5d.zip
Fix chktex highlighting wrong column when using tabs instead of spaces (#4661)
* 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 * Add test_tex_chktex.vader * Use functions to set g: variables in ale_linters/tex/chktex.vim * Update ale_linters#tex#chktex#GetCommand() to use '%e'
-rw-r--r--ale_linters/tex/chktex.vim28
-rw-r--r--test/linter/test_tex_chktex.vader27
2 files changed, 40 insertions, 15 deletions
diff --git a/ale_linters/tex/chktex.vim b/ale_linters/tex/chktex.vim
index 160baf0d..7708b1ea 100644
--- a/ale_linters/tex/chktex.vim
+++ b/ale_linters/tex/chktex.vim
@@ -1,29 +1,27 @@
" Author: Andrew Balmos - <andrew@balmos.org>
" 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
@@ -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'
\})
diff --git a/test/linter/test_tex_chktex.vader b/test/linter/test_tex_chktex.vader
new file mode 100644
index 00000000..7052c367
--- /dev/null
+++ b/test/linter/test_tex_chktex.vader
@@ -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'