Aaron Jensen

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Getting ReSharper and VS to play nice with MSpec

Does ReSharper want to make your specs look like this?

Superfluous privates, indentation and warnings

But you want your specs to look like this?

clean text with less noise

Just follow these easy steps:

  1. Go to Resharper>Options

  2. Go to Languages>C#>Formatting Style>Other

  3. Uncheck Modifiers>Use explicit private modifier

  4. Uncheck Other>Indent anonymous method body and hit OK

  5. Go to your project properties>Build and suppress warning 169

  6. Enjoy!


Posted Sun, Oct 19 2008 3:14 PM by aaronjensen
Filed under: , ,

[Advertisement]

Comments

DotNetKicks.com wrote mSpec and ReSharper
on Sun, Oct 19 2008 7:40 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Nicholas Blumhardt wrote re: Getting ReSharper and VS to play nice with MSpec
on Sun, Oct 19 2008 10:39 PM

Mmm.... Aaron, when I said that was the most twisted C# I'd ever seen, I understated just how cool it is :) Still in awe of this framework!

Dew Drop – October 20, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop – October 20, 2008 | Alvin Ashcraft's Morning Dew
on Mon, Oct 20 2008 8:41 AM

Pingback from  Dew Drop – October 20, 2008 | Alvin Ashcraft's Morning Dew

Rohit wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 9:29 AM

I don't understand why seeing private declaration is deemed noisy or why it's a problem to see the indentation tab stopped at the same column as of the previous line. Writing private would definitely make your intentions clear.

Adam Tybor wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 11:12 AM

Just what I was looking for... Thanks for posting it.  I would love one more showing some of the DRY stuff we talked about.

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 11:17 AM

Rohit,

The language makes your intentions clear. Private is an unnecessary keyword. Any unnecessary ceremony is just that. As such, it should be treated lightly and removed because it does not add value.

Furthermore, these tips are for the MSpec framework. A framework which has no understanding of "private" so it's even more superfluous. The entire point of the framework is to remove language noise and focus on the essence of the specs.

With regards to the indentation, do you indent your method bodies to begin under the ()'s? In MSpec, these initializers are essentially methods, just reshaped. Removing the excess indentation treats them as such.

Arjan`s World » LINKBLOG for October 20, 2008 wrote Arjan`s World » LINKBLOG for October 20, 2008
on Mon, Oct 20 2008 3:24 PM

Pingback from  Arjan`s World    » LINKBLOG for October 20, 2008

Sergey Shishkin wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 5:21 PM

Nice tip if you only code specs. I don't want the rest of my code look like garbage.

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 7:08 PM

Sergey,

Wow. Garbage? Not having superfluous privates and indenting sanely is garbage? If you say so :)

Rafferty Uy wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 9:31 PM

What's suppress warning 169 for? What is 169?

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Oct 20 2008 10:58 PM

169 is unused private. It's what makes the instance fields (It, Because, Establish, etc) gray, and it can give you a warning when building.

Sergey Shishkin wrote re: Getting ReSharper and VS to play nice with MSpec
on Thu, Oct 23 2008 3:57 AM

Aaron,

underscores in method names is garbage. Explicit access modifiers is discipline. With redundant indentation you're right, I also customize them.

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Thu, Oct 23 2008 8:26 AM

Sergey,

You have obviously completely missed both the point of this post and mspec. That is fine as mspec is a difficult thing to wrap your head around. This post is for people that use mspec and I am assuming you do not.  

With regard to underscores, no setting I have suggested forces you to use underscores in all your code. This is an mspec requirement. It has been proven time and time again that boxcar naming is much more suitable for longer sentence fragments than pascal.

Calling explicit modifiers "discipline" is just silly, especially considering resharper is set up by default to force you to use them. Replace the word explicit with redundant, which is what thy really are, and maybe you will see my point of view.

Spend some time in a language like ruby or any other with a high signal to noise ratio and you will find that your biases and predispositions are really baseless.

Again if you do not even use or see the need for mspec you can write this post off completely.    

Jason Evans wrote re: Getting ReSharper and VS to play nice with MSpec
on Fri, Oct 24 2008 4:14 AM

Hi there.

Just looking at the screen shots of your source code, what font are you using in your VS IDE? It looks pretty cool.

cheers.

Jas.

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Fri, Oct 24 2008 10:03 AM

Jason,

That's Damien Guard's Envy Code R:

damieng.com/.../envy-code-r-preview-7-coding-font-released

Beto wrote re: Getting ReSharper and VS to play nice with MSpec
on Fri, Oct 31 2008 8:21 PM

What theme are you using?

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Tue, Nov 4 2008 9:58 AM
KevDog wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Jun 1 2009 10:08 PM

I'd be interested in a "proof" that boxcar naming is more suitable than pascal case. Personally, I find it hard to read and harder to type. It slows me down and is very awkward.

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Tue, Jun 2 2009 2:39 PM

KevDog,

Typing it is easy if you use an AHK script or something similar to replace spaces with underscores like this: blog.jpboodhoo.com/BDDAutoHotKeyScriptUpdateTake2.aspx

As for reading it, only you know what's easier to read for yourself. That said, I've seen a post or two on the subject in which the blogger quizzed his wife on which was easier for a long sentence and boxcar always won.

If you can learn to phase out the underscores while reading it's significantly easier to read. It also allows you to case things properly. I've yet to meet someone who has claimed they prefer PascalCasingThingAfterTheyHave given_boxcar_a_shot_for_a_while

Peter Seale wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Jun 8 2009 11:06 AM

Thanks for pointing me here; these tips are what I needed (especially fixing the crazy indentation!)

ScottBellware wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Nov 9 2009 8:05 AM

Hi Aaron. Everyone in Norway loves you!

aaronjensen wrote re: Getting ReSharper and VS to play nice with MSpec
on Mon, Nov 9 2009 11:41 AM

And I love them!

Eric Lee wrote re: Getting ReSharper and VS to play nice with MSpec
on Tue, Jan 26 2010 1:40 AM

There's another setting you'll want to turn off, at least in RS 5.0.  Under Languages | C# | Formatting Style | Other | Align Multiline Constructs, turn off Expression.  That will prevent RS from indenting lambda expressions that you put on a second line after the field declaraction like the "It" lines in Aaron's examples above.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?