How to judge the comment rate of Java functions by using sonar scan?

  1. Version information:

Sonarqube: 7.9.3 community version

maven:3.6.3

  1. Desired effect:

(1) When using MVN sonar: Sonar command to scan java project, how to judge the annotation rate of Java function?

(2) Can different languages be set in the same project directory?

For example:

Scan range path: src/main

Expectation: scan annotation rate and bug in src/main/Java path;

In the src/main/test path, only bug scanning is performed, and no annotation rate scanning is performed

I hope to get a reply as soon as possible. Thank you!

Hi,

I’m not understanding the question. Specifically, what do you mean by “annotation rate”? Could you rephrase/restate?

 
Ann

Sorry, my description may not be accurate. What I want to express is: can I make a comments (%) for Java functions.
image

That is to say, only judge the comments (%) of the Java function.

This is the requirement of our recent project, and if it can be realized through API interface is ok. Can this be achieved?

Hi,

So you want to raise an issue when the ratio of comments to code is too low in a method? I believe you’d have to implement that rule yourself. There is a rule that raises an issue when there’s no Javadoc, but it can’t tell the difference between real documentation & an empty stub provided by the IDE.

 
Ann

@Ann

Can you tell me how to customize this rule about the ratio of comments to code, in which file or API interface it can be customized?Or do you need to modify the source file and repackage it?I want to know the location of the file?
Thank you very much!

baiguanghui

Hi baiguanghui,

I can’t tell you off-hand how to do this. The docs should get you started. And the rule you want to modify is somewhere in the Java analysis code. Sorry but I’m not familiar with the code base, so I can’t point you to the file.

If you have specific development questions, feel free to open new threads in the ‘Writing rules’ category.

 
Ann

How to open a new threads in the ‘Writing rules’ category, can you tell me?

The same way you opened this one.