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.

Compared with StyleCop

Same positions and output, apart from the skipped cases.