Open TristanFAURE opened 2 months ago
I am taking the feedback of the community and will be glad to contribute this lint
You may also want to use tools such as Mozilla's rust-code-analysis to gather metrics by function.
You may also want to use tools such as Mozilla's rust-code-analysis to gather metrics by function.
Thanks for the information, i did not look yet the source code of clippy I would expect to plug a visitor on the AST but no problem if I have to run an AST. Do you know if an existing rule already use it ? (to have an example) I will check the library, thanks for the reference !
It includes a CLI tool which produces various metrics for every item (function, module, etc.), as json or toml files for example. It gives you the number of lines, the number of physical code lines, the number of blank lines. The rest is comments. It also gives you directly the number of comments, but a block with multiple lines will count as one comment so it may be less useful for you.
What it does
The lint counts the number of lines of the file and count the number of comments in the source file and do a percentage if the percentage is bellow a specific threshold a warning is raised
In tools like sonarqube it corresponds to comment_lines_density https://docs.sonarsource.com/sonarqube/latest/user-guide/code-metrics/metrics-definition/
Comment Density (%) = (Number of Comment Lines / (Total Lines - Empty Lines)) × 100
Advantage
It is important for some industries (like space industry), some coding standards request it
Drawbacks
This metric is generally not relevant and we want developers to think about relevant comments instead of number of lines of comments, but as said in Advantage it is something requested by standards
Example
Could be written as with 52 % (13 of 25) of comments: