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?
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.
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.
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/
Related
Want to be able to do a Find but contain my results to the current namespace the current opened file is in. Like "Current Project" but "Current Namespace". Is there a plugin or tool that can do this?
You can always use a regex :
namespace my_namespace(.*\n)*.*my_search
That's kind of an ugly solution, since it will select everything between namespace keyword and you search. But that's still useful.
You can adapt it and change capture groups in order to be able to use it for replacements.
Rather than parsing and inspecting every code file individually, Agent Mulder plugin utilizes ReSharper's Structural Search (sometimes known as Structural Search and Replace, or SSR) to look for patterns of code in the entire solution. This is both effective (since the solution structure already exists in ReSharper's caches), and makes it very easy to extend Agent Mulder to support additional containers.
Here is an overview of ReSharper's Structural Search API (based on ReSharper SDK v6.1)
When using the various navigation and usage features of ReSharper, is there a way to make it hide some of the projects (with tests) in the solution?
Often when I'm browsing through the code, I'm not really interested in the tests, but only the production code.
I received this answer from the Resharper support team.
I have looked at "find usages" deeper and figured out that there is the
following item in filter dropdown -- "Show Unit Test Usages" (attached). So
if you uncheck this item -- usages from Test Projects won't appear in search
result.
Well im not sure this works for the navigation and usage features but for analysis it does, tryto use the skip files and folders menu to add folders which should be excluded.
Under Optionmenu use Settings under the Code Inspection section and select "Edit Items to Skip" and select your folder.
Take a look at this Article too
First, there's no setting in ReSharper to "forget" a certain project in solution.
However, in some cases, navigation combos may help you out.
For example, when you search for types, files or symbols with ReSharper, you can restrict search scope with navigation combos. Say, in NHibernate, entering "dm spec " in Go to Type restricts search scope to Projects\Core\NHibernate.DomainModel\NHSpecific
I'm trying to find a list of all the default formatting and rules that Resharper enforces.
Unfortunately, I'm not having any luck.
We use the tool, but want to provide a document of standards to new hires so they can view the standards prior to coding.
Under the ReSharper menu, then Options, you'll find the current rules and conventions ReSharper is using for this solution. Of particular importance are:
Code Inspection->Inspection Severity: Shows the severity of things that ReSharper detects in code. The more things that are warnings or errors, the more closely you will have to conform code to ReSharper's conventions in order to get the file to "go green", or even to compile. The hierarchy is:
Do Not Show - self-explanatory, ignores the inspection
Hint - Does not show on sidebar, shows as dotted line under code in question. Good example: using "var" when the line of code doesn't otherwise explicitly specify the type being assigned.
Suggestion - Shows on sidebar as green tick, code in question has green underline. Good examples: use of "var" when type is explicitly defined in the assignment, member visibility.
Warning - Shows on sidebar as yellow tick, code in question underlined blue, or text is faded color. Naming convention violations, redundant keywords or qualifiers, unused code members.
Error - Red sidebar tick, code in question either red text or underlined red. By default, nothing that wouldn't cause a compilation error is marked as a ReSharper error, but you can prevent compilation by "promoting" lower-priority inspections to errors.
Languages->Naming Style: This section shows you how ReSharper will expect various types of code member names to be formatted. The "Advanced settings" option also contains the "abbreviations list", which is basically a list of exceptions to the normal camel-casing conventions. By default, all format inconsistencies are warnings, and I do not see a way in 5.1 (the version I use) to change the severity of this.
EDIT: Here's a list of inspections and their default severities for RS 4.5, which is a few versions back but should still have the "meat" of ReSharper's C# inspections. http://unintelligible.org/blog/2010/05/24/resharper-45-inspection-severity-list/
Beyond this, even JetBrains simply refers you to the Options window if you want to see the list of inspections for your current language. So, if you want something more up-to-date, you may have to do it yourself. If you do, be sure to post it somewhere so others don't have to repeat your work.
IMHO company coding standard is more than just formatting. It usually includes project organization conventions, library usage guidelines, etc. Listing every possible formatting rule ReSharper knows about will make it quite long and boring. Few examples for common constructs (which you can copy from bottom part of formatting setup window) should suffice. Providing them with short rationale should not be too hard to do manually.
Much like
// ReSharper disable ConvertToAutoProperty
I would like to know what, if existing, I can add to particular files (and only particular files) so that fields are not sorted on code cleanup.
For more information:
I know there are settings one can set in R# itself. This needs to work even where I don't control settings (like on other people's computers)
I know I can make a setting to disable sorting for particular types in TypeMembersLayout. This also will not work due to the same reason.
I only want this to happen on files I care that it doesn't happen with, not a global setting.
I've been using Resharper for years, and can say with confidence this option doesn't exist. Good idea though..
Maybe Generated Code options can help you. But I didn't try it.
Go to ReSharper->Options->Code Inspection->Generated Code and add your files.
I think ReSharper leaves such files untouched.
From version 5.0 onwards, ReSharper offers a "Go To Related Files" navigation which offers a list of files that R# thinks are related to the file currently being edited: for example, base types, derived types, .designer.cs to and from the relevant .cs, and so on.
I have looked in the R# Options and also online, but have not been able to find out:
Is there a way to add files to this list, either within R# natively or by an already-existing plug-in?
(My motivation is to be able to navigate at coding time between files containing classes that are connected by a run-time-only convention-over-configuration, er, convention)
I don't know about existing plugins, but this feature is extendable.
You need to implement IRelatedFilesProvider interface in your plugin and mark it by RelatedFilesProvider attribute. As far as I know, NHibernate plugin do it for analogous task.