.NET Tools
Essential productivity kit for .NET and game developers
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:
- Maintaining consistent code style with formatting inspections
- Configuring inspection severities with EditorConfig
- Code style settings from Roslyn conventions in EditorConfig
- StyleCop code style settings and inspections
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_fielddotnet_style_qualification_for_propertydotnet_style_qualification_for_methoddotnet_style_qualification_for_eventdotnet_style_predefined_type_for_locals_parameters_membersdotnet_style_predefined_type_for_member_accessdotnet_style_require_accessibility_modifierscsharp_preferred_modifier_ordercsharp_style_var_for_built_in_typescsharp_style_var_when_type_is_apparentcsharp_style_var_elsewherecsharp_style_expression_bodied_constructorscsharp_style_expression_bodied_methodscsharp_style_expression_bodied_propertiescsharp_style_expression_bodied_accessorscsharp_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:

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:

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

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!
