private static void AnalyzeOperation(SyntaxNodeAnalysisContext context) { var usingDirective = context.Node; var allNodes = usingDirective.Parent.ChildNodes().ToList(); if (allNodes.Last() == usingDirective) { return; } var nextNode = allNodes[allNodes.IndexOf(usingDirective) + 1]; if (AnalyzerUtility.CheckIfHaveEmptyStringBefore(nextNode)) { return; } var countOfUsingsAfter = allNodes.Count(node => node.Kind() == SyntaxKind.UsingDirective && node != usingDirective && allNodes.IndexOf(node) > allNodes.IndexOf(usingDirective)); if (countOfUsingsAfter == 0) { context.ReportDiagnostic(Diagnostic.Create(_rule, usingDirective.GetLocation(), usingDirective)); } }
private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { var node = context.Node; if (AnalyzerUtility.CheckIfHaveEmptyStringBefore(node) || AnalyzerUtility.CheckIfNodeFirstInBlock(node)) { return; } if (node.Ancestors().Any(ancestor => ancestor.Kind() == SyntaxKind.SwitchSection)) { return; } context.ReportDiagnostic(Diagnostic.Create(_rule, node.GetLocation(), node.Kind())); }