Duplicate Imports
ID |
csharp.duplicate_imports |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
CSharp |
Tags |
code-style, imports |
Description
Reports using directives that appear more than once within the same scope, whether at file
level or inside a namespace. A repeated using System.Text; adds nothing the compiler needs
and only clutters the source.
Rationale
Duplicate using directives are dead weight. They lengthen the using block, make it harder to
see at a glance which namespaces are actually in scope, and add noise to diffs and merges. A
using static and a plain using of the same name are kept distinct (they import different
things), as are alias directives keyed on their alias, so only true duplicates are reported.
using System;
using System.Text;
using System.Text; // FLAW — System.Text already imported
using static System.Math;
using static System.Math; // FLAW — duplicate static import
using System.Collections.Generic; // OK — imported only once
Remediation
Delete the redundant using directive, keeping a single occurrence of each namespace, static
import, or alias within a given scope.