rspec/rules/S1144/csharp/rule.adoc

62 lines
1.5 KiB
Plaintext

== Why is this an issue?
``++private++`` or ``++internal++`` types or ``++private++`` members that are never executed or referenced are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.
=== Noncompliant code example
[source,csharp]
----
public class Foo
{
private void UnusedPrivateMethod() {...} // Noncompliant
private class UnusedClass {...} // Noncompliant
}
----
=== Compliant solution
[source,csharp]
----
public class Foo
{
public Foo()
{
UsedPrivateMethod();
}
private void UsedPrivateMethod()
{
var c = new UsedClass();
}
private class UsedClass {...}
}
----
=== Exceptions
This rule doesn't raise issues on:
* Empty constructors
* Attributed members
* ``++Main++`` method
* Methods with event handler signature ``++void Foo(object, EventArgs)++`` that are declared in partial class
* Empty serialization constructor on type with ``++System.SerializableAttribute++`` attribute.
* Internals in assemblies that have a ``++System.Runtime.CompilerServices.InternalsVisibleToAttribute++`` attribute.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]