Is this rule broken or is it me? Options for preventing the inevitable fallout

typescript
sonarqube

(Nick) #1

Using: Version 7.0 (build 36138)
Trying: To establish sane comment density rules that won’t cause our dev team to riot.
Tried: Dropping percentage down to minimal.

As shown below (or in the attached screen snippet) my source:

Is only 6 lines long total.
2 of those lines are blank.
3 of those lines are comments.
1 of those lines is code.

I don’t want to turn the rule off, and I’d rather go back to the default 25%, but this is ridiculous. I figure I’m missing something obvious about the configuration. Looking for advice and ideas to try that I might have missed. How can I make this rule behave. Is there a way to get sonar to ignore blank lines (is it even counting them now?) Is there a way to fix the ration to be “lines of actual code” : “lines of actual comments”?


(Elena Vilchik) #2

Hi @melgish

Sorry for the delay.

I think the problem is in the leading comments. SonarTS (who is computing comment lines) does not count all comments before first line of code (see https://github.com/SonarSource/SonarTS/blob/master/sonarts-core/src/runner/metrics.ts#L74). So your file will have 0 comment lines (you can see that clicking on the icon next to “100% coverage” text).

And FYI formula to compute comment density is comment_lines / (comment_lines + lines_of_code).