Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to StyleCop for Visual Studio? [closed]

I like StyleCop's static code analysis and rules enforcement. However, it is severely lacking in several key departments.

  • Adding new rules isn't officially supported and from what I hear pretty difficult.
  • Automatic "fixing" of trivial rules violations would be nice! Perhaps not with variable naming but with method ordering (static, etc) this would be a huge time saver.
  • Microsofts "one-size-fits-all" approach to StyleCop is kind of restrictive. I would like to have a custom set of rules for our in-house standards.

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

like image 693
mmcdole Avatar asked Nov 13 '08 03:11

mmcdole


People also ask

Is StyleCop still used?

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.

How do I enable StyleCop in VS 2022?

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 😉).

How do I add StyleCop to Visual Studio?

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.

How do I open StyleCop settings editor?

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.


2 Answers

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:

  • File Headers (SA1633-SA-1640)
  • Code ordering (SA1200-SA1202)
  • Requiring "this" (SA1101)

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.

like image 118
Bevan Avatar answered Nov 15 '22 16:11

Bevan


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.

like image 30
HowardvanRooijen Avatar answered Nov 15 '22 16:11

HowardvanRooijen