Skip to content

Commit fc44991

Browse files
committed
Merge branch 'master' into bugfix/3279-handle-optional-named-args-correctly
2 parents 3c09a6a + fdb3d67 commit fc44991

27 files changed

Lines changed: 656 additions & 57 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1141CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
7777
break;
7878
}
7979

80-
var newSyntaxRoot = syntaxRoot.ReplaceNode(node, newNode).WithAdditionalAnnotations(Simplifier.Annotation);
80+
var newSyntaxRoot = syntaxRoot.ReplaceNode(node, newNode.WithAdditionalAnnotations(Simplifier.Annotation));
8181
return document.WithSyntaxRoot(newSyntaxRoot.WithoutFormatting());
8282
}
8383

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/ReadabilityRules/SA1141CSharp7UnitTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,49 @@ public void TestMethod()
182182
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
183183
}
184184

185+
/// <summary>
186+
/// Validates that the usage of <see cref="System.ValueTuple"/> within LINQ expression trees will produce no
187+
/// diagnostics.
188+
/// </summary>
189+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
190+
[Fact]
191+
[WorkItem(3305, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3305")]
192+
public async Task ValidateValueTupleUsageInExpressionTreeAsync()
193+
{
194+
var testCode = @"using System;
195+
using System.Linq.Expressions;
196+
197+
public class TestClass
198+
{
199+
Expression<Func<(int, int)>> expression1 = () => ValueTuple.Create(10, 20);
200+
Expression<Func<(int, int)>> expression2 = () => new ValueTuple<int, int>(10, 20);
201+
Expression<Func<((int, int), int)>> expression3 = () => new ValueTuple<ValueTuple<int, int>, int>(ValueTuple.Create(10, 10), 20);
202+
Expression<Func<(int, int)>> expression4 = () => new System.ValueTuple<int, int>(10, 20);
203+
Expression<Func<(int, int), (int, int)>> expression5 = arg => new System.ValueTuple<int, int>(arg.Item1, arg.Item2);
204+
Expression<Func<(int, int), (int, int)>> expression6 = (arg) => new System.ValueTuple<int, int>(arg.Item1, arg.Item2);
205+
206+
Expression<Func<[|ValueTuple<int, int>|], [|ValueTuple<int, int>|]>> expression7 = ([|ValueTuple<int, int>|] arg) => ValueTuple.Create(arg.Item1, arg.Item2);
207+
}
208+
";
209+
var fixedCode = @"using System;
210+
using System.Linq.Expressions;
211+
212+
public class TestClass
213+
{
214+
Expression<Func<(int, int)>> expression1 = () => ValueTuple.Create(10, 20);
215+
Expression<Func<(int, int)>> expression2 = () => new ValueTuple<int, int>(10, 20);
216+
Expression<Func<((int, int), int)>> expression3 = () => new ValueTuple<ValueTuple<int, int>, int>(ValueTuple.Create(10, 10), 20);
217+
Expression<Func<(int, int)>> expression4 = () => new System.ValueTuple<int, int>(10, 20);
218+
Expression<Func<(int, int), (int, int)>> expression5 = arg => new System.ValueTuple<int, int>(arg.Item1, arg.Item2);
219+
Expression<Func<(int, int), (int, int)>> expression6 = (arg) => new System.ValueTuple<int, int>(arg.Item1, arg.Item2);
220+
221+
Expression<Func<(int, int), (int, int)>> expression7 = ((int, int) arg) => ValueTuple.Create(arg.Item1, arg.Item2);
222+
}
223+
";
224+
225+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
226+
}
227+
185228
/// <summary>
186229
/// Validates that the usage of <see cref="System.ValueTuple"/> within pattern matching will produce no diagnostics.
187230
/// </summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1015CSharp8UnitTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly,
13+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
714

815
public class SA1015CSharp8UnitTests : SA1015CSharp7UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")]
19+
public async Task TestGenericTypePointerAsync()
20+
{
21+
const string testCode = @"using System;
22+
23+
public struct Foo<T>
24+
{
25+
internal unsafe Foo<T [|>|] * Next1;
26+
internal unsafe Foo<T [|>|]* Next2;
27+
}";
28+
const string fixedCode = @"using System;
29+
30+
public struct Foo<T>
31+
{
32+
internal unsafe Foo<T> * Next1;
33+
internal unsafe Foo<T>* Next2;
34+
}";
35+
36+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
37+
}
1038
}
1139
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1023CSharp8UnitTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,39 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly,
13+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
714

815
public class SA1023CSharp8UnitTests : SA1023CSharp7UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")]
19+
public async Task TestGenericTypePointerAsync()
20+
{
21+
const string testCode = @"using System;
22+
23+
public struct Foo<T>
24+
{
25+
internal unsafe Foo<T> [|*|] Next1;
26+
internal unsafe Foo<T>[|*|]Next2;
27+
internal unsafe Foo<T> [|[|*|]|]Next3;
28+
}";
29+
const string fixedCode = @"using System;
30+
31+
public struct Foo<T>
32+
{
33+
internal unsafe Foo<T>* Next1;
34+
internal unsafe Foo<T>* Next2;
35+
internal unsafe Foo<T>* Next3;
36+
}";
37+
38+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
39+
}
1040
}
1141
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1118CSharp9UnitTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,77 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.CSharp;
9+
using Microsoft.CodeAnalysis.Testing;
610
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
11+
using Xunit;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<StyleCop.Analyzers.ReadabilityRules.SA1118ParameterMustNotSpanMultipleLines>;
713

814
public class SA1118CSharp9UnitTests : SA1118CSharp8UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3314, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3314")]
18+
public async Task TestWithExpressionAsync()
19+
{
20+
var testCode = @"
21+
class Foo
22+
{
23+
public record R(int X, int Y);
24+
25+
public void FunA(params object[] j)
26+
{
27+
}
28+
29+
public void FunB(R r)
30+
{
31+
FunA(
32+
1,
33+
r with
34+
{
35+
X = 1,
36+
});
37+
}
38+
}";
39+
40+
await new CSharpTest(LanguageVersion.CSharp9)
41+
{
42+
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
43+
TestCode = testCode,
44+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
45+
}
46+
47+
[Fact]
48+
[WorkItem(3314, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3314")]
49+
public async Task TestWithExpression2Async()
50+
{
51+
var testCode = @"
52+
class Foo
53+
{
54+
public record R(int X, int Y);
55+
56+
public void FunA(params object[] j)
57+
{
58+
}
59+
60+
public void FunB(R r)
61+
{
62+
FunA(
63+
1,
64+
r with
65+
{
66+
X = 1,
67+
},
68+
2);
69+
}
70+
}";
71+
72+
await new CSharpTest(LanguageVersion.CSharp9)
73+
{
74+
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
75+
TestCode = testCode,
76+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
77+
}
1078
}
1179
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ public class ClassName
185185
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
186186
}
187187

188+
[Fact]
189+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
190+
public async Task TestClassWithIncludedMissingDocumentationAsync()
191+
{
192+
var testCode = @"
193+
/// <include file='MissingFile.xml' path='/ClassName/*' />
194+
public class ClassName
195+
{
196+
}";
197+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
198+
}
199+
188200
[Fact]
189201
public async Task TestClassWithIncludedSummaryDocumentationAsync()
190202
{
@@ -210,6 +222,35 @@ public class ClassName
210222
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
211223
}
212224

225+
[Fact]
226+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
227+
public async Task TestFieldWithIncludedSummaryDocumentationAsync()
228+
{
229+
var testCode = @"
230+
public class ClassName
231+
{
232+
/// <include file='FieldWithSummary.xml' path='/FieldName/*' />
233+
public int FieldName;
234+
}";
235+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
236+
}
237+
238+
[Fact]
239+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
240+
public async Task TestFieldWithIncludedDefaultSummaryDocumentationAsync()
241+
{
242+
var testCode = @"
243+
public class ClassName
244+
{
245+
/// <include file='FieldWithDefaultSummary.xml' path='/FieldName/*' />
246+
public {|#0:int FieldName|};
247+
}";
248+
249+
DiagnosticResult expected = Diagnostic().WithLocation(0);
250+
251+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
252+
}
253+
213254
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken)
214255
=> VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken);
215256

@@ -232,6 +273,20 @@ private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[
232273
Summary description for the ClassName class.
233274
</summary>
234275
</ClassName>
276+
";
277+
string fieldContentWithSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
278+
<FieldName>
279+
<summary>
280+
Foo
281+
</summary>
282+
</FieldName>
283+
";
284+
string fieldContentWithDefaultSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
285+
<FieldName>
286+
<summary>
287+
Summary description for the ClassName class.
288+
</summary>
289+
</FieldName>
235290
";
236291

237292
var test = new StyleCopDiagnosticVerifier<SA1608ElementDocumentationMustNotHaveDefaultSummary>.CSharpTest
@@ -242,6 +297,8 @@ private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[
242297
{ "ClassWithoutSummary.xml", contentWithoutSummary },
243298
{ "ClassWithSummary.xml", contentWithSummary },
244299
{ "ClassWithDefaultSummary.xml", contentWithDefaultSummary },
300+
{ "FieldWithSummary.xml", fieldContentWithSummary },
301+
{ "FieldWithDefaultSummary.xml", fieldContentWithDefaultSummary },
245302
},
246303
};
247304

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,36 @@ public void TestMethod(string param1, string param2, string param3)
312312
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
313313
}
314314

315+
/// <summary>
316+
/// Verifies that included documentation with missing documentation file produces no diagnostics.
317+
/// </summary>
318+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
319+
[Fact]
320+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
321+
public async Task VerifyIncludedMissingDocumentationAsync()
322+
{
323+
var testCode = @"
324+
/// <summary>
325+
/// Foo
326+
/// </summary>
327+
public class ClassName
328+
{
329+
/// <include file='MissingFile.xml' path='/TestClass/TestMethod/*' />
330+
public void TestMethod(string {|#0:param1|}, string {|#1:param2|}, string {|#2:param3|})
331+
{
332+
}
333+
}";
334+
335+
DiagnosticResult[] expected =
336+
{
337+
Diagnostic().WithLocation(0).WithArguments("param1"),
338+
Diagnostic().WithLocation(1).WithArguments("param2"),
339+
Diagnostic().WithLocation(2).WithArguments("param3"),
340+
};
341+
342+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
343+
}
344+
315345
/// <summary>
316346
/// Verifies that included documentation with missing elements documented produces the expected diagnostics.
317347
/// </summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ public class ClassName
285285
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
286286
}
287287

288+
[Fact]
289+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
290+
public async Task VerifyIncludedMissingFileIsNotReportedAsync()
291+
{
292+
var testCode = @"
293+
/// <summary>
294+
/// Foo
295+
/// </summary>
296+
public class ClassName
297+
{
298+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
299+
public ClassName Method() { return null; }
300+
}";
301+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
302+
}
303+
288304
[Fact]
289305
public async Task VerifyIncludedMemberWithValidParamsIsNotReportedAsync()
290306
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ public class ClassName
154154
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
155155
}
156156

157+
[Fact]
158+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
159+
public async Task VerifyIncludedMissingFileAsync()
160+
{
161+
var testCode = @"
162+
/// <summary>
163+
/// Foo
164+
/// </summary>
165+
public class ClassName
166+
{
167+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
168+
public ClassName Method(string foo, string bar) { return null; }
169+
}";
170+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
171+
}
172+
157173
[Fact]
158174
public async Task VerifyMemberWithValidParamsAndIncludedDocumentationAsync()
159175
{

0 commit comments

Comments
 (0)