jdneo / vscode-checkstyle

Checkstyle extension for VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle
GNU Lesser General Public License v3.0
68 stars 15 forks source link

Fix the error column that’s reported to VS Code #292

Closed karlvr closed 3 years ago

karlvr commented 3 years ago

This fixes the reported column of errors in VS Code in code that uses tab indentation.

CheckStyle has funny treatment of tabs. Its error.getColumn() returns a number that treats tabs as being however many spaces. Fortunately getolumnCharIndex() returns the correct value to send back to VS Code.

karlvr commented 3 years ago

@jdneo hmm, I think I might be out by one on this... it's reporting the error 1 character too far to the left...

karlvr commented 3 years ago

@jdneo yeah, checked in the CheckStyle code and it is 0-based, so I'll add 1 to it.

jdneo commented 3 years ago

Hi @karlvr

Sorry but maybe a very stupid question from me: How can I reproduce this problem?

karlvr commented 3 years ago

@jdneo No problem! If your file has tab indentation, and is indented a couple of tabs, you'll see that before this patch the highlighted error in vs code is too far to the right (by 3 spaces for each tab if your tabs are 4 spaces)

jdneo commented 3 years ago

I got your point. So how should the checkstyle configuration looks like for this case?

I'm using

<module name="RegexpSinglelineJava">
    <property name="format" value="^\t* "/>
    <property name="message" value="Indent must use tab characters"/>
    <property name="ignoreComments" value="true"/>
</module>

<module name="Indentation">
    <property name="basicOffset" value="2"/>
</module>

But seems it's not a correct way to reproduce

karlvr commented 3 years ago

@jdneo Actually, it's for any check not just indentation checks. If you use tab indentation in your final, any check appears highlighted in the wrong spot. I used a FinalParameterCheck in my case.

Maybe it's because I have tabWidth set to 4 in my Checkstyle config, but I thought it defaulted to 8!

jdneo commented 3 years ago

Yes I can see it use the final check:

image