List all rule keys whose warnings have no line number associated with it

Hi all,

I am using sonar-java APIs to mine violations in this project. I wanted to know which checks in sonar-java never have a line number associated with them (it is -1). For example, all violations of S1996 do not have any line number associated with them. We can deduce that from the source code here. Is there a way to get this information statically?

Hi,

Welcome to the community!

Are you trying to extract this data from SonarLint or SonarQube/SonarCloud?

If the latter, the Web APIs will be of some help. I’m looking at the api/issues/search docs in our dogfooding instance of SonarQube (the SonarCloud API should be very similar). While you can’t search by line_number=-1, you could search by rule (if you know the relevant rules).

Off-hand there are two types of rules that wouldn’t raise issues on a particular file line; those that raise them at file level and those that raise them at directory level and above. For the latter type, searching by component with the addition of the onComponentOnly parameter should do the trick.

And BTW, would you mind explaining your use case? I’m curious.

 
HTH,
Ann

Hi Ann,

Thank you for your response!

Are you trying to extract this data from SonarLint or SonarQube/SonarCloud?

I was trying to extract this data by parsing the source code of SonarJava not from SonarQube. Why? I will explain my use case.

I am working on a project called Sorald which automatically repairs violations reported by SonarJava static analyser. Our code is structured in a way that only lets us fix violations that have a line number associated with them. As of now, we ignore those violations in our code, but we are not sure what exactly they are.

I have found a solution to get this data. I can perform an intersection of rules I gets from my project and the rules stored in this map here.

Regards,
Aman

1 Like

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