Sonar report - issues are not reported against contributor introducing the error

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube: 9.0.0
  • what are you trying to achieve
    we are using SonarQube for TypeScript project,
    Scenario: Developer 1 cerates new file, no issues reported on initial commit, Developer 2 from team removes a code block/function added my initial contributor, which leads to “Unnecessary imports should be removed” issue, the import used in removed code block was added by developer 1 in initial commit, which becomes unused as code block is removed, In this case issue should be assigned to Developer 2, but SonarQube assigns issue to Developer 1, which is wrong, ideally issue should have be assigned to Developer 2, who really introduced the issue, instead of one who was original author.
  • what have you tried so far to achieve this
    To be honest just some google search, not much of research, as I am not sure if its new requirement or a bug.

Hey there.

Thanks for mentioning this.

To be honest – it’s a known limitation for rules like this. I’ll quote an old post:

For the deletion case, figuring out that something is unused not because it was stubbed in and then never called, but because a different line (which line? where?) was edited or deleted would mean examining every line of the file and comparing the current version to the previous version which, frankly just doesn’t seem worth the effort for something like an unused parameter.

Thinking about this a few years later, I wonder if one possible solution for rules like this would be to assign the last person who committed the file. :man_shrugging:

These rules (unused import, unused variable) also cause some trouble for issue backdating – they prevent us from being able to always backdate issues to the last time a line was changed.

And with these rules being few and far between, it’s difficult to justify a change for these corner cases.

In any case, I’m happy to move your post to the Product Manager for a Day - Sonar Community category to see if it triggers any further discussion.

1 Like

Hello Colin, thanks for taking this topic for further discussion.

On the possible solution, My initial though was issue should be assigned to author who introduced the issues at first place, but like your option to assign to last contributor, as it is also last committer responsibility to cleanup past mess :slight_smile: this will also avoid if contributor leading to the issue has moved out of the team or organization. There is no point in having an issue where assignee is no longer part of the team.

Thanks
Praveen.

@Colin I see post is not moved to Product Manager for a Day - Sonar Community category, can you please help here, interested to take this topic forward!

Thanks
Praveen

Done!