Prevent Resharper From Adding Regions
A couple of days ago I was annoyed that Resharper was insisting on turning my abstract base NUnit test class with nothing in it but a shared [SetUp] method into a one line class with a collapsed Setup / Teardown region in it. While I didn’t always feel this way, my experience has taught me that regions are a smell in your code. They are a way to hide things you don’t want to deal with or look at. It’s kind of like putting makeup over a melanoma instead of having a doctor remove it. Here’s a pretty good analysis of why regions are a code smell if you’re interested.
So anyway, I’m using Resharper and am in general a huge fan, and I know I can configure this thing every which way, but I look through the options and nothing jumps out at me about how to adjust Region settings for NUnit tests. I manually removed the region and checked in my code and, rather than spending more time and effort researching a solution, griped about it on twitter today. Not long after, Todd Ropog let me know about this:
Prevent Resharper from adding Regions to Interfaces
Chris outlines the steps nicely:
This is why I never found what I was looking for – if you don’t uncheck the “Use Default Patterns” checkbox, you never even see the XML used. Once you see this:
you’re pretty much there. All you need to do is look for things that say:
<Group>
<Name Region="Some Region Name"/>
</Group>
So, to sum up:
- Regions can indicate a code smell and should be used sparingly.
- Resharper is a fabulous tool…
- …but it’s so darned flexible that finding how to do some things can be hard.
- Twitter can be a great way to get other people to tell you how to do things you don’t know how to do. :)
- Hopefully this helps a few people Googling/Binging or having their friends Tweet how to remove regions from Resharper code cleanup in the future.