Code style settings for expression bodied members

Rider formatting settings allow you specify body style for members with "single line" bodies, the `Editor/Code Style/C#/Syntax Style/Code Body` section. It works identical to setting IDE0022 set to "when_on_single_line" in your `.editorconfig` file. The problem is, it does not really work the way it's called. What is called "single line" is actually is a "single expression", so cleanup with option "when_on_single_line" results in this:

protected override IComponent BuildHeader(HeaderData data)
=> Label("Name")
.WithContentAlignment(HorizontalAlignment.Center, VerticalAlignment.Center)
.WithTrailingBorder(BorderType.Thin, Color.Black)
.WithBottomBorder(BorderType.Thin, Color.Black);

The code style is debatable thing, some might say that this is alright, but preferred way of a lot people I know and myself included is to use a braces when member body is not really single line

Because this, at least for me, formatting above is not an option, I have to either deal with fact that I can't have an expression bodied methods:

protected override IEnumerable<Lab> SelectHeaderData(HeaderData data)
return data.Labs;

Or manually convert methods like the one above to expression body after cleanup. Or, don't use the cleanup at all.

All the options are really not that great. I'd be really glad if there is already a option to configure code style that way, and I just had a hard time finding it. But if there is none, it would've been nice to have.

1 comment
Comment actions Permalink

Hello Ronimizy, thank you for your question. Unfortunately, when_on_single_line isn't supported now. There is a similar issue in our bug tracker - RSRP-474690. Please comment or vote for it to see status changes.

Please let me know if you have any questions. Have a nice day!


Please sign in to leave a comment.