Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic StyleCop

Tags:

.net

stylecop

StyleCop is an awesome little add-on for visual studio. But it doesn't show you live hints or provide any automated fixes.

Along comes reSharper and StyleCop for reSharper, this is the ideal solution, however it costs too much.

Is there an open source way to achieve the live code hints and automated fixes for style cop?

Or is reSharper the only way to do this at present?

Thanks in advance...

like image 540
JL. Avatar asked Feb 08 '10 12:02

JL.


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 turn off StyleCop?

right-click on a project in Project Explorer. select "StyleCop Settings" on the "Rules" tab of the dialog that opens, uncheck the "C#" root of the Enabled rules tree.

What is FxCop and StyleCop?

StyleCop is a source code analysis tool that provides developers with an effective way to follow C# coding standards. FxCop runs against the compiled binaries as a way to understand and enforce the.NET Framework Guidelines for managed code assemblies.

How do you run StyleCop in rider?

Apply settings from StyleCop files StyleCop). To start taking these settings into account, select the Enable StyleCop support checkbox on the Editor | Code Style page of JetBrains Rider settings Ctrl+Alt+S and choose which StyleCop file format should be used.


1 Answers

Well, there is one way to achieve a small amount of automated StyleCop fixes for free without installing any new software. That's right, read my lips, no new software!

Visual Studio has lots of build-in features that will fix a lot of StyleCop errors. All you have to do is set it up and use them. Listen up, and I'll tell you more!

Some of my personal favourites are:
- the right-click Refactor window (rename anything, anytime, everywhere!)
- Edit/Advanced/Format Document combined with modifications to the Visual Studio settings in Tools/Options/Environment and saving those settings out in a .vssettings file and storing those settings with the solution. Make Visual Studio enforce your style! Hoo-ah!
- Custom Snippets! Make that full page of boilerplate appear with only three keystrokes! I know you've had dreams about this kind of productivity!

But wait, there's more!

As for "live hints", if you right-click on the StyleCop violation in the error list you can get a link to the appropriate section of documentation to help you out! Right there, where you want it, when you want it!

By no means as fully featured as ReSharper, but a bargain at the low-low price of nothing! You can't turn down this deal!

(offer not fully valid to those using MSBuild integration)

like image 178
Task Avatar answered Sep 20 '22 04:09

Task