Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Prevent ReSharper from Wrapping One-Line Statements?

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.

like image 211
Ryan D'Baisse Avatar asked Feb 16 '14 13:02

Ryan D'Baisse


1 Answers

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:

enter image description here

Check the ones that start with Keep existing arrangement [...] if you want to instruct ReSharper to leave, say, single-line ifs 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:

  1. Open the menu Resharper -> Options
  2. Go to Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping
  3. 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

like image 190
faceman Avatar answered Oct 13 '22 01:10

faceman