All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S1144.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

This rule raises an issue when a private/internal type or member is never referenced in the code.

Why is this an issue?

A type or member that is never called is dead code, and 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.

This rule detects type or members that are never referenced from inside a translation unit, and cannot be referenced from the outside.

Exceptions

This rule doesn’t raise issues on:

Code examples

Noncompliant code example

public class Foo
{
    private void UnusedPrivateMethod(){...} // Noncompliant, this private method is unused and can be removed.

    private class UnusedClass {...} // Noncompliant, unused private class that can be removed.
}

Compliant solution

public class Foo
{
    public Foo()
    {
        UsedPrivateMethod();
    }

    private void UsedPrivateMethod()
    {
        var c = new UsedClass();
    }

    private class UsedClass {...}
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy