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:
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:
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:
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:
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:
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:
Subscribe to Blog updates
Thanks, we've got you!
Eager, Lazy and Explicit Loading with Entity Framework Core
Entity Framework Core (EF Core) supports a number of ways to load related data. There’s eager loading, lazy loading, and explicit loading. Each of these approaches have their own advantages and drawbacks. In this post, let’s have a quick look at each of these ways to load data for navigational prope…
OSS Power-Ups: bUnit – Webinar Recording
The recording of our webinar, OSS Power-Ups: bUnit, with Egil Hansen and Steven Giesel, is available. This was the twelfth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webi…
Accelerating Your Testing Workflow with Unit Test Creation and Navigation
Unit tests play an important role in our daily development workflow. They help us ensure our codebase's correctness when writing new functionality or performing refactorings to improve readability and maintainability. In the process, we often create new test files that accompany the p…
Introducing Predictive Debugging: A Game-Changing Look into the Future
With the introduction of debugging tools, software developers were empowered to interactively investigate the control flow of software programs to find bugs in live environments. At JetBrains, we've always strived to improve the art of debugging. Besides the more standard things you expect from a de…