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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With