The language I’m analyzing relies on include files, and this means that some issues can be reported multiple times exactly at the same location (for example, an unused variable in an include file used in 10 “main” procedures). In many cases (but not all), it doesn’t make any sense to report an issue more than once.
Is it possible to query the SensorContext object before calling SensorContext#newIssue(), and see if a specific issue has already been raised at a given location ? I would like to avoid having to duplicate the list of issues in each rule.
For performance reasons (and for simplicity of API changes) we have progressively removed most “read” APIs. Sensor are only able to “push” data, without the ability to read them back.
So you’ll have to find your own strategy to deduplicate issues.
For example the strategy used by SonarC# is to keep an in-memory set: https://github.com/SonarSource/sonar-dotnet/blob/366b5b7589beeede0d21019afa645e9c65c6798d/sonar-dotnet-shared-library/src/main/java/org/sonarsource/dotnet/shared/plugins/SarifParserCallbackImpl.java#L78
It makes sense to have a clean and simple API. I’ll include the code in my rules, thanks a lot for your answer !