0

I'm coding a custom rule for a Java. There are two Tree.KIND instances (STRING_LITERAL and ASSIGNMENT) to be captured. There is a particular line where both the logic of String Literal and Assignment throws an issue. But sonar test throws error saying

Unexpected at [Line number]

That particular line has the comment // Noncompliant to denote issue. But still the test case failed since the same error is caught by two different logic.

Manoj Kumar
  • 289
  • 4
  • 12

1 Answers1

2

There are two options how to solve this

  1. If possible, try to split the test code in a way that each issue is detected on distinct line. It shouldn't be very difficult to put newline between assignment and literal.
  2. You can use special syntax to say that issue is expected at line with given offset from the noncompliant comment by using Noncompliant@+[offset]syntax, where [offset] is replaced by integer. This way you can indicate that line has two issues by using one // Noncompliant comment and one comment with offset notation. // Noncompliant@+1 int x = "Hello".length(); // Noncompliant
Tibor Blenessy
  • 4,254
  • 29
  • 35
  • Thanks. I have custom rule, that call reportIssue during visitNode about 10 times, sometimes 2 issues per line. But sonar qube miss some issues. Local run by JavaCheckVerifier.verify works well. What is the reason, should I split my rule? – Woland Sep 28 '18 at 09:18
  • Please post a separate question with all the relevant infomation – Tibor Blenessy Sep 28 '18 at 14:44