CC0057 : Unused parameters on extension methods
See original GitHub issueThis is an open discussion but I think that CC0057 (remove unused parameters) should not be triggered on extension methods. sometimes, we have to add extension methods to existing class, even if we don’t use it. This a convenient method to get more coherence in client code.
public static string RenderFooBar(this HtmlHelper helper)
{
// do something without helper
return "footbar";
}
Current output after fix applied (if it is a code fix bug)
public static string RenderFooBar()
{
// do something without helper
return "footbar";
}
Please note that the project won’t compile after the code fix because RenderFooBar is no longer an extension method.
Expected output after fix applied (if it is a code fix bug)
public static string RenderFooBar(this HtmlHelper helper)
{
// do something without helper
return "footbar";
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
CA1801: Review unused parameters (code analysis) - .NET
Unused parameters incur maintenance and performance costs. Sometimes, a violation of this rule can point to an implementation bug in the method.
Read more >Heleonix.Guard 2.0.0
Provides performant guard functionality for methods to throw ... #pragma warning disable CC0057 // Unused parameters public static void ...
Read more >c# parameterless extension method [duplicate]
Is it possible to create an extension method that takes no parameters? I am new to using extension methods and have only seen...
Read more >Some helpful extensions when dealing with types in .NET
In this post, I am sharing some extension methods that became helpful when ... "IDE0060:Remove unused parameter", Justification = "Extension method")].
Read more >Remove Unused Parameter | CodeRush
Removes a method parameter if it is never referenced in the method body code. ... Remove Unused Parameter is a cascading Refactoring. That...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
True, but sometimes it’s better to keep it coherent with common conventions. In asp.net MVC, we generally create extension methods on HtmlHelper for ‘everything that will generate Html’.
But I think the general suggestion is more :: should it provide a fix that is useless and will break the code ?
@KristianWedberg It is not hard to find out, but as I said earlier, this is exactly the case where you suppress the analyzer directly in the source, that is what a suppression is for. 😉