Skip to content

qualify-namespace-usings

C#stylefix: safedefault: offcsharp/stylecop

Reports a using directive inside a namespace whose name is not written fully qualified, so that it resolves relative to the enclosing namespace. The fix writes the full name, unless it has type arguments.

A relative name resolves to different things when a namespace with that name is added anywhere in the enclosing namespaces, so a new file can change what a using means without touching it.

To fix, write the full name.

Reported
using System;
using System.Diagnostics;
namespace A.B {
using C.D;
struct S { }
...
class P { public virtual void Run() { } }
...
After the fix
using System;
using System.Diagnostics;
namespace A.B {
using A.C.D;
struct S { }
...
class P { public virtual void Run() { } }
...
csharp:
lint:
rules:
qualify-namespace-usings: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line qualify-namespace-usings in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1135 full