Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Easiest way to configure Microsoft.CodeAnalysis.FxCopAnalyzers to apply classical rulesets #943

Closed
Dresel opened this issue Apr 23, 2016 · 14 comments
Assignees
Labels
Area-Infrastructure Bug The product is not behaving according to its current intended design
Milestone

Comments

@Dresel
Copy link

Dresel commented Apr 23, 2016

For the classical static code analysis you could use predefined Microsoft rule sets like Managed Recommended Rules.

Is there an easy way to configure FxCopAnalyzers to only apply rules that are within a certain rule set? The workflow we are currently using is the following:

  • Disable all FxCopAnalyzers rules (there might be rules enabled by default which are not in the desired rule set)
  • Go through each rule, look if it exists in the desired rule set (for example in the Managed Recommended Rules ruleset) and enable it again if it does

This is somehow tedious, so I wonder if there is a better way to do this?

@mavasani mavasani added Area-Infrastructure Bug The product is not behaving according to its current intended design Urgency-Soon labels May 9, 2016
@mavasani mavasani added this to the 1.2 milestone May 9, 2016
@mavasani mavasani self-assigned this May 9, 2016
@mavasani
Copy link
Contributor

mavasani commented May 9, 2016

This is one of the primary tasks that we need to do prior to releasing 1.2.0 bits of this package. Currently, there is no non-trivial way to do this.

@mavasani
Copy link
Contributor

mavasani commented May 9, 2016

FYI @srivatsn

@jinujoseph jinujoseph modified the milestone: 1.2 Apr 17, 2017
@mavasani mavasani added this to the Unknown milestone Apr 17, 2017
@axelheer
Copy link

Do we have rulset support in version 2.0?

@mavasani
Copy link
Contributor

@jinujoseph There have been multiple requests for this now. I will spend some time on this tomorrow to see if I can come up with a quick solution so our cibuild also generates:

  1. A ruleset which disables all rules from the analyzer package
  2. Classical FxCop rulesets which include the above ruleset, and then turn on the relevant rules.
  3. Package the above rulesets in our analyzer NuGet packages.

I think we need this for a good compat story anyways.

@alextolp
Copy link

alextolp commented May 3, 2018

+1

1 similar comment
@curia-damiano
Copy link

+1

mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Jun 11, 2018
We now generate the following set of ruleset files for each analyzer package:
1. AllRulesEnabled.ruleset
2. AllRulesDefault.ruleset
3. AllRulesDisabled.ruleset

For every unique rule category within the pacakge, say security, performance, design, etc., we generate 2 ruleset files per category. For example, for Security, we generate:
1. SecurityRulesEnabled.ruleset (all security rules enabled, including the ones with IsEnabledByDefault = false. All rules from other categories are disabled)
2. SecurityRulesDefault.ruleset (all security rules have default severity and IsEnabledByDefault is honored. All rules from other categories are disabled)

For the core FxCopAnalyzers package, we also package all the legacy FxCop rulesets, which have been edited to include AllRulesDisabled.ruleset upfront to match legacy FxCop configuration.

Fixes dotnet#943
@mavasani
Copy link
Contributor

I have a PR out to package classical and auxiliary rulesets along with each analyzer package: #1718

Kindly, take a look at the description and screenshots in the PR to confirm this satisfies everyone's ask.

@Dresel @axelheer @alextolp @curia-damiano

mavasani added a commit that referenced this issue Jun 12, 2018
We now generate the following set of ruleset files for each analyzer package:
1. AllRulesEnabled.ruleset
2. AllRulesDefault.ruleset
3. AllRulesDisabled.ruleset

For every unique rule category within the pacakge, say security, performance, design, etc., we generate 2 ruleset files per category. For example, for Security, we generate:
1. SecurityRulesEnabled.ruleset (all security rules enabled, including the ones with IsEnabledByDefault = false. All rules from other categories are disabled)
2. SecurityRulesDefault.ruleset (all security rules have default severity and IsEnabledByDefault is honored. All rules from other categories are disabled)

For the core FxCopAnalyzers package, we also package all the legacy FxCop rulesets, which have been edited to include AllRulesDisabled.ruleset upfront to match legacy FxCop configuration.

Fixes #943
@mavasani
Copy link
Contributor

@mavasani
Copy link
Contributor

@mavasani
Copy link
Contributor

mavasani commented Jun 12, 2018

Also tagging @gewarren. We probably want to document #1718 (comment) and #1718 (comment) on docs.microsoft.com, so customers who wants to migrate from legacy FxCop to FxCop analyzers without altering their existing rule configuration can use the new rulesets that we package with the analyzer packages.

@gewarren
Copy link
Contributor

@mavasani will do, thanks.

@Dresel
Copy link
Author

Dresel commented Jun 18, 2018

Looks good. Thanks 👍

@zivillian
Copy link

Can you please describe how those rulesets can be used in a project? I tried adding <CodeAnalysisRuleSet>..\rulesets\legacy\MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> with different paths and ended with just copying the ruleset folder to my project.

@mavasani
Copy link
Contributor

@zivillian Relative paths will not work as the ruleset location is relative to the NuGet package root. You either need to explicitly define/reference NuGet package root and package version in your absolute path OR copy over the required ruleset files to your project directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure Bug The product is not behaving according to its current intended design
Projects
None yet
Development

No branches or pull requests

8 participants