Jan Schreuder on .Net

.Net code samples, experiences, observations

View my professional profile on LinkedIn

Recent Posts

Tags

News

  • Inappropriate comments will be deleted at my discretion.

    The information and code samples in this weblog is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the merchantability and/or fitness for a particular purpose.

Community

Email Notifications

Tool suppliers

Tools

General

Microsoft

Favorite blogs

Archives

StyleCop - QuickStart tips

After using StyleCop for some weeks, there are some things I think that might be useful to others when they want to start using the tool. So here are some tips.

Tip 1 - Also download the documentation

The documentation for StyleCop is available as a separate download. It explains why the rules are introduced and how you can fix violations. Without this documentation, you may think some of the rules are useless or annoying.

Tip 2 - Do not run the tool on an entire solution

At least, not untill you're satisfied that your code complies with the rules. You get so many warnings in a project or solution where the tool hasn't been used before, that you may think to stop using it immediately.

Tip 3 - Running the tool on one class file

Could have been in tip 2 as well, but I wanted to make a distinction here. When you right-click in the code, you will see the item Run StyleCop. Select this, and the tool will only check that particular class file. The number of warnings is signicantly less than when you run the tool on an entire project or solution, so the results are more obvious and motivate you more to keep using the tool.

Tip 4 - Disable rules you really disagree to

Rules you really don't want to check can be disabled using the StyleCopSettingsEditor. How this can be done is explained in this blog post. I disabled a number of them. I also included a number of overrides to the check for hungarian notation. For example, I have boolean variable names like isValid and isCompliant. StyleCop used to warn me about using hungarian notation in these cases, whereas I'm not. You can add the 'is' part in the Hungarian tab of the StyleCopSettingsEditor and it will no longer warn you about this.

Tip 5 - Re-Align the source before you start

Select all the code using Ctrl-A, then press Ctrl-K followed by F. Visual Studio will re-align much of the code. This automatically eliminates a number of errors found by StyleCop.

 

Leave a Comment

(required) 

(required) 

(optional)

(required)