' "switch/Select" statements should contain a "default/Case Else" clauses' pattern clash

Hello,

I am using SonarC# 8.40 through Codacy to analyse C# code

I am having an issue with the ’ “switch/Select” statements should contain a “default/Case Else” clauses’ issue pattern in the way that is clashes with another pattern, ‘Empty “default” clauses should be removed’. For example, if I had some code like this:

switch(number)
{
    case(3)
    {
         DoSomething();
    }

    case(5)
    {
         DoSomething();
    }

    case(8)
    {
         DoSomething();
    }
}

It would want me to add a default clause because ’ “switch/Select” statements should contain a “default/Case Else” clauses’. However if I add a default clause with a break inside (Because I do not want it to do anything in this case) such as the example below:

default:
    break;

It will raise the issue that ‘Empty “default” clauses should be removed’. Of course removing results in the first issue

That is the problem I am having, any fixes would be much appreciated :+1:

Thanks for the help

Hey there.

This version is over a year old – I suggest seeing if you can reproduce on the latest version of SonarQube, or on https://sonarcloud.io!