Can you access if the line has code coverage in new rule

Hi all,
I’m trying to create a rule for a function and check if the function has been covered or not. If none of the lines are covered in the function, I want to create an issue. In SQ, which lines are covered can be seen but can you access the same information when writing a new rule check? Does such method exists in the library?

Thanks,

Hi,

Welcome to the community!

I’ve moved your thread to the ‘Writing rules’ category. It will help if you’ll add the language in question, either as a tag or post.

 
:smiley:
Ann

I’m currently using the C++ community plugin to write the rule. So, I thought it was not relevant for the question. The solution would also work for the Python plugin if it exists. The code coverage result comes from a ‘Generic Test Data format’.

Thanks in advance.

Hi,

Well… yes and no. That plugin isn’t supported here. To write a rule based on it, you’ll need to ask its maintainers how to get this information. So you’ll need to open an issue on that project.

 
Good luck! :smiley:
Ann

Thank you for your answer. For the people following the topic, I asked their maintainers and no, it is not possible to do it with the C/C++ community plugin.

Can I do it with also official plugins? For example, if I used Java plugin can I do it with ‘generic test data’ or do I have to use Jacoco? Or is it possible with Python plugin? I’m asking because we are planning to do it for those plugins in the future.

I thought it might have been possible with API functions but seems it’s not possible that way.

Thanks in advance.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Hi,

That really depends on the language. Some support custom rules and others don’t.

The source of the coverage data would really be irrelevant. However, it’s worth pointing out that this is probably a rule that would run server-side rather than analysis side. If I run a rules search on Next all the rules with “coverage” in the text are in repositories named “Common [language]”, which means they’re implemented in SonarQube core and run server-side. The point of all this is to say, it’s not clear to me how feasible it would be to write coverage-related rules in a plugin. (This is not my area of expertise, so I could be entirely wrong on that point.)

 
Ann

1 Like