Resharper function to fix naming convention issues - resharper

A bunch of classes doesn't comply to our naming conventions for private variables. Resharper shows this as a warning, but wants me to fix all of them by hand. Is there some magic option to auto-fix these issues?
'Clean-up code' won't do anything with this. Same goes for converting properties with backing fields to automatic properties when possible: the hint is shown, but Resharper won't fix it automatically.

In more recent versions of ReSharper, this is much easier, but the solution might not be obvious. It wasn't for me!
Here are the steps:
When an inconsistent naming is detected, ReSharper underlines the symbol in question. Click on it. This will cause a light bulb to appear in the margin.
Click on the light bulb. The first option should be 'rename to [corrected name]'. To the right, there's an arrow.
Click the arrow to drill down. From there, you can choose Fix in File, Fix in Project, and so on.

No, resharper will not silently perform an action that alters the behavior of code, only style/aesthetics.
You must actively make functional changes to code.
put your cursor at the top of the file, hold down ALT and alternate between PAGE DOWN to get to the next style issue and ENTER to bring up the smart tag to make the change.
use SHFT-ALT PAGE DOWN to cycle through errors.

Related

How to expand an UltiSnips snippet using <c-y> in the YouCompleteMe pop-up menu?

This problem really hit a nerve with me. I have both YouCompleteMe and UltiSnips installed on my vim 8.0 editor. It seems that both of these plugins use the tab key for doing the auto-completion and that has created an incompatibility that has been also addressed by this question. My question is more specific, though. When I write a piece of code like <html, there is a pop-up menu that shows me all related snippets for that code.
I use the tab key to navigate through that menu but when I hit ctrl+y to accept and therefore expand one of these snippets, nothing happens! I think this structure suggests that it's possible to somehow choose one of those snippets from the menu without trying to define a shortcut for UltiSnip. What am I doing wrong? How should I navigate and choose those snippets?
I also would not want to stuff my vim with any new plugins (like supertab, etc.).
The solution was actually a lot simpler than I expected. In the beginning, I felt stupid for not knowing it but when I find a similar question like this one, I thought that probably many were fallen into the same trap.
I don't know whether to name it a bug or not but it's how Ultisnips and YouCompleteMe work together. In order to expand a snippet, you have to write the initializer exactly as it's defined. Of course, this seems obvious, but when you see a pop-up menu of different snippets, you might think they can be chosen but it only works if you already wrote the snippet initializer exactly as it's defined.
So when a snippet is called "html5"---as it's shown in my question---writing an extra opening bracket (<) will cause it to stop working. It cannot be expanded.
Also, don't forget to check out Siegfried Gevatter configuration. It's not possible to use tab key both for navigating into the pop-up menu and expanding the snippets.
P.S. It was nice if navigating through the pop-up menu could change the whole word (including the angle bracket), not just what succeeds it. This feature works this way in most of the other editors I see and that's probably why I wasn't able to spot the problem in the beginning.

prevent resharper from automatically fixing issues

I noticed that Resharper automatically applies fixes (e.g. removing unnecessary namespace prefixes) in methods that I am not working on within the file I'm working on. How do I turn this off? (I only want to fix things if I take specific action).
After reading your question, I'm not sure whether it is about disabling automatic fixes, or just make them more local.
What you're talking about, is called Code Cleanup. You can disable parts of that in the ReSharper options, including the "Optimize Using directives", which you were talking about.
If you just want to cleanup/format a part of a file, you have the option to first select the method/code part, and then hit the shortcut to cleanup. Then, all modifications will just apply to the selected area, not the file.

List of Resharper Default Formatting and Rules

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.

ReSharper - Is there a disable command I can add to a file that will not allow reorder of type members?

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.

Have you used JustCode?

Has anyone used JustCode from Telerik lately? This question has been asked about two years ago, but I'm sure the issues must have been resolved by now. Especially referring to running it side by side with ReSharper.
I have been using Resharper for a while now. I decided to try JustCode to see how it behave.
After a week of using JustCode, I am uninstalling it and returning to Resharper.
What I like about JustCode:
A single window indicating all warnings/errors in entire solution.
Performance seemed to be a bit better than Resharper.
Refactoring is easier to get to.
Projects can be excluded, or type of file
Language can be excluded (such as XAML)
What I did not like about JustCode:
Sometimes the underline used to open the option for fixing or refactoring is frustratingly hard to click since VS also puts an underline at the same spot (and it is the context menu of the latter that pops up).
Cannot change an hint to be a warning instead.
Saw some minor bugs
JustCode was giving hundreds of false positive warnings in the XAML code (luckily I could turn the inspection of XAML off)
What I was missing from Resharper:
Warnings about method parameter missing/mismatch from the documentation
Hints to transform an expression into a Linq expression.
When writing an opening bracket, resharper automatically adds the closing one and puts you on an empty line in between the two.
When completing a method, Resharper adds the first parentheses. It also adds the last one if that method is parameterless.
I am sure there is a bunch of other stuff that I can't remember now
You can install both Resharper and JustCode alongside. I first suspended Resharper before installing JustCode and used JustCode fine. When I resumed Resharper and restarted VS, both were running together without error.
Together, Resharper was finding more than JustCode.
For example, JustCode did not give a warning for the following: "Value assigned is not used in any execution path."
It even missed an error: "Cannot convert type 'int' to 'bool'." The expression was:
if ((bool)CanDoIt) // Here CanDoIt is a property of type int.
{
...
}
All in all, the tool is not bad. I recommend it over not having any. But if you have the choice between Resharper and JustCode, go with Resharper... for the moment; JustCode is still young.
You can change the size of JustCode's smart tag or turn off Visual Studio's smart tag in JustCode's options menu. I prefer to access VS's smart tag by using ctrl+., so it hasn't been an issue for me.

Resources