-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #4727
Conversation
The Or we can leave this out altogether since the |
@hsanson I had added a check if the option is available |
After installing latest chktex 1.7.8 and doing several test I was able to understand what this PR tries to do. I made some modifications (see diff below) that you can add to this PR to improve it:
Save the following diff in a file and use git-apply to apply it: diff --git a/ale_linters/tex/chktex.vim b/ale_linters/tex/chktex.vim
index dd064127..ca336326 100644
--- a/ale_linters/tex/chktex.vim
+++ b/ale_linters/tex/chktex.vim
@@ -4,22 +4,28 @@
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'
- let l:options .= ' -S TabSize=1'
- endif
-
" Check for optional .chktexrc
let l:chktex_config = ale#path#FindNearestFile(a:buffer, '.chktexrc')
if !empty(l:chktex_config)
let l:options .= ' -l ' . ale#Escape(l:chktex_config)
+ else
+ " If no configuration file is found try to set TabSize value based
+ " on buffer tabstop (#723). Note -S option is available on chktex
+ " 1.7.7+.
+ if ale#semver#GTE(a:version, [1, 7, 7])
+ let l:options .= ' -S TabSize=' . &tabstop
+ endif
endif
let l:options .= ' ' . ale#Var(a:buffer, 'tex_chktex_options')
@@ -49,7 +55,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'
\})
diff --git a/test/linter/test_tex_chktex.vader b/test/linter/test_tex_chktex.vader
index 94ce0d49..1e037004 100644
--- a/test/linter/test_tex_chktex.vader
+++ b/test/linter/test_tex_chktex.vader
@@ -1,21 +1,44 @@
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=' . &tabstop
+ \ . ' -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):
@@ -23,5 +46,5 @@ Execute(The options should be configurable):
AssertLinter 'chktex',
\ ale#Escape('chktex')
- \ . ' -v0 -p stdin -q -S TabSize=1'
+ \ . ' -v0 -p stdin -q'
\ . ' --something' |
@Jorengarenar after further testing it seems you are correct and TabSize must be fixed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work and patience.
Repetition of #4661, taking into account #4712
Fixes #723
chktex implemented bug #56486: Allow setting options on 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.