Code formatting engine updates in ReSharper and Rider

Over the past few ReSharper releases, we completely rewrote our code formatting engine. By doing this rewrite, we are able to iterate and innovate more rapidly.

In the latest ReSharper 2017.3 EAP releases, we have started to build on top of these rewritten foundations, guided by the most-voted feature requests in our issue tracker. Let’s start a blog series and look at the various improvements!

This post is part of a series around changes in the ReSharper and Rider code formatter:

New code formatting options in ReSharper and Rider 2017.3

Both ReSharper 2017.3 EAP and Rider 2017.3 EAP (coming soon) come with a number of new options for configuring the code formatting engine and defining code style of C#, C++, JavaScript, TypeScript, HTML and Protobuf. Make sure to explore the ReSharper settings under Code Editing!

For example in ReSharper C++, we can now configure outdenting for . and -> in chained method calls, and for commas. For HTML, there are new options for configuring linebreaks before multiline elements or even before all elements.
Configure HTML linebreaks for multiline elements

Both ReSharper 2017.3 EAP and Rider 2017.3 EAP come with a large number of existing and new code formatting options. Here’s a list of some of the new options:

  • All languages (C#/C++/JS/TS/HTML/Protobuf)
    • Disable/enable/change settings for code formatter with comments
    • Disable formatter using .editorconfig file masks that have disable_formatter=true
    • Option to keep extra space inside (to respect user alignment around existing =)
  • C#
    • Alignment in columns inside code
    • Options to outdent binary operators, dots and commas
    • Option “Nested ternary expression style”
    • Option to insert blank lines before/after statements: depending on their contents
    • Improve alignment of nested binary expressions and chained method calls
    • Line Breaks and Wrapping options to place attributes on same line/previous line, specify arrangement of attributes, …
    • Options to specify single-line/multi-line formatting for expression-bodied members
    • Options for embedded blocks of code
  • HTML formatter has new options for linebreaks before multiline elements or even before all elements
  • C++ adds outdenting for . and -> in chained method calls, and for commas

And many, many more! In the next post, we’ll look at two awesome new features made possible by our code formatter rewrite: disabling/enabling/configuring the code formatter for different blocks of code, and chopping long lines of code.

Download ReSharper 2017.3 EAP and give it a try! We’d love to hear your feedback!

This entry was posted in How-To's and tagged , , , , , , , , , . Bookmark the permalink.

4 Responses to Code formatting engine updates in ReSharper and Rider

  1. GreenMoose says:

    Aww still no “always use var in foreach” (in combination with “use var when type is evident”) (RSRP-433029) ? :)

  2. Alex Povar says:

    And still this not all the EditorConfig properties are supported (e.g. “this” keyword usage: RSRP-465742).

  3. Andreas Seibt says:

    In general EAP6 is very unstable i get a lot of exceptions on various places while editing source code.

  4. Mackenzie Zastrow says:

    Any chance with these updates that we’ll get format on save [RSRP-115863]( or a command to invoke format [RSRP-465536]( with the new formatting engine?

Leave a Reply

Your email address will not be published. Required fields are marked *