I like StyleCop's static code analysis and rules enforcement. However, it is severely lacking in several key departments.
Is there such a commercial product out there?
alt text http://blogs.interakting.co.uk/images/blogs_interakting_co_uk/dominicz/WindowsLiveWriter/MicrosoftStyleCopSourcecodeanalysisforfo_D8EF/styleCopErrors_6.gif
StyleCop used to be a Visual Studio plugin and a NuGet package. You can still use this in Visual Studio 2019, but the current recommended way to use StyleCop is to use the Roslyn-based analyzers.
The stylecop feature doesn't work with Visual Studio 2022 . The Compatible versions are Visual Studio 2012, 2013, 2015, 2017, 2019 . Please try to always add a source to statements like this (even if it is obviously correct in this case 😉).
Open a project in your Visual Studio. Right-click on the project file in the explorer solution panel, and then click on StyleCop Settings... to open the configuration window as shown in the following screenshot: Once you have finished selecting the rules you need, you can launch your first analysis of code.
If you are on Windows, the Settings. StyleCop file can be opened from the Explorer and edited through a GUI. If that doesn't work, try dragging the Settings file onto an application called StyleCopSettingsEditor.exe which is installed in your StyleCop Program Files folder.
Adding rules is, or is going to be, officially supported:
As promised, we will also be releasing SDK documentation for StyleCop explaining how to author custom rules and how to integrate the tool into custom build environments. The SDK documentation is currently under final review and we hope to release it very soon. -- JasonAll
In terms of our "in-house" style, I got pretty close by disabling a handful of StyleCop rules:
You can do this globally by modifying the Settings.StyleCop file in the installation directory, though I've taken the approach of putting one at the root of our source tree in each project.
The end effect is much what we want. There are a handful of "in-house" choices that would be nice to flag, but even without them StyleCop is delivering a lot of value for us.
StyleCop for ReSharper could help (you'd need to purchase ReSharper, but the plug-in is free):
StyleCop for ReSharper is now feature complete in that is has reached feature parity with StyleCop 4.3.
There are 148 StyleCop rules.
- 38 of these must be fixed manually (normally because you have to type descriptive text or rename variables).
- Of the remaining 110 rules 58 are fixed by R# Code Cleanup (silent mode).
- Of the 52 now remaining we have Code Cleanup rules that fix all of them automatically.
We also provide 106 Quick Fixes that provide in place context menu fixes for violations for the 110 rules that can be fixed automatically
We also ship a "StyleCop friendly ReSharper Code Style Sharing Settings file" which configures ReSharper to automatically format code in a StyleCop friendly manner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With