How to Prevent ReSharper from Wrapping One-Line Statements?

resharper, resharper-8.0

Solution

Update for newer versions of ReSharper

(my version is 2021.1)

Since a picture is worth than a thousand words, you probably want to configure it like so. In this way it takes care of constructs such as `using` too:

Check the ones that start with `Keep existing arrangement [...]` if you want to instruct ReSharper to leave, say, single-line `if`s alone if they are already written that way.

Took me longer to figure out than I wanted it to, hopefully it will help someone else.

You can change this in the R# Settings:

- Open the menu Resharper -> Options

- Go to Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping

- Change to option Break line in single embedded statement to Put on a single line or Do not change

Edit: As mentioned by @Alexander it would be more suitable to use the option Break Line in a block with a single statement which I think is available since R# 8

Problem

What is the best way to prevent ReSharper from wrapping certain lines of code. For example, an `if` statement with one condition and a simple body should not be wrapped. ReSharper currently forces this line... ``` if (item == null) { return null; } ``` ... to break like this: ``` if (item == null) { return null; } ``` I don't want to blindly disable this feature necessarily... just make it a bit more intelligent.

Original source