Prevent ReSharper from formatting specific code block

4.1k Views Asked by At

Is there a way to prevent ReSharper from formatting a specific code block in a file? Something like:

void MyMethod ()
{
    // ReSharper disable formatting
    PRE     =   { my top format }   /* no rules */   ;
    // ReSharper enable formatting
}
2

There are 2 best solutions below

0
On BEST ANSWER

At the moment this is not possible. See feature request RSRP-187963.

As a workaround, if you have a big chunk of "pre-formatted" code, you could move it to an own (partial class) file and add it to the "Generated Code" configuration list. This disables R#'s "Code Cleanup" for this file. Note that it also disables the inspections! (Unfortunately the "Generated Code Region" feature only disables the inspections, not the "Code Cleanup" for a region, as of R# version 9.2.)

7
On

Now it is possible in version 2017.3 like this:

// @formatter:off — disable formatter after this line
// @formatter:on — enable formatter after this line