Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bail out on reporting unused parameter diagnostic for special paramet… #32883

Merged
merged 1 commit into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,19 @@ void M(object [|o|])
{
}
}
}");
}

[WorkItem(32851, "https://github.com/dotnet/roslyn/issues/32851")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedParameters)]
public async Task Parameter_Unused_SpecialNames()
{
await TestDiagnosticMissingAsync(
@"class C
{
[|void M(int _, char _1, C _3)|]
{
}
}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ $"Public Class C
System.Console.WriteLine(p)
#End If
End Sub
End Class")
End Function

<WorkItem(32851, "https://github.com/dotnet/roslyn/issues/32851")>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedParameters)>
Public Async Function Parameter_Unused_SpecialNames() As Task
Await TestDiagnosticMissingAsync(
$"Class C
[|Sub M(_0 As Integer, _1 As Char, _3 As C)|]
End Sub
End Class")
End Function
End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ private bool IsUnusedParameterCandidate(IParameterSymbol parameter)
return false;
}

// Ignore special parameter names for methods that need a specific signature.
// For example, methods used as a delegate in a different type or project.
// This also serves as a convenient way to suppress instances of unused parameter diagnostic
// without disabling the diagnostic completely.
// We ignore parameter names that start with an underscore and are optionally followed by an integer,
// such as '_', '_1', '_2', etc.
if (parameter.Name.StartsWith("_") &&
(parameter.Name.Length == 1 ||
uint.TryParse(parameter.Name.Substring(1), out _)))
{
return false;
}

return true;
}
}
Expand Down