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.
Related
I have a file with loads of redundant x?.let { it.something() } and I want to keep them this way.
How do I suppress the warning? IDE doesn't offer suppression here. I've looked into Errors.java and DefaultErrorMessages.java but nothing seemed to fit.
More general question: what arguments are supported by #Suppress annotation?
Like I said in the comment on the other question, just use the IDE to suppress warnings - every warning popup has a 'More Options' link, or you can put the cursor on the highlighted bit of code and do Alt+Enter (or whatever) or click the lightbulb. Then you'll get a list of actions for the warning, and you can hit the right arrow to get options for each one - the main action (the "fix it" one) has options that allow you to suppress the warning instead:
There's no defined set of possible things you can suppress, because things like lint checks can be added to over time (or by using libraries that provide their own checks), IDE features can be expanded, etc. Like the language spec says:
kotlin.Suppress is used to optionally mark any piece of code as suppressing some language feature, such as a compiler warning, an IDE mechanism or a language feature. The names of features which one can suppress with this annotation are implementation-defined, as is the processing of this annotation itself.
So it's better to let the IDE do it automatically since it knows the name of the inspection being triggered when it warns you about a thing, so it can create the appropriate annotation.
Generally you shouldn't be suppressing these anyway, they're highlighting code that has issues, is unnecessarily complex, or that isn't actually what you think it is (like in my example there, I'm treating the value as potentially null - but it's not actually a nullable type). It's better to fix the issue rather than suppress it and leave the intent ambiguous. Even if you know what it means and what it's supposed to do, someone who comes along later might be confused by it (possibly Future You!). There are some situations where it's necessary or useful, but generally speaking the warnings are there for a good reason.
Android Studio just updated its Kotlin plugin, and suddenly my code is polluted with warnings about the naming conventions. Apparently Google and/or JetBrains think everyone ought to use CamelCase, but (a) I prefer snake_case (use of underscores), (b) nearly every line of my sources now has a lint complaint, making it hard to separate the wheat from the chaff, and (c) I don't have time to rewrite all my code just to pander to other people's aesthetic sense.
How do I convince AS to be a Philistine like me?
In the menu, select File, then Settings. In the leftmost panel of the window that now appears, select Editor, then Inspections. In the next leftmost panel that now appears, find Kotlin, unfold it by clicking on the triangle, then find Naming conventions, and unfold that. You now have two options.
If you want AS to disregard Kotlin naming conventions, you can simply uncheck its box, and the boxes below it.
However, you can actually use this to convince AS to convert to snake_case instead of CamelCase, or any other aesthetic, as opposed to Google's and/or JetBrains'. If you click on, for instance, "Class naming convention," you will see on the right a text box labeled "Pattern:". It will probably contain [A-Z][A-Za-z\d]*. Add an underscore in a strategic location according to regex rules, for instance, [A-Z][_A-Za-z\d]*. Do this for each of the identifier types whose naming convention you'd like to change, and you're good to go.
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.
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/
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.