Is there a StyleCop/FxCop autofixing tool? [closed

2020-02-18 15:18发布

Is there a tool that can automatically fix StyleCop and FxCop rules, rather than manually fixing thousands of warning and errors?

There must be one, it is such a good business opportunity!

9条回答
走好不送
2楼-- · 2020-02-18 15:46

StyleFix will fix many of the violations found by StyleCop.
GhostDoc makes it easy to add comments to your methods.

Lateley I've been using Telerik JustCode. It really helps PREVENT the style issues.

查看更多
欢心
3楼-- · 2020-02-18 15:47

FxCop doesn't come with its own fixing features just yet. Project Roslyn (targeted to be released somewhere after VS11) will provide a new engine for static analysis rules and comes with fixing built in as a feature.

There are a number of tools that provide their own fixing rules. A few have been mentioned before:

These sometimes flag more or other things than FxCop or StyleCop would. And herein lies a danger of conflicting rules. Which is already occurring here and there if you're one tool such as FxCop.

And there are a few open source projects that attempt to provide fixes for the most common FxCop and StyleCop warnings. I haven't tried those for StyleCop, but most of the FxCop auto fixing tools don't really work well, as there are but few FxCop rules that are truly easy to fix.

None of these tools will be able to help you fix custom rules (or rules you've downloaded from other sources, such as MSOCAF or open source projects (FxCopContrib for example) or other Microsoft projects (Such as the rules included in the Open Source Web Service Software Factory CTP).

And, especially with FxCop rules I see that while the thing being flagged, which seems very simple to resolve, actually points to a much larger issue.

  • Take for example the performance rule requesting you to make all your methods static. This is actually pointing out to you that you have classes with low cohesion. Just marking everything static might make your code a tiny bit faster, but won't improve your design and will most certainly make testing and maintaining your code harder in the long run.
  • Or the rule that mentions you should provide an IFormatProvider to any method that has an overload which supports it. I see too many developers who just put CurrentCulture in there and are done with it. Still getting import/export errors when they transfer files between two differently configured systems. As globalization, localization and internationalization are hard subjects to tackle.

This applies a lot less to StyleCop, as the coding style is often not related to the actual underlying implementation or design. And it looks like StylecopFixer is a great add-on if you're not using the Resharper integration which now ships with StyleCop by default.

查看更多
唯我独甜
4楼-- · 2020-02-18 15:49

No, frustratingly. That's why Style Cop is counter-productive. Consistent formatting looks nice, but there's little productivity benefit to it (what really makes code hard to read is length and indirection). Perfect spacing is not worth spending hours adjusting lines by hand.

If there were an automated tool to achieve consistent formatting, I might hook it up post-check-in. But Style Cop is made by sadists who force the user to do the tedious formatting by hand. Presumably their conversation went like this:

Bob: Using pattern matching, the software identifies ugly code
Charlie: —and fixes it!
Bob: No. It prints a message about each transgression.
Charlie: And then the user right-clicks to fix them all?
Bob: No. The message scolds them 'invalid spacing around the comma'.
Charlie: And then explains how the user can fix it?
Bob: No, that information is in a separate document.
Charlie: On Google?
Bob: No.

I hate Style Cop. It's below a minimum viable product.

查看更多
登录 后发表回答