JetBrains Rider 2024.3 Help

Use StyleCop styles

In C#, JetBrains Rider can apply its code formatting and code syntax styles according to StyleCop rules. Below are several ways in which JetBrains Rider supports StyleCop.

To apply StyleCop rules, JetBrains Rider relies on its own features and settings, which do not always map directly onto StyleCop rules:

  • JetBrains Rider supports most of StyleCop naming, maintainability, readability, and layout rules.

  • Some StyleCop rules may not be supported in a specific version of JetBrains Rider. However we will try to support more rules in coming versions.

Inspections for StyleCop rules

JetBrains Rider provides a number of code inspections for formatting and syntax style rules. These inspections do not find all code style problems that StyleCop finds, but they also can find some other problems that StyleCop cannot find, such as indenting problems.

As of version 2018.1, formatter inspections are disabled by default, but they will be automatically activated as soon as you enable StyleCop settings, and will offer you quick-fixes for code issues to automatically correct detected problems.

Apply settings from StyleCop files

By default, JetBrains Rider does not read settings from StyleCop files (RuleSet and Settings.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. Make sure that Read settings from editorconfig, project settings and rule sets on the Editor | Inspection Setting page of JetBrains Rider settings is selected.

When StyleCop integration is enabled, settings from StyleCop configuration files (RuleSet and Settings.StyleCop) will override JetBrains Rider code formatting and code syntax styles, and enable corresponding code inspections.

If you have the StyleCop.Analyzers NuGet package installed in your project, JetBrains Rider will also read and apply the default values of the StyleCop Analyzers styles. These values will take precedence over the corresponding styles in JetBrains Rider settings, but they will be overridden by the values from the configuration files, if any.

If you use EditorConfig and StyleCop configuration files simultaneously, the StyleCop settings will always take precedence over both EditorConfig properties and JetBrains Rider settings.

Use StyleCop.Analyzers

Yet another way to apply StyleCop rules in your code is by using StyleCop Analyzers for the .NET Compiler Platform instead of StyleCop. To harness these analyzers, enable the .NET compiler platform analyzers in JetBrains Rider and then install the corresponding analyzer package.

Last modified: 18 September 2024