Code style settings from Roslyn conventions in EditorConfig

In our previous post, we looked at how we can specify ReSharper’s inspection severities inside our EditorConfig file. In this post, we will see how ReSharper and Rider integrate with Roslyn conventions.

In this series:

Integration of Roslyn conventions

When we are in collaboration with folks that don’t have ReSharper or Rider installed, it makes sense to use Roslyn conventions in our EditorConfig file as well. Since ReSharper 2017.1 we supported reading most of the Roslyn formatting conventions and adjust the effective ReSharper settings accordingly. In ReSharper 2018.1 EAP and Rider 2018.1, we extend our support by the following Roslyn language conventions including their severity:

  • dotnet_style_qualification_for_field
  • dotnet_style_qualification_for_property
  • dotnet_style_qualification_for_method
  • dotnet_style_qualification_for_event
  • dotnet_style_predefined_type_for_locals_parameters_members
  • dotnet_style_predefined_type_for_member_access
  • dotnet_style_require_accessibility_modifiers
  • csharp_preferred_modifier_order
  • csharp_style_var_for_built_in_types
  • csharp_style_var_when_type_is_apparent
  • csharp_style_var_elsewhere
  • csharp_style_expression_bodied_constructors
  • csharp_style_expression_bodied_methods
  • csharp_style_expression_bodied_properties
  • csharp_style_expression_bodied_accessors
  • csharp_prefer_braces

Note: we will add support for Roslyn naming conventions in a future version of ReSharper.

Before adding any of these conventions to our EditorConfig files, we need to enable the related option under Options | Code Editing | General Formatter Style:

Enable reading formatting settings from editorconfig

As an example, we could specify to prefer built-in type names instead of var and notify with a warning if the convention was violated:

This setting will automatically be applied to the effective ReSharper settings. For better understanding, the overridden settings are highlighted in yellow:

Overriding settings via editorconfig

Another great way to find out about our effective settings, is to browse ReSharper | Windows | File Formatting Info:

Formatting tool window

Tip: we can open any ReSharper tool window by hitting Alt+Enter and typing its name.

Our help section provides more information about using EditorConfig files.

Stay tuned for the next part of this series, in which we will see how ReSharper and Rider integrate with StyleCop configurations.

Download ReSharper 2018.1 EAP now! Or give Rider 2018.1 EAP a try. We’d love to hear your feedback!

About Matthias Koch

Matthias is a passionate C# developer and likes to talk about clean code, testing and tooling in general. Much of his spare time in the last years was devoted to his very own open source projects, including NUKE. He is working at JetBrains as developer advocate for the .NET department. Follow him on Twitter.
This entry was posted in How-To's and tagged , , , , , , , , . Bookmark the permalink.

3 Responses to Code style settings from Roslyn conventions in EditorConfig

  1. Bulat says:

    I’m trying to use these styles dotnet_style_… in Rider 2018.3.4 but it says “unknown key”. How can I solve this?

  2. Manuel Riezebosch says:

    How about roslyn diagnostic (or code quality) analyzers: For example dotnet_diagnostic.CA1062.severity = none works on build but not for Rider.

Leave a Reply to Smad Cancel reply

Your email address will not be published. Required fields are marked *