Alphabetizing using statements
This commit is contained in:
parent
b25d2d9772
commit
3bbb77f9d0
|
|
@ -2,8 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Server.Kestrel.Networking;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,41 @@ namespace Microsoft.StandardsPolice
|
||||||
location: typeDeclaration.GetLocation()));
|
location: typeDeclaration.GetLocation()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax))
|
||||||
|
.OfType<UsingDirectiveSyntax>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var priorUsingDirective = default(UsingDirectiveSyntax);
|
||||||
|
foreach (var usingDirective in usingDirectives)
|
||||||
|
{
|
||||||
|
var acceptableOrder = false;
|
||||||
|
if (!acceptableOrder && priorUsingDirective == null)
|
||||||
|
{
|
||||||
|
acceptableOrder = true;
|
||||||
|
}
|
||||||
|
if (!acceptableOrder && string.Compare(priorUsingDirective.Name.ToString(), usingDirective.Name.ToString(), StringComparison.OrdinalIgnoreCase) < 0)
|
||||||
|
{
|
||||||
|
acceptableOrder = true;
|
||||||
|
}
|
||||||
|
if (!acceptableOrder &&
|
||||||
|
priorUsingDirective.Name.ToString().StartsWith("System.") &&
|
||||||
|
!usingDirective.Name.ToString().StartsWith("System."))
|
||||||
|
{
|
||||||
|
acceptableOrder = true;
|
||||||
|
}
|
||||||
|
if (!acceptableOrder)
|
||||||
|
{
|
||||||
|
diagnostics.Add(Diagnostic.Create(
|
||||||
|
"SP1004", "StandardsPolice", "namespaces not alphabetized",
|
||||||
|
DiagnosticSeverity.Warning,
|
||||||
|
DiagnosticSeverity.Warning,
|
||||||
|
false,
|
||||||
|
3,
|
||||||
|
location: usingDirective.GetLocation()));
|
||||||
|
}
|
||||||
|
priorUsingDirective = usingDirective;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ScanNamespace(IList<Diagnostic> diagnostics, INamespaceSymbol namespaceSymbol)
|
private static void ScanNamespace(IList<Diagnostic> diagnostics, INamespaceSymbol namespaceSymbol)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue