Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.38 KB

SA1502.md

File metadata and controls

54 lines (40 loc) · 1.38 KB

SA1502

TypeName SA1502ElementMustNotBeOnSingleLine
CheckId SA1502
Category Layout Rules

Cause

A C# element containing opening and closing braces is written completely on a single line.

Rule description

A violation of this rule occurs when an element that is wrapped in opening and closing braces is written on a single line. For example:

public object Method() { return null; }

When StyleCop checks this code, a violation of this rule will occur because the entire method is written on one line. The method should be written across multiple lines, with the opening and closing braces each on their own line, as follows:

public object Method()
{
    return null; 
}

As an exception to this rule, accessors within properties, events, or indexers are allowed to be written all on a single line, as long as the accessor is short.

How to fix violations

To fix a violation of this rule, rewrite the element so that it expands across multiple lines.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1502:ElementMustNotBeOnSingleLine", Justification = "Reviewed.")]
#pragma warning disable SA1502 // ElementMustNotBeOnSingleLine
#pragma warning restore SA1502 // ElementMustNotBeOnSingleLine