Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent ReSharper from formatting specific code block

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
}
like image 344
D.R. Avatar asked Dec 09 '15 11:12

D.R.


People also ask

How do I set rules in ReSharper?

Find the name of formatting rule that you want to tweak. You can look it up on the Code Editing | [Language] | Formatting Style page of ReSharper options ( Alt+R, O ) or alternatively, you can select a code block where the desired rule applies, press Alt+Enter , and choose Format selection | Configure.

How to clean code visual studio?

Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

How do I run ReSharper cleanup?

Select ReSharper | Options from the main menu or press Alt+R O . Go to the cleanup profiles settings page: Code Editing | Code Cleanup | Profiles. Select which Code Cleanup profile should be applied on save and click Set as default (the default profile is also used for silent cleanup).


2 Answers

Now it is possible in version 2017.3 like this:

// @formatter:off — disable formatter after this line // @formatter:on — enable formatter after this line 
like image 167
Timur Lemeshko Avatar answered Oct 04 '22 05:10

Timur Lemeshko


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

like image 30
ulrichb Avatar answered Oct 04 '22 04:10

ulrichb