I’d like Sonar to flag the issue in both cases so that me and my teammates can catch issues when they are going into our Team/Dev/QA environments before they go into UAT/Prod.
Our “git flow” looks like this loosely:
dev-work-item-123-branch —PR—> team-branch —PR—> main
We have Sonar setup to analyze all PRs and it would be nice if it would catch these issue in the first PR that goes from an individual developer into our Team branch instead of later after it has already been integrated into our Team environment and is about to go into main.
Let me ask: is your team branch truly short-lived? Do you kill it and start a new one on a regular basis? Because I’m suspecting something about what’s counted as “new” here, and an apples-to-apples comparison of both branches being long-lived would sure simplify things.
Hmm, you know, you are right. We don’t fully kill off the Team branch (regularly) we just continually add more and more commits to it, same as we do main, just main sits “above” it in the flow and gets deployed to Prod, where the Team branch would only ever get deployed to Team/Dev environment.
I’ll rename my Topic.
Another point that your “new” comment made me think of - the issue in C# code that Sonar identified was NOT “new” code. You can see the PR code viewer doesn’t highlight it in red (removed) or green (added). That “unused field” had existed in that same file in both branches for some time. We have other examples too of “missed issues” at the Team level, this was just an easy one to explain - or so I thought
My first suggestion is to analyze the team branch as a long-lived branch. Unfortunately, that means you’ll have to scrap it and start again since you can’t change a branch’s type.
Then we’ll have an apples-to-apples comparison to work with.