Redundant Return Statement
I'm cleaning up old code from a messy developer. When given something like:
private void MyMethod()
{
// do something
return;
}
Why doesn't ReSharper code inspection suggest to remove my redundant return statement?
The above case isn't that bad, but I find often I have something more complicated like:
private void MyMethod()
{
if (x != null)
{
x.foo;
x.bar;
}
return;
}
Without the redundant return statement, I would normally be suggested to invert the if statement to reduce nesting. But with it there, I don't get that option. If I invert anyway, instead of reducing nesting I get an extra set of empty braces {}.
Adding an inspection to detect a redundant return statement should make things a lot easier.
Regards,
Matt
Please sign in to leave a comment.
Fixed in 6.1: http://youtrack.jetbrains.net/issue/RSRP-178762 "ReSharper should suggest to remove return; at the end of void method"
Moose with the green face,
Where is the download for 6.1? I can't seem to find it. My version of RS is build 6.0.2202.688. The link you gave suggests 6.1.0.2747 but I cannae find the bugger anywhere.
6.1 is next version to be released (don't know the timeplan).
Hello Matt,
This is something we are going to do really soon. Stay tuned.
Sincerely,
Ilya Ryzhenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
MJ> I'm cleaning up old code from a messy developer. When given
MJ> something like:
MJ>
MJ> private void MyMethod()
MJ> {
MJ> // do something
MJ> return;
MJ> }
MJ> Why doesn't ReSharper code inspection suggest to remove my redundant
MJ> return statement?
MJ>
MJ> The above case isn't that bad, but I find often I have something
MJ> more complicated like:
MJ>
MJ> private void MyMethod()
MJ> {
MJ> if (x != null)
MJ> {
MJ> x.foo;
MJ> x.bar;
MJ> }
MJ> return;
MJ> }
MJ> Without the redundant return statement, I would normally be
MJ> suggested to invert the if statement to reduce nesting. But with it
MJ> there, I don't get that option. If I invert anyway, instead of
MJ> reducing nesting I get an extra set of empty braces {}.
MJ>
MJ> Adding an inspection to detect a redundant return statement should
MJ> make things a lot easier.
MJ>
MJ> Regards,
MJ> Matt
MJ> ---
MJ> Original message URL:
MJ> http://devnet.jetbrains.net/message/5317060#5317060