2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2020-06-30 12:47:33 +02:00
|
|
|
Unused parameters are misleading. Whatever the values passed to such parameters, the behavior will be the same.
|
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2021-11-01 15:31:47 +01:00
|
|
|
This rule raises an issue when a ``++private++`` method or constructor of a class/struct takes a parameter without using it.
|
2020-06-30 12:47:33 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2020-06-30 12:47:33 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,csharp]
|
2020-06-30 12:47:33 +02:00
|
|
|
----
|
|
|
|
private void DoSomething(int a, int b) // "b" is unused
|
2021-11-01 15:31:47 +01:00
|
|
|
{
|
2020-06-30 12:47:33 +02:00
|
|
|
Compute(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DoSomething2(int a) // value of "a" is unused
|
2021-11-01 15:31:47 +01:00
|
|
|
{
|
2020-06-30 12:47:33 +02:00
|
|
|
a = 10;
|
|
|
|
Compute(a);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2020-06-30 12:47:33 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,csharp]
|
2020-06-30 12:47:33 +02:00
|
|
|
----
|
|
|
|
private void DoSomething(int a)
|
2021-11-01 15:31:47 +01:00
|
|
|
{
|
2020-06-30 12:47:33 +02:00
|
|
|
Compute(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DoSomething2()
|
2021-11-01 15:31:47 +01:00
|
|
|
{
|
2020-06-30 12:47:33 +02:00
|
|
|
var a = 10;
|
|
|
|
Compute(a);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2020-06-30 12:47:33 +02:00
|
|
|
|
|
|
|
This rule doesn't raise any issue in the following contexts:
|
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2021-01-27 13:42:22 +01:00
|
|
|
* The ``++this++`` parameter of extension methods.
|
2020-06-30 12:47:33 +02:00
|
|
|
* Methods decorated with attributes.
|
|
|
|
* Empty methods.
|
2021-01-27 13:42:22 +01:00
|
|
|
* Methods which only throw ``++NotImplementedException++``.
|
2020-06-30 12:47:33 +02:00
|
|
|
* Main methods.
|
2021-01-27 13:42:22 +01:00
|
|
|
* ``++virtual++``, ``++override++`` methods.
|
2020-06-30 12:47:33 +02:00
|
|
|
* interface implementations.
|
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
* Remove this unused method parameter "{0}".
|
|
|
|
* Remove this parameter "{0}", whose value is ignored in the method.
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== 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[]
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|