SA1516: Elements should be separated by blank line
Cause
Adjacent C# elements are not separated by a blank line.
📝 The behavior of this rule can change based on the configuration of the
blankLinesBetweenUsingGroupsproperty in stylecop.json. See Configuration.md for more information.
📝 Global using directives (C# 10) are treated as their own set of using groups. When
blankLinesBetweenUsingGroupsrequires separation, the rule enforces blank lines between the global using block and subsequent namespace-level usings or top-level statements in addition to the usual spacing within each set of using directives.
Rule description
To improve the readability of the code, StyleCop requires blank lines in certain situations, and prohibits blank lines in other situations. This results in a consistent visual pattern across the code, which can improve recognition and readability of unfamiliar code.
A violation of this rule occurs when two adjacent element are not separated by a blank line. For example:
public void Method1()
{
}
public bool Property
{
get { return true; }
}
In the example above, the method and property are not separated by a blank line, so a violation of this rule would occur.
public event EventHandler SomeEvent
{
add
{
// add event subscriber here
}
remove
{
// remove event subscriber here
}
}
In the example above, the add and remove of the event need to be separated by a blank line because the add is multiline.
When using C# 10 file-scoped namespaces, the namespace declaration should be followed by a blank line before any using, extern alias, or type declarations.
How to fix violations
To fix a violation of this rule, add a blank line between the adjacent elements.
How to suppress violations
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1516:ElementsMustBeSeparatedByBlankLine", Justification = "Reviewed.")]
#pragma warning disable SA1516 // ElementsMustBeSeparatedByBlankLine
#pragma warning restore SA1516 // ElementsMustBeSeparatedByBlankLine