question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CC0057 : Unused parameters on extension methods

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cybermaxscommented, Jun 1, 2016

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’.

//csharp
     public static class LabelExtensions
     {
          public static string Label(this HtmlHelper helper, string target, string text)
          {
               return String.Format("<label for='{0}'>{1}</label>", target, text);

          }
     } 
//razor vew
 <%= Html.Label("firstName", "First Name:") %> 

But I think the general suggestion is more :: should it provide a fix that is useless and will break the code ?

0reactions
giggiocommented, Jun 12, 2017

@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. 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found