Skip to content

no-regions

C#styleno fixdefault: offcsharp/stylecop

Reports every #region outside a block (a region inside a block is no-region-in-body’s), also in disabled #if branches. No fix, because removing a pair is a judgment call.

A region hides code behind a label, so a reader of a large class sees only the labels and not the size of what is behind them. Regions make a file longer without making it clearer, and are often a sign that the class should be split.

To fix, remove the region, or move its members to a class of their own.

Reported
class A {
# region R
int a;
# endregion
# if X
...
csharp:
lint:
rules:
no-regions: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line no-regions in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1124 full