Unused Import
ID |
csharp.unused_import |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
CSharp |
Tags |
dead_code, reliability |
Description
Reports using directives that bring no name into scope:
-
aliased (
using X = N.M.T;) — the aliasXis never referenced; -
namespace (
using N.M;) — no unqualified reference resolves to a type inN.M; -
static (
using static T;) — no unqualified member reference resolves to a static ofT.
Attribution is driven by the sankxy local symbol table: every using directive
is a symbol and the usage resolver credits unqualified type or member references
to the directive that brought them into scope. A directive with no recorded
usages is dead code.
Rationale
Dead imports accumulate over refactors. Removing them keeps the file declarations honest and avoids confusion about which namespaces are actually needed.
using System; // OK, referenced
using System.IO; // OK, File comes from here
using System.Text; // FLAW (nothing from System.Text is used)
using StringList = System.Collections.Generic.List<string>; // FLAW (alias never used)
using Json = System.Text.Json.JsonSerializer; // OK, referenced
public class Sample
{
public bool Exists(string path) => File.Exists(path);
public string Serialize<T>(T value) => Json.Serialize(value);
}
Remediation
Delete the aliased using directive that is no longer used. If the alias is part
of a planned migration, mark it with a TODO comment so the intent is visible.