Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom code analysis in ReSharper

Tags:

resharper

I'm new to ReSharper. For those who uses Resharper, is there a way I can add custom code analysis rules?

For example I might have a rule say All private variables should start with letter "m". How can I add this to Resharper so if I violate this, it can shows as a warning or an error?

like image 236
Rajithakba Avatar asked Feb 15 '10 06:02

Rajithakba


People also ask

How do I run a ReSharper code analysis?

ReSharper helps you resolve most of the discovered code issues automatically. All you need is to press Alt+Enter when the caret is on a code issue highlighted in the editor and check the suggested quick-fixes.

How do I change my ReSharper settings?

To configure the main set of ReSharper preferences In the Visual Studio menu, choose ReSharper | Options. In the Options dialog that appears, select a node in the left pane and configure settings in the right pane. Use the search box in the left top corner to find a specific preference.

How can I get ReSharper report?

Study inspection results saved in an XML report In the main menu, choose ReSharper | Inspect | Load Saved Issues Report. Select an XML report file and click Open. The report is opened in a new tab of the Inspection Results window.


3 Answers

I know the question is old, but for all folks coming from google like me:

Resharper -> Options -> Code inspections -> Custom Patterns

There you can create your own rules for highlighting patterns or offering substitutions. This is for ReSharper 8. I'm not sure from which version this option is there.

like image 187
Episodex Avatar answered Nov 02 '22 00:11

Episodex


You can write your own plugins for ReSharper. Take a look at here:

http://stylecopforresharper.codeplex.com/

This is similar to what you're asking for. It might even do what you want. Not sure since I'm not a big StyleCop user.

Also take a look at the first in my series of blog posts coming on ReSharper plugins:

http://hadihariri.com/2010/01/12/writing-plug-ins-for-resharper-part-1-of-undefined/

like image 44
Hadi Hariri Avatar answered Nov 02 '22 00:11

Hadi Hariri


Just to expand on what @AakashM notes above: this can be specified in ReSharper Options | Languages | (either Common or C# or whatever) | Naming Style.

If you click on Advanced Settings, and then double-click on one of the "entity descriptions", there is a far larger selection of possible entities (including events, namespaces etc) , together with access rights (private, protected, etc) and so on, for which you can define prefix, suffix and casing rules.

like image 43
Joel in Gö Avatar answered Nov 02 '22 01:11

Joel in Gö