简体   繁体   中英

Multiple issues in a single line sonar plugin maven test

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM