Code Smell outside of new code

Hi everyone,

we encouter a scenario we can’t wrap our heads around.
We have the following implementation

internal class MockCamera
{
private Bitmap bitmap1;
private Bitmap bitmap2;

public void CaptureImage()
        {
            bitmap1 = new Bitmap(@PATH_TO_OUR_FILE_1);
            bitmap2 = new Bitmap(@PATH_TO_OUR_FILE_2);
        }
}

When I delete the line “bitmap1 = new Bitmap(@PATH_TO_OUR_FILE_1);”, SonarLint marks this as issue " Unused private types or members should be removed (csharpsquid:S1144)" locally in my Visual Studio. So far so good

But if I then create a pull request with this change, SonarQube doesn’t seem to add this to the code smells of NEW CODE. As I understand the NEW CODE section only shows the issues within the changed code.
But if the change (like in our example) generates an issue considering a line outside of the changed lines, when does SonarQube take up this issue ?

SonarQube Version: 8.9.1.44547

Cheers

Claudius

Hi Claudius,

PR analysis raises issues on new code. And what you’ve described is an unfortunate deficit of that strategy. Sometimes changes to one line can cause issues to be raised on un-touched, and thus not-new, lines. And PR analysis isn’t going to raise an issue on the old line even if that issue is a direct result of changes in the PR. We’re aware of the issue. Hopefully it will be addressed soon.

 
:woman_shrugging:
Ann

Hi Ann,

thank you for your response.
I was just wondering about this issue since I understood the “new-code-overall-code-strategy” as you described. So, luckily I wasn’t that wrong :slight_smile:
I will keep this in mind for future PR analysis. Since we base our quality gates on new code as well as overall code it is not that big of a deal for our Release Management. As I said I was just curious.
Hopefully this issue will be addressed in the future.

I will mark your answer as solution since you pretty much answered my question :slight_smile:

Thank you very much

Claudius

1 Like

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