Skip to content

Commit 972c393

Browse files
committed
CR: In SA1133 use getInnermostNodeForTie:true and then call FirstAncestorOrSelf() on the found node
1 parent 67983c5 commit 972c393

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1133CodeFixProvider.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,8 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5555
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5656
{
5757
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
58-
var nodeInSourceSpan = syntaxRoot.FindNode(diagnostic.Location.SourceSpan);
59-
AttributeListSyntax attributeList;
60-
if (nodeInSourceSpan.Parent is AttributeListSyntax)
61-
{
62-
attributeList = (AttributeListSyntax)nodeInSourceSpan.Parent;
63-
}
64-
else if (nodeInSourceSpan.Parent is AttributeSyntax)
65-
{
66-
var violatingAttribute = (AttributeSyntax)nodeInSourceSpan.Parent;
67-
attributeList = (AttributeListSyntax)violatingAttribute.Parent;
68-
}
69-
else
70-
{
71-
return document;
72-
}
58+
var nodeInSourceSpan = syntaxRoot.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true);
59+
AttributeListSyntax attributeList = nodeInSourceSpan.FirstAncestorOrSelf<AttributeListSyntax>();
7360

7461
var newAttributeLists = new List<AttributeListSyntax>();
7562

0 commit comments

Comments
 (0)