Dotnet logo

.NET Tools

Essential productivity kit for .NET and game developers

How-To's

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:

csharp_style_var_for_built_in_types = false : warning

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!

image description