-
Notifications
You must be signed in to change notification settings - Fork 277
Description
The following code fragment
public ActionResult ChangePassword(ChangePasswordMessageId? message, bool? Redirect = false)
{
var returnUrl = "ChangePassword";
Correctly identifies a place where nameof should be used. However it suggests using nameof(ChangePasswordMessageID) instead of the correct nameof(ChangePassword). If I change the type of message it produces the correct fix, and if I change returnUrl to "ChangePasswordMessage" then it does not suggest any fix. This leads me to believe that it's correctly identifying the issue, but incorrectly finding the suggested fix because of the matching prefix, although I haven't looked at the code so I can't be sure (I'll take a look later on if you want).
Tested with code-cracker version 1.0.0-rc2 (although I believe it also existed in earlier versions).
Here is a simple test that will not work:
public class TypeName
{
void Foo(TypeName d)
{
var bar = new [] { "Foo" };
}
}And here is the test case:
[Fact]
public async Task ReplacesUsingMethodName()
{
const string source = @"
public class TypeName
{
void Foo(TypeName d)
{
var bar = new [] { ""Foo"" };
}
}";
const string fixtest = @"
public class TypeName
{
void Foo(TypeName d)
{
var bar = new [] { nameof(Foo) };
}
}";
await VerifyCSharpFixAsync(source, fixtest);
}@mirhagk is working on it.