Ale: chktex reports issues from the wrong files

Created on 28 Feb 2017  路  9Comments  路  Source: dense-analysis/ale

When you run chktex on a file which imports other files, where those other files produce warnings/errors, those warnings or errors are reported in the original file incorrectly.

bug help wanted

Most helpful comment

Hi, this is still an issue with both chktex and lacheck. I'm using Vim 8.0 on Debian, newly-installed ALE from github, chktex 1.7.6, and lacheck 1.26. I haven't used syntax checkers in the past, so I probably won't use proper jargon. Haven't set any options in ale, so everything should be at its default state.

MWE: Two files, one of which \inputs the other. The inputted file has a simple error (no nonbreaking space before a \ref).
File 1 (ale_test.tex):

\documentclass{article}
\begin{document}
\section{Test}\label{test}
\input{ale_input}
\end{document}

File 2 (ale_input.tex):

Here is a reference in the input file without a nonbreaking space: \ref{test}.

We expect ALE to highlight line 1 in ale_input.tex. Actual result is that line 1 is marked in both files. Both display this warning when the cursor is on line 1:

perhaps you should insert a `~' before "\ref"

If I move the \ref in ale_input.tex to a different line, the reported error in ale_test.tex moves accordingly.

Both chktex and lacheck check \input'd files. Here's the output from lacheck when I run it by hand:

~/test $ lacheck ale_test.tex 
** ale_input:
"ale_input.tex", line 1: perhaps you should insert a `~' before "\ref"

And chktex:

~/test $ chktex ale_test.tex 
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with PCRE regex support.
Warning 2 in ale_input.tex line 1: Non-breaking space (`~') should have been used.
Here is a reference in the input file without a nonbreaking space: \ref{test}.  
                                                                  ^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.

So this might be fixable by changing the regex used to match the current filename.

Additional note: if I open ale_test.tex from outside its directory, we don't get this error. This is because chktex and lacheck fail to find the error in ale_input.tex, because they can't find the file:

~ $ lacheck test/ale_test.tex 
** ale_input:
"test/ale_test.tex", line 4: Could not open "ale_input"

~ $ chktex test/ale_test.tex 
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with PCRE regex support.
chktex: WARNING -- Unable to open the TeX file `ale_input'.
Warning 27 in test/ale_test.tex line 4: Could not execute LaTeX command.
\input{ale_input}  
^^^^^^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.

All 9 comments

Same goes for lacheck.

In :help error-file-format, I see the native capability of supporting multiple files. We need to make the compiler output the file name and then scan it with an appropriate %f in an entry of the errorformat option.
Or are you using some different work-around for generating the loc/qf list? Did not have a look at the code yet but could give it a try.

EDIT: Oh I understand the challenge, you are passing the buffers via stdin to the checkers, thus the filename is already lost at this point?

ALE doesn't use errorformat and so on at all.

I don't use chktex myself. If anyone wants to have a go at fixing this, go for it. If not, I'll get to it eventually.

Alright I will give it a try for both lacheck and chktex.

Unfortunately I did not yet find the code which further processes the returned (by linter handler) list of dictonaries.

call add(l:output, {                                                                                                                                                   
      \   'bufnr': a:buffer,                                                                                                                                                 
      \   'lnum': l:match[1] + 0,                                                                                                                                            
      \   'col': 0,                                                                                                                                                          
      \   'text': l:match[2],                                                                                                                                                
      \   'type': 'W',                                                                                                                                                       
      \}) 

in ale_linters/tex/lacheck.vim

Is there support for a key:value pair for the filename already?

I would propose to not just ignore out-of-file errors, since tex's \input{otherfile.tex} calls act exactly like if the input was written in the current file.

Is there support for a key:value pair for the filename already?

I'm not sure what you mean by this. All items returned from the callback function should be errors to display for the file being checked.

So the returned list is a list of dictionaries: one dictionary for each error, and each dictionary contains keys like: bufnr,lnum,col,text,type. What I meant is how (or where) this dictionary (for a single error) gets further processed for display in the loc list. And especially whether there exists some dedicated key (like file, filename, or alike) in the dictionary for a filename, already?

Only the buffer number is used for setting errors. Each buffer in Vim has a number, and the buffer number is recorded when ALE starts checking a file. This buffer number is passed around everywhere, and then the buffer number is used to set the errors for a given buffer.

For fixing the bug for this GitHub issue, the way to go about it is to first check if the lines of output from chktex return the filenames the errors and warnings are for. If the command can either return the filename being checked, or something like '<stdin>', etc., then either can be used to filter the matches down to only those for the file being checked.

I don't know too much about chktex myself.

Of course. I would just love to preserve the file names and put them in the loc-list, since the loc-list of capable of also allowing jumps to other files.

I think this was fixed a while ago. If someone can paste some output from the command where this is a problem, I'll add a test for it and fix that.

Hi, this is still an issue with both chktex and lacheck. I'm using Vim 8.0 on Debian, newly-installed ALE from github, chktex 1.7.6, and lacheck 1.26. I haven't used syntax checkers in the past, so I probably won't use proper jargon. Haven't set any options in ale, so everything should be at its default state.

MWE: Two files, one of which \inputs the other. The inputted file has a simple error (no nonbreaking space before a \ref).
File 1 (ale_test.tex):

\documentclass{article}
\begin{document}
\section{Test}\label{test}
\input{ale_input}
\end{document}

File 2 (ale_input.tex):

Here is a reference in the input file without a nonbreaking space: \ref{test}.

We expect ALE to highlight line 1 in ale_input.tex. Actual result is that line 1 is marked in both files. Both display this warning when the cursor is on line 1:

perhaps you should insert a `~' before "\ref"

If I move the \ref in ale_input.tex to a different line, the reported error in ale_test.tex moves accordingly.

Both chktex and lacheck check \input'd files. Here's the output from lacheck when I run it by hand:

~/test $ lacheck ale_test.tex 
** ale_input:
"ale_input.tex", line 1: perhaps you should insert a `~' before "\ref"

And chktex:

~/test $ chktex ale_test.tex 
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with PCRE regex support.
Warning 2 in ale_input.tex line 1: Non-breaking space (`~') should have been used.
Here is a reference in the input file without a nonbreaking space: \ref{test}.  
                                                                  ^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.

So this might be fixable by changing the regex used to match the current filename.

Additional note: if I open ale_test.tex from outside its directory, we don't get this error. This is because chktex and lacheck fail to find the error in ale_input.tex, because they can't find the file:

~ $ lacheck test/ale_test.tex 
** ale_input:
"test/ale_test.tex", line 4: Could not open "ale_input"

~ $ chktex test/ale_test.tex 
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with PCRE regex support.
chktex: WARNING -- Unable to open the TeX file `ale_input'.
Warning 27 in test/ale_test.tex line 4: Could not execute LaTeX command.
\input{ale_input}  
^^^^^^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

catbaron0 picture catbaron0  路  3Comments

trevordmiller picture trevordmiller  路  4Comments

aressler38 picture aressler38  路  3Comments

ilyakopy picture ilyakopy  路  4Comments

sodiumjoe picture sodiumjoe  路  4Comments