Using JetBrains ReSharper with a StyleCop plugin

In September I wrote a short article about writing a clean code. I told you that it is a good habit to implement programs with a one and good style. Today I am going to wrtie something about a special tools which are very useful during programming.

First of all, you need to have a JetBrains ReSharper installed at your local machine. Then you have to download a StyleCop, which is a plugin designed for ReSharper (

ReSharper allows you to clean your code automatically. When something is wrong with code it highlights it. When you use it for a first time you won’t be able to accustom with it. But after few weeks it will be your best friend during programming. Why should we use it and why is it so popular? It is caused by companies, which are developing large projects. In each project, there are 4-5 developers working on a solution – just think about it – each of programmer has a different style, habits and so on. To avoid a dirty and hard code to maintain, someone came up with the idea of creating a special tool designed for such situations.

Below you can see how does it work in a short example:

Code without any help from ReSharper & StyleCop plugin:


You can see blue & green highlights. Green means that you should think about types of variables, problems with your code (but remember – not with a functionality!), while blue is used to tell you, that you should think about a fix-spacing, comments, etc.

Code after styling:



As you can see, all spacing problems were fixed, it added summaries and InvariantCulture to a conversion from int to string with a .ToString() method.

It was a simple example, but with this tool you can change for example 4 if conditions into one switch in a one second. You are also able to change a foreach expression into a special LINQ, also in one second. It will remember about checking null conditions. On the other hand it is not designed for begineers, because it is not a good way to write your code automatically when you are still learning basics.


4 thoughts on “Using JetBrains ReSharper with a StyleCop plugin

  1. I like the valuable information you supply for your articles.
    I will bookmark your blog and take a look at again
    right here regularly. I am moderately certain I’ll learn a lot of new stuff right here! Best of luck for the next!

  2. ReSharper and StyleCop are not necessary if you have 4 or 5 developers in a team. If some of them writes bad code rest of them force them to change it or explain them why he write it that way. The problem is if programmer who write some code don’t work in this project. If style of code is not consistent you should decode both syntax and logic to understand it. If you use tools like R# or SC your work is much easier (sometimes it takes a half of time and that counts).

    1. I have a lot of situations when the new developer comes to our project and then he spends much less time at code analysis, what brings the better effects, just because previous teammates used R# with a StyleCop. If you have 4-5 experienced developers in your team, I can agree that we can avoid using these plugins. But sometimes there are also unexperienced programmers – then you should tak this solution into a consideration. Again, what in case of any future maintenance? Trust me, this code looks better and the maintenance cost is much lower.

      However, there are also disadvantages of using R#, for example – slower machine.

      1. R# is great. I personally feel little uncomfortable if I write code without it.
        But I’ve worked in team where the only person who use R# was me (I bought personal licence). Despite of that fact we were able to keep quite high quality and consistency of code. Our team didn’t change often. It took couple of weeks (or months) before newbie start to code without code review and we had strong leaders.

Zostaw komentarz

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s