ReSharper Line Breaks and Wrapping
Asked Answered
B

1

39

So, this:

cmd = new OdbcCommand( string.Format( @"
SELECT *
  FROM Bobby_Tables
 WHERE Name = {0}", "Little Bobby Drop Tables" ), odbcConnection );

gets formatted to:

cmd = 
      new OdbcCommand( 
            string.Format( 
                  @"
SELECT *
  FROM Bobby_Tables
 WHERE Name = {0}", 
                  "Little Bobby Drop Tables" ), odbcConnection );

I've looked at each of the options for line breaks and wrapping but I haven't been able to find the one to keep things on the same line as long as possible. I'm assuming that I missed the correct option. My Right margin (columns) option is set to 100, which is plenty big.

Question: Is there a way to make it look like the original, and still get smart formatting on other things that actually do need to be wrapped?

I can manually put the

cmd = new OdbcCommand( string.Format (
      @"

back on the first line and it'll leave the verbatim string on the next line happily. That's an alright compromise I guess.

Benighted answered 31/7, 2012 at 16:22 Comment(4)
Try setting the "Keep existing line breaks" property to true under Code Editing => C# => Formatting Style => Line Breaks and Wrapping. You can also shortten the "Right margin (columns)" property so that the right margin is smaller and thus "Chop if long" doesn't happen as often.Id
Can you elaborate on what you are trying to achieve? Do you want Resharper to bring the Select statement all back into a single line? If so, I don't think it will do that. Resharper is usually trying to reformat code and break it up for readability.Retinoscopy
Love the xkcd reference. "maybe you will learn to sanitize your sql".Hairtail
Possible duplicate of How to stop Resharper from line breaking after return keyword for long lines?Rigorous
A
90

I guess that your problem is that the first line got broken in three. This is because of bug http://youtrack.jetbrains.com/issue/RSRP-288271 that was fixed in ReSharper 7.0. You should consider upgrading or turning off option ReSharper | Options -> Code Editing | C# | Formatting style | Line breaks and wrapping -> LineWrapping | Wrap long lines.

Affirmative answered 31/7, 2012 at 17:52 Comment(6)
Hey @Dmitry Osinovskiy, maybe you have a clue about a problem I'm having with ReSharper 6.1? If you could, please take a look in my question: #11623081Wilmawilmar
We're still on 6.1. I'm using a Right Margin of 100, so it should be plenty. It seems like, "Oh, this new OdbcCommand() is too long, put it on a new line. Oh, this string.Format() is too long, put it on a new line. Oh, this verbatim string is too long, put it on a new line." At least, that's how I imagine the algorithm working.Benighted
@devundef Unfortunately I don't have a clue. But you can always try to ask him twitter.com/fergard/status/228271877393633280Affirmative
As a new user to ReSharper, I'm surprised at how many defaults it has that I disagree with! This was one. Thanks for pointing out how to turn it off.Miffy
@Miffy Select solution in Solution Explorer, Extensions > ReSharper > Edit > Detect formatting settings to find all of them at onceAffirmative
The option to turn off the wrapping of long lines is now located at Extensions > ReSharper> Options > Code Editing > C# > Formatting Style > Line Breaks and Editing > General > Wrap long lines. Simply un-check the check-box, if it is selected.Neglectful

© 2022 - 2024 — McMap. All rights reserved.