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 follows 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.
The fix never joins clauses onto one line: a mixed query always ends up with each clause on its own line, like BRO1108 for argument lists. BRO1128 is reported together with BRO1129 and BRO1130 in the same query, so one run fixes the whole query.
Not reported¶
- Queries whose clauses share a line across a comment (the fix couldn't make the layout consistent without moving it).