BRO1521: Place '=>' consistently when an expression body wraps¶
When the line breaks next to the => of an expression-bodied member (method, property, accessor, operator, local
function, ...) or a switch expression arm, the => goes at the end of the broken line (the default) or at the
beginning of the continuation line. Not a StyleCop rule.
Example¶
Before¶
public class Temperature
{
private readonly double celsius = 21.5;
public double Fahrenheit
=> (celsius * 9 / 5) + 32;
public string Describe()
=> celsius switch
{
< 0 => "freezing",
_ => "fine",
};
}
After¶
public class Temperature
{
private readonly double celsius = 21.5;
public double Fahrenheit =>
(celsius * 9 / 5) + 32;
public string Describe() =>
celsius switch
{
< 0 => "freezing",
_ => "fine",
};
}
Why¶
One place for the => in the whole codebase. The default puts it where lambdas have it: at the end of the line, so
every => follows one convention.
The reference repositories StyleBro is tested on (2026-10-04) are split for expression bodies: four put => at the
beginning of the line (OpenTelemetry 676 to 335, Jellyfin 398 to 14, FluentValidation 52 to 3, Serilog 2 to 0) and
three at the end (Polly 543 to 130, FFMpegCore 3 to 0, CsvHelper 2 to 0); Newtonsoft.Json has one of each (1,259 at
the beginning and 901 at the end in all). Lambdas are not split: 5,299 of 5,308 have => at the end of the line.
Switch arms broken at => are rare (8 at the beginning, 14 at the end) and follow the same setting.
How the fix works¶
Only the => moves: it goes to the other side of the line break with one space between it and the code on its line.
The line break and the continuation line's indentation stay as they are.
Configuration¶
[*.cs]
# end_of_line (default) or beginning_of_line.
stylebro_arrow_placement_when_wrapping = end_of_line
Not reported¶
- Lambdas (
x =>followed by the body on the next line): a block body's{goes on its own line after the=>, and lambdas keep=>at the end of the line almost everywhere (5,299 of 5,308 in the reference repositories, block bodies included); they're left alone. - An
=>right after awhereconstraint: BRO1111 places it on its own line with the body. - A query as the body (
=>+from x in ...): the query layout rules (BRO1127-BRO1130) indent its clauses by whetherfromstarts its line, so they would re-indent the query. - A comment or a directive next to the
=>, an=>alone on its line, and code with syntax errors.
Compared with StyleCop¶
StyleCop has no such rule. Roslynator's RCS0032 does the same, off by default and with its own option
(roslynator_arrow_token_new_line). stylebro-migrate turns this rule off, so migrating doesn't change a
StyleCop-clean repository.