Resharper should not default to removing named parameters with literal values

Suppose you have a method


what does this mean? who knows

deathStar.PowerupReactor(overload: true)

what does this mean? looks pretty clear the reactor is being set to overload.

Unfortunately resharper wants to remove overload: with standard/common clean up code resharper settings and light bulbs. This is fine for an informational bulb, but it really shouldn't default to removing the parameter name.

Using parameter names like very frequently is a core tenant of writing code that as closely as possible resmebles spoken english.

Comment actions Permalink

Hello Chris,

  Feel free to suppress such inspection in ReSharper | Options | Code Inspection | Inspection Severity | type "Redundant explicit argument name specification for literal expression" in search field | Do not show.


Comment actions Permalink

I am having this problem with 2016.1 ultimate. I did not have this problem before.  The option named above is not visible in the list of inspections.  The arguments have always been shown in grey (meaning a hint) and the bulb calls it a "redundant argument name". But now the cleanup has started removing them.

They are vital. Especially in our unit tests where helper functions take several parameters and labeling them this way is essential to make the tests readable.  Please can you fix Resharper so these are no longer removed in code Cleanup. I can't begin to think of a situation where a developer has gone to the trouble of naming arguments and wishes to see them vanish.

Comment actions Permalink

@Colin Harkness it looks like this was something they officially added to resharper 2016.1 check out it talks about it. ctrl+f parameters to jump to it. it's possible the default settings for this new feature just aren't configured to your liking.

Comment actions Permalink

Chris, thanks for pointing this out, but I think they've not implemented it correctly. I have all these set to "Positional argument" and "Hint".  The before and after sections show the cleanup respecting any named arguments that are present. Changing to "Named argument" seems to force all arguments in that category to being named. However, in practice it forces all to either Positional or all to Named. There's no "leave it alone" option.


It seems an odd choice anyway. If any parameter is named, then all the parameters to the right of it also need to be named.I find it hard to imagine that one would want all literals named (e.g. p.SetReadOnly(true) is descriptive without naming the argument).  It would certainly be handy to have a feature to name all the parameters in a method-call.

Comment actions Permalink

The current version of ReSharper is v2017.1 and it seems JetBrains hasn't solved this problem yet.

As @Colin Harkness noticed, currently the last resort for keeping "named parameters" is to set the option "Named expressions (variables, properties, methods, etc)" to "Named argument".

This is certainly not the best way out.

Comment actions Permalink

I found that I can leave named arguments when I cleanup code in below way.

Version v2017.1.2.


First, I have to write this special comment.


// ReSharper disable ArgumentsStyleNamedExpression


Second, I have to uncheck Remove code redundancies.

Forgive me if I am wrong.

Comment actions Permalink

@onionmk2, thank you for your solution. It Does Work.

I've done some minor configuration though. In order to keep automatic addition of the "// ReSharper disable ArgumentsStyleNamedExpression" simple, I have added this instruction to File Header Text as is shown in fig. 1.

                                                         Fig.1 - Add ArgumentsStyleNamedExpression Rule


After that, you have to check "Update File Header Option" in Code Cleanup Configuration as is shown in fig. 2

                                                         Fig.2 - Check "Update File Header" option

 In this case, when a Code Cleanup starts, it first adds ArgumentsStyleNamedExpression rule, and applies code style to file.

 After adding this rule, you can go to Tools | Options | Environment | Fonts and Colors | ReSharper Parameter Identifier and change the highlighting color for this case in order to visually distinguish arguments and parameters names as is shown in fig 3.

enter image description here

Fig.3 - Parameter name highlighting



Please sign in to leave a comment.