Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StyleCop Rule for Multiline Curly Brackets

SA1503 in StyleCop is an all or nothing deal when it comes to curly brackets. I want to be able to allow the following code:

if (x == 3) return true;

But disallow the following:

if (x == 3)
    return true;

if (x == 3)
    foreach (var w in widgets)
        x++;

So basically, same line without curly brackets good, multi-line without curly brackets bad.

I'm new to writing custom StyleCop rules and I'm struggling with where to begin. Any help would be greatly appreciated.

like image 436
Hungry Beast Avatar asked Nov 13 '22 16:11

Hungry Beast


1 Answers

I've wanted the same styles, and had to turn off the rules StatementMustNotBeOnSingleLine and CurlyBracketsMustNotBeOmitted to support it. This now supports the single line scenario, but unfortunately doesn't check the multi line scenario.

However I don't think this should be a new rule, but rather a change to the current rules (maybe configurably controlled). I suggest raising an issue on the StyleCop site, and if you're game get the source and make the change. There is a developer guide in the documentation which will help get you started.

like image 59
Mightymuke Avatar answered Nov 15 '22 06:11

Mightymuke