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

Migrate to StyleCop Source Code Analyzer #817

Open
dotnetjunkie opened this issue May 21, 2020 · 2 comments
Open

Migrate to StyleCop Source Code Analyzer #817

dotnetjunkie opened this issue May 21, 2020 · 2 comments

Comments

@dotnetjunkie
Copy link
Collaborator

The Simple Injector code base is currently verified using the deprecated StyleCop VS extension. This extension hasn't been maintained for several years and shows parsing errors on lines that use newer (> 6.0) C# features.

Instead, the code base can make use of the new Source Code Analyzer for StyleCop. This has the following advantages:

  • It actually works. No more parsing errors.
  • The analyzer is actively maintained.
  • No extension needs to be installed. Works automatically for every developer working on the code base.
  • The analyzer runs on every build. Impossible to forget.

The repository currently makes use of Settings.StyleCop (XML) files that configure which rules should be applied. The new Analyzer, however, doesn't read those XML files any longer and the used settings have to be migrated to rule set files, the new stylecop.json format, and sometimes .editorconfig.

Unfortunately, migrating from Settings.StyleCop to stylecop.json can be quite time intensive. I haven't found clear documentation on how to convert the old XML to the new JSON and which settings to place where exactly. Should we start off with a rule set and configure exceptions? Or should we skip the rule set entirely and use stylecop.json with a little bit of .editorconfig, or should we use .editorconfig, with a little bit of stylecop.json?

@leoniDEV
Copy link

leoniDEV commented May 21, 2020

If I can make a suggestion (even if I'm not contributor to this project, but I'm a really satisfied user, I also bought your awesome book about dependency injection) is to use .editorconfig file only (or at least migrate slowly from ruleset to .editorconfig, if you need to support VS versions older than 16.3), mostly for two reason:

  1. It is the intended, official and supported way to configure analyzers;
  2. the integration with Visual Studio enable you to configure severity from lightbulb or from error list;
    Using the lightbulb/error list to configure severity is pretty straightforward, also edit the .editorconfig file by hand is pretty easy, given that the convention for the rules is really simple and predicteble.

I migrated all my analyzer configs to .editorconfig mostly through the lightbulb/error list, and some times also adding the rules by hand editing the file directly, using the Visual Studio UI also add a useful comment that describe the rules.

Anyway my experience about migrating ruleset to .editorconfig is based solely on my projects which are small and relativly simple so I don't know if this workflow fits also for a project like this.

Finally I also discovered this issue but I don't know how and if it works, I never used.

@dotnetjunkie
Copy link
Collaborator Author

Hi @leoniDEV, thank you for your valuable feedback and useful links. .editorconfig seems clearly the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants