We are running SonarQube Developer Edition Version 9.2.4 (build 50792)
The analysis is triggered via merge requests through our self hosted GitLab, which is currently at version Enterprise Edition 14.6.0-ee
Not sure exactly how much information is required, but the point is that the analysis that runs on merge requests is reporting code smells on lines that are not changed by the merge request. What I’ve done in this MR is to add a bunch of functions at one place in the file, which largely consist of code that was copied from one really big function further down in the file. And in that really big function, I replaced two chunks each by a single line, calling a respective one of new functions I added above. The view in gitlab shows this as one huge chunk of added code, then about 56 lines of unchanged lines, before two large chunks of code that were replaced each by a single line. These chunks now being separated by 3 lines of unchanged code.
However, it seems like the revision detection in SonarQube is detecting completely different lines as being changed by this commit. Notably, those chunks of 56 and 3 lines of unchanged lines that I mentioned, are being considered as part of one large chunk of lines that is part of the revision for the commit I’ve added. There are code smells in these lines, which is being reported.
It’s almost as if SonarQube is running its own separate git diff for some reason, which detects different parts of the code as unchanged. It seems like spiritually the problem is that it spiritually sees that one chunk of code was moved above another chunk, but when evaluating that together with the other changes, it considers the wrong chunk to be moved downwards, instead of correctly considering the correct opposite chunk from being moved upwards.
I think I would much rather have SonarQube report code smells, from the code that is effectively unchanged and moved into another new function, as new code smells. That seems more cohesive than getting reports from actual unchanged code that just happens to have moved relative to the code that I moved into a different function.