Dotnet logo

The .NET Tools Blog

Essential productivity kit for .NET developers


Formatter comments and more in ReSharper and Rider 2018.2

Probably everyone has faced this issue once or twice: we’ve gone through all these options to find some proper formatting and code style settings. Most of our code looks pretty and clean now. But then, there are these few cases, where the formatter leaves our code in a rather unreadable or inconvenient shape.

ReSharper 2018.2 to the rescue! It introduces a new button Save as comments in the Configure Format dialog, which allows us to make ad-hoc adjustments with formatter comments:

Adding formatter comments

Formatter comments are supported by ReSharper and Rider 2018.2. However, the Configure Format dialog is currently exclusive to ReSharper. Eventually, this dialog will be added to Rider as well.

Speaking of the Configure Format dialog, it is an excellent way to illustrate some other features we’ve added: there is a total of 4 new options to configure how enumerations are arranged by ReSharper.

Some of them are rather familiar from other formatting options, like Keep existing arrangement of enumeration and Wrap enumeration declaration (Chop always, Chop if long, Simple Wrap). All new and shiny are the options max enumeration members on a single line and place simple enumeration on single line. Here they are in action:

Formatting enum types

In a similar way, the max elements on single line option has been added to other declaration types, including method signatures, method invocations and initializers. For initializers, we can even differentiate between initializers for arrays and other initializers:

Formatting initializers

Moreover, we’ve made initializer formattings more intuitive in ReSharper and Rider 2018.2. For instance, the general setting Keep existing line breaks is now superseded by the more specific setting Keep existing arrangement of initializers. Similarly, the Chop if long or multi-line setting for Wrap object and collection initializers has been fixed to only chop, when there are line breaks between elements and their separating commas (i.e., line breaks around closing curly/square brackets won’t affect formatting).

The default indent size for C# is 4, which can take up quite a lot of space for blocks with deep nesting. While some developers decided to halve this value, this can also decrease readability. As an established alternative approach, ReSharper and Rider 2018.2 now support to omit indentation for namespace declarations:

No indentation for namespace blocks

Also the StyleCop integration has been further improved. In the last release, we’ve introduced yellow highlightings for overridden settings by StyleCop.Settings file. With ReSharper and Rider 2018.2 we also show a tooltip that indicates the specific StyleCop rules being responsible for the override:

Settings overridden by StyleCop

With this information we can navigate to the File Formatting Info tool window and find out, which other settings this particular rule affects. The tool window now outlines the related ReSharper settings for inspections, formatting and code style. As of now, this tool window is exclusive to ReSharper, but will be added to Rider eventually:

Overridden ReSharper settings sorted by StyleCop rules

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

Comments below can no longer be edited.

1 Response to Formatter comments and more in ReSharper and Rider 2018.2

  1. Dew Drop - August 22, 2018 (#2787) - Morning Dew says:

    August 22, 2018

    […] Formatter comments and more in ReSharper and Rider 2018.2 (Matthias Koch) […]

Discover more