Skip to content

BRO1128: Query clauses should be on separate lines or all on one line

A query's clauses are all on one line or each on its own line. Replaces StyleCop SA1103.

Example

Before

using System.Linq;

public class Orders
{
    public object Large(int[] amounts)
    {
        var large = from a in amounts where a > 100 orderby a
            select a;
        return large;
    }
}

After

using System.Linq;

public class Orders
{
    public object Large(int[] amounts)
    {
        var large = from a in amounts
            where a > 100
            orderby a
            select a;
        return large;
    }
}

Why

A query split at some clauses but not others hides its structure; one clause per line reads top to bottom.

How the fix works

Every clause that shares a line with the clause before it moves to its own line. The indentation is StyleCop's: the line the from is on, one level deeper when the from isn't the first thing on that line (as in var q = from ...), using indent_style/indent_size from .editorconfig. The diagnostic is on the from keyword.

Not reported

  • Queries whose clauses share a line across a comment (the fix couldn't make the layout consistent without moving it).

Compared with StyleCop

StyleCop's fix offers two actions, all on one line or each on its own line, and under dotnet format applies whichever comes first, which changes from run to run (seen while comparing the two), and the one-line action makes long lines, pulls the query up behind => and writes ( from. StyleBro always puts each clause on its own line, like BRO1108 for argument lists. StyleCop doesn't report SA1103 when it reports SA1104 or SA1105 in the same query, which leaves the rest of a mixed query to a second run; StyleBro reports BRO1129/BRO1130 and BRO1128 together, so one run fixes the query.