Skip to content

Commit ee1bb96

Browse files
committed
Processed review comments
1 parent 6285950 commit ee1bb96

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5151
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5252
{
5353
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
54-
var violatingAttribute = (AttributeSyntax)syntaxRoot.FindNode(diagnostic.Location.SourceSpan);
54+
var violatingAttribute = (AttributeSyntax)syntaxRoot.FindNode(diagnostic.Location.SourceSpan).Parent;
5555
var attributeList = (AttributeListSyntax)violatingAttribute.Parent;
5656
var newAttributeLists = new List<AttributeListSyntax>();
5757

@@ -61,7 +61,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
6161

6262
for (var i = 0; i < attributeList.Attributes.Count; i++)
6363
{
64-
var newAttributes = SyntaxFactory.SeparatedList(new[] { attributeList.Attributes[i] });
64+
var newAttributes = SyntaxFactory.SingletonSeparatedList(attributeList.Attributes[i]);
6565
var newAttributeList = SyntaxFactory.AttributeList(attributeList.Target, newAttributes);
6666

6767
newAttributeList = (i == 0)

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1133UnitTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,69 @@ public void TestMethod()
103103
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
104104
}
105105

106+
/// <summary>
107+
/// Verifies that multiple attribute list are handled correctly.
108+
/// </summary>
109+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
110+
[Fact]
111+
public async Task VerifyThatMultipleAttributeListsAreHandledCorrectlyAsync()
112+
{
113+
var testCode = @"using System.ComponentModel;
114+
115+
[EditorBrowsable(EditorBrowsableState.Never), DesignOnly(true)]
116+
#if false
117+
[DataObject(true), Browsable(true)]
118+
#else
119+
[DataObject(true), Browsable(false)]
120+
#endif
121+
public class TestClass
122+
{
123+
/// <summary>
124+
/// Test method.
125+
/// </summary>
126+
[EditorBrowsable(EditorBrowsableState.Never), DesignOnly(true), DisplayName(""Test"")] // test comment
127+
public void TestMethod()
128+
{
129+
}
130+
}
131+
";
132+
133+
var fixedTestCode = @"using System.ComponentModel;
134+
135+
[EditorBrowsable(EditorBrowsableState.Never)]
136+
[DesignOnly(true)]
137+
#if false
138+
[DataObject(true), Browsable(true)]
139+
#else
140+
[DataObject(true)]
141+
[Browsable(false)]
142+
#endif
143+
public class TestClass
144+
{
145+
/// <summary>
146+
/// Test method.
147+
/// </summary>
148+
[EditorBrowsable(EditorBrowsableState.Never)]
149+
[DesignOnly(true)]
150+
[DisplayName(""Test"")] // test comment
151+
public void TestMethod()
152+
{
153+
}
154+
}
155+
";
156+
157+
DiagnosticResult[] expected =
158+
{
159+
this.CSharpDiagnostic().WithLocation(3, 47),
160+
this.CSharpDiagnostic().WithLocation(7, 20),
161+
this.CSharpDiagnostic().WithLocation(14, 51)
162+
};
163+
164+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
165+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
166+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
167+
}
168+
106169
/// <inheritdoc/>
107170
protected override CodeFixProvider GetCSharpCodeFixProvider()
108171
{

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1133DoNotCombineAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static void HandleAttributeList(SyntaxNodeAnalysisContext context)
5252

5353
if (attributeList.Attributes.Count > 1)
5454
{
55-
context.ReportDiagnostic(Diagnostic.Create(Descriptor, attributeList.Attributes[1].GetLocation()));
55+
context.ReportDiagnostic(Diagnostic.Create(Descriptor, attributeList.Attributes[1].Name.GetLocation()));
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)