Code style settings from Roslyn conventions in EditorConfig

Posted on by Matthias Koch

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!

Comments below can no longer be edited.

5 Responses to Code style settings from Roslyn conventions in EditorConfig

  1. Smad says:

    April 6, 2018

    File formating info can’t detect asmx. https://www.screencast.com/t/l9IdqMz6i3
    Also related issue:
    https://youtrack.jetbrains.com/issue/RSRP-468670

  2. Bulat says:

    April 5, 2019

    I’m trying to use these styles dotnet_style_… in Rider 2018.3.4 but it says “unknown key”. How can I solve this? https://snag.gy/VGdbnO.jpg

  3. Manuel Riezebosch says:

    January 17, 2020

    How about roslyn diagnostic (or code quality) analyzers: https://github.com/dotnet/roslyn-analyzers/blob/a23fde8d03fcec0c8e5beb6b1f3882048ab8435b/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.md. For example dotnet_diagnostic.CA1062.severity = none works on build but not for Rider.

  4. Greta says:

    June 12, 2020

    I have the same issue as Manuel Riezabosch.

    Rider does not understand
    dotnet_diagnostic.CA1062.severity = none

    type of settings from the .editorconfig file

Subscribe

Subscribe to .NET Tools updates