Skip to content

BRO1515: Braces should not be omitted from multi-line child statement

A child statement that spans several lines is a block. Replaces StyleCop SA1519.

Example

Before

public class Mailer
{
    public void Send(bool urgent, string to)
    {
        if (urgent)
            Deliver(to,
                priority: 1);
    }

    private static void Deliver(string to, int priority)
    {
    }
}

After

public class Mailer
{
    public void Send(bool urgent, string to)
    {
        if (urgent)
        {
            Deliver(to,
                priority: 1);
        }
    }

    private static void Deliver(string to, int priority)
    {
    }
}

Why

Without braces, a statement continued over several lines is easy to misread as several statements, only the first of which belongs to the condition.

How the fix works

Like BRO1514; the statement's continuation lines move with it, so their relative indentation stays.

Not reported

The same cases as BRO1514. With stylebro_layout_by = csharpier, a statement longer than the print width counts as multi-line because CSharpier would split it, except a return, yield return or throw of one string literal or interpolated string: CSharpier can't break it, so it stays on one line (and csharp_prefer_braces = when_multiline leaves it without braces).