question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SA1513 fires in switch statements

See original GitHub issue

SA1513 fires erroneously for switch statements with enforced braces. A block of code structured in the following manner

int i = 0;
switch (i)
{
    case 1:
    {
        // Thing
        break;
    }
    case 2:
    {
        // Other thing
        break;
    }
    default:
    {
        break;
    }
}

will raise two instances of the inspection at lines 8 and 13, respectively. I would assume that this is not intended behaviour, and that no instances should be raised. If this is intended, it would be a good candidate for addition into the json configuration, as it is a common pattern for switch statements and introducing blank lines between the cases would go against this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Ruhrpottpatriotcommented, Oct 17, 2017

I want to second this proposal. The rule also fires (I guess by design) when you put the break outside the block braces. At least in my eyes the following looks very weird:

case statement: 
{
    // Some code
}

break;
case anotherStatement:
    // More Code

From intuition I’d expect this form:

case statement: 
{
    // Some code
}
break;

case anotherStatement:
    // More Code
0reactions
maxkoshevoicommented, Apr 19, 2022

Is an external implementation that fixes this ready somewhere?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Trying to suppress StyleCop message SA1513: ...
I am trying to suppress the following StyleCop message for a specific property: SA1513: Statements or elements wrapped in curly brackets must ...
Read more >
if and switch statements - select a code path to execute
The if-else statement allows you to choose which of the two code paths to follow based on a Boolean expression. The switch statement...
Read more >
Untitled
Jamari traylor block, Wenatchee fire complex, Mahkota dimana pacarku, Thai wifi hotspot, ... Csir case 2013 expected exam date, Tablet advan vandroid t2ci, ......
Read more >
switch - JavaScript - MDN Web Docs - Mozilla
The switch statement evaluates an expression, matching the expression's value against a series of case clauses, and executes statements ...
Read more >
Strings in switch Statements
The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found