92 lines
2.1 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
This rule raises an issue when a `private` method or constructor of a class/struct takes a parameter without using it.
=== Exceptions
This rule doesn't raise any issue in the following contexts:
* The `this` parameter of extension methods.
* Methods decorated with attributes.
* Empty methods.
* Methods which only throw `NotImplementedException`.
* The Main method of the application.
* `virtual`, `override` methods.
* interface implementations.
== How to fix it
include::../how-to-fix-it.adoc[]
=== Code examples
==== Noncompliant code example
[source,csharp,diff-id=1,diff-type=noncompliant]
----
private void DoSomething(int a, int b) // Noncompliant, "b" is unused
{
Compute(a);
}
private void DoSomething2(int a) // Noncompliant, the value of "a" is unused
{
a = 10;
Compute(a);
}
----
==== Compliant solution
[source,csharp,diff-id=1,diff-type=compliant]
----
private void DoSomething(int a)
{
Compute(a);
}
private void DoSomething2()
{
var a = 10;
Compute(a);
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Remove this unused method parameter "{0}".
* Remove this parameter "{0}", whose value is ignored in the method.
'''
== Comments And Links
(visible only on this page)
=== on 6 Mar 2017, 17:55:59 Amaury Levé wrote:
\[~freddy.mallet] Shall we ignore all empty methods or only public ones? If you say all of them, shall we also ignore empty Ctor?
About ``++static void Main(string[] args)++`` do you mean we also ignore the argument even if the method is not empty?
=== on 7 Mar 2017, 10:08:34 Jean-Christophe Collet wrote:
My suggestions:
* Ignore all empty methods including constructors (they should be flagged by another issue anyway)
* Yes, since Main(string[] args) is a 'non-negotiable' signature, we should ignore the case where 'args' is not used.
=== on 7 Jan 2019, 16:44:49 Nicolas Harraudeau wrote:
The new description matches the existing implementation. It just explains more precisely what cases raise an issue.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]