[JAVA] squid:S00103 (Lines should not be too long) - enhancement - ignore lines inside <pre> block

620 views
Skip to first unread message

Adam Gabryś

unread,
Jul 30, 2016, 10:33:15 AM7/30/16
to SonarQube

Hello,
I have a lot of the squid:S00103 (Lines should not be too long) issues on example code placed in Javadoc <pre> blocks.

Is there any chance that this rule will ignore lines placed in <pre> blocks?

Link to sources: https://github.com/gabrysbiz/maven-plugin-utils/blob/develop/src/main/java/biz/gabrys/maven/plugin/util/parameter/ParametersLogBuilder.java#L40

Regards,
Adam Gabryś

Michael Gumowski

unread,
Aug 2, 2016, 11:23:39 AM8/2/16
to Adam Gabryś, SonarQube
Hey Adam,

Thanks for the feedback. There is indeed an issue when dealing with Javadoc. I'm however not sure that only excluding the line within the "<pre>" tags is the correct solution to your issue. In your cases, it's the usage of @link which considerably increase the size of the line. As the size of such textual reference cannot be reduced, I would prefer to simply exclude lines using @link, because you can use such links anywhere in a Javadoc block of comment.

What do you think?

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/BLU436-SMTP211F4416185EE55AD5E675898020%40phx.gbl.
For more options, visit https://groups.google.com/d/optout.

Adam Gabryś

unread,
Aug 2, 2016, 3:49:09 PM8/2/16
to Michael Gumowski, SonarQube

Hi Michael,
I agree that rule should ignore lines with @link - additionally it should also ignore @see (the same situation). That fix will not solve all problems with "<pre>" blocks but it is definitely easier to implement ;-)

https://github.com/SonarSource/sonar-java/blob/master/java-checks/src/main/java/org/sonar/java/checks/TooLongLineCheck.java#L79

One hint: maybe rule should ignore @link if its length is longer that maxLineLength - @linkStartPosition.

Noncompliant Code Example:
/**
  * {@link very.long.link.so.rule.should.ignore.this.line very long text which exceeds maximum length}
  * {@link shortlink} this line can be split, but I'm very lazy programmer and I don't like click "format code" in my IDE
  * @see this.should.never.be.split.SomethingInterestingWithLongName#getThatInterestingThing(String)
  */

Compliant Solution:
/**
  * {@link very.long.link.so.rule.should.ignore.this.line very long text which exceeds maximum length}
  * {@link shortlink} this line is split, because I have learned
  * how to format code in my IDE
  * @see this.should.never.be.split.SomethingInterestingWithLongName#getThatInterestingThing(String)
  */

Regards,
Adam Gabryś

Michael Gumowski

unread,
Aug 3, 2016, 2:59:09 AM8/3/16
to Adam Gabryś, SonarQube
Hey,

Agreed to also handle @see! JIRA ticket created: SONARJAVA-1800

Cheers,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

Reply all
Reply to author
Forward
0 new messages