Hungry Beast
Hungry Beast

Reputation: 3725

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.

Upvotes: 5

Views: 2052

Answers (1)

Mightymuke
Mightymuke

Reputation: 5144

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.

Upvotes: 1

Related Questions