Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-59104: Warn on/suggest fix for apparent change to instance

$
0
0
Reporter Clinton Sheppard (clinton) Clinton Sheppard (clinton)
Created Feb 22, 2008 10:01:08 PM
Updated Apr 13, 2018 6:28:40 PM
Resolved Apr 13, 2018 6:28:40 PM
Subsystem Code Analysis
Assignee Ilya Ryzhenkov (orangy)
Priority Normal
State Fixed
Type Feature
Fix version Unidentified prior version
Affected versions No Affected versions
Fixed In Version ReSharper Undefined
VsVersion All Versions
// incorrect
public DateTime GetAdjustedDate(int months)
{
DateTime result = DateTime.Now;
result.AddMonths(-months); // modified value not stored to a variable, this line has no apparent value
return result;
}

// correct
public DateTime GetAdjustedDate(int months)
{
DateTime now = DateTime.Now;
result = now.AddMonths(-months);
return result;
}


Resharper could detect the case were results to instance methods that do not change the instance are not captured in a variable.

Similar methods are not hard to find:

string foo = "bar";
foo.ToUpper(); // modified value not stored to a variable, this line has no apparent value
return foo;

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>