Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Regex to write custom patterns in Resharper

I'm currently trying to write rules to enforce some code formatting for our team using Resharper 9. Some of the rules I'm trying to write don't work properly or don't work at all. Example : Enforcing simple getter and setter properties in a single line : enter image description here

which will convert this : enter image description here

to this :

public string Description { get; set;
    }

As you can see, the ending curly brace is gone to a new line which I didn't ask for.

Anyone has encountered this problem ?

Another random issue is to rewrite methods with an empty space between the method name and the leading parenthesis :

enter image description here

but I can't get this one to work. Any help would be great

like image 985
Mehdi Avatar asked Nov 21 '25 21:11

Mehdi


1 Answers

Structural Search and Replace isn't designed to enforce formatting - almost the opposite! It's designed to match code regardless of formatting, and to match code constructs that are similar (e.g. x > 1 and 1 < x are equivalent matched statements).

To enforce this kind of formatting requires something like StyleCop. There is currently a plugin for 9.1, but not 9.2. The plugin for 9.1 is available in ReSharper's Extension Manager (ReSharper → Extension Manager), however, it's only visible if you enable pre-release extensions (ReSharper → Options → Extension Manager → Enable pre-release). Hopefully, the 9.2 compatible version will be available soon.

like image 191
citizenmatt Avatar answered Nov 23 '25 14:11

citizenmatt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!