Hello,
I am currently re-implementing the two Checkstyle checks NoWhitespaceAfter and NoWhitespaceBefore rules in SonarQube. So I have …
NoWhitespaceAfter.java
NoWhitespaceBefore.java
AbstractNoWhitespace.java
(, from which both rules are inheriting, to unite identical logic snippets.)
Unit tests are passing. However, when testing both rules on a local SonarQube server each rule activated on its own is also functioning but as soon as both rules are activated together both rules are detecting compliance and noncompliance cases wrong. For example, the NoWhitespaceBefore
only finds whitespaces before <
and >
tokens but not the other tokens like ++ -- . ... ;
when I am checking my test file NoWhitespaceBeforeCheck_AllowLineBreaksFalse_TestFile
with SonarLint (as seen on the screenshot).
Please check out my example project to this issue. I’d be really thankful if someone would be looking into that. I also tried the following on a separate branch but the problem persists:
- Remove the
AbstractNoWhitespace
to make sure that there is no dependency between both rules anymore. - I am using
context.getFileLines()
(code line) which extracts the Java code to analyze to find neighboring whitespaces. On this branch instead of calling it once I am calling it for every token to visit, to make sure that I am not analyzing outdated code snippets.
I am also wondering if it’s not allowed to override both visitNode(Tree)
AND visitToken(SyntaxToken)
which I am doing in NoWhitespaceBefore.java.
Kind regards,
Johannes