Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.46 KB

File metadata and controls

41 lines (30 loc) · 1.46 KB

SA1210

TypeName SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace
CheckId SA1210
Category Ordering Rules

Cause

The using directives within a C# code file are not sorted alphabetically by namespace.

Rule description

A violation of this rule occurs when the using directives are not sorted alphabetically by namespace. Sorting the using directives alphabetically makes the code cleaner and easier to read, and can help make it easier to identify the namespaces that are being used by the code. The System namespaces are an exception to this rule and will always precede all other namespaces. See SA1208 for more details.

Global using directives (C# 10) are analyzed independently from local using directives. Diagnostics and fixes compare only directives which both use, or both omit, the global modifier.

How to fix violations

To fix an instance of this violation, order the using directives alphabetically by namespace with all the System namespace entries first.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1210:UsingDirectivesMustBeOrderedAlphabeticallyByNamespace", Justification = "Reviewed.")]
#pragma warning disable SA1210 // UsingDirectivesMustBeOrderedAlphabeticallyByNamespace
#pragma warning restore SA1210 // UsingDirectivesMustBeOrderedAlphabeticallyByNamespace