29

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
}
1

2 Answers 2

43

Now it is possible in version 2017.3 like this:

// @formatter:off — disable formatter after this line
// @formatter:on — enable formatter after this line
Sign up to request clarification or add additional context in comments.

7 Comments

Where should I put it? I have a file with dapper code, sql-source intermixed with function that uses it. I do not want code R# clean-up to move all sql-strings to the top of the file. Tried putting "// @formatter:off — disable formatter after this line" early in the file. No difference. Code-cleanup reorders everything.
@mattias Please ask JetBrains via their YouTrack issue tracker and report back how it's done for non-C# files : )
This did not work for me...? I have R# 2019.2.1. I use CTRL-K+CTRL-D to format my code.
@Jess Ctrl+K, D is the Visual Studio formatter. The above will only apply to Resharper.
The link is outdated; the current one (as of 2022) is Use comments to configure formatter.
|
8

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.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.