diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index c9bcc64c11..49e777c59c 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; +using Microsoft.AspNet.Server.Kestrel.Networking; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs index d42bba4663..0961eed061 100644 --- a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -49,6 +49,41 @@ namespace Microsoft.StandardsPolice location: typeDeclaration.GetLocation())); } } + + var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) + .OfType() + .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 diagnostics, INamespaceSymbol namespaceSymbol)