Skip to content

Commit d180895

Browse files
authored
Merge pull request #2394 from sharwell/csharp7-maintainability
Update maintainability rules for C# 7
2 parents 9f460c3 + fa031e1 commit d180895

21 files changed

Lines changed: 355 additions & 5 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using StyleCop.Analyzers.Test.MaintainabilityRules;
9+
using TestHelper;
10+
using Xunit;
11+
12+
public class SA1119CSharp7UnitTests : SA1119UnitTests
13+
{
14+
/// <summary>
15+
/// Verifies that extra parentheses in pattern matching are reported.
16+
/// </summary>
17+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
18+
/// <seealso cref="SA1408CSharp7UnitTests.TestPatternMatchingAsync"/>
19+
[Fact]
20+
public async Task TestPatternMatchingAsync()
21+
{
22+
var testCode = @"public class Foo
23+
{
24+
public void Bar()
25+
{
26+
if ((new object() is bool b) && b)
27+
{
28+
return;
29+
}
30+
}
31+
}";
32+
var fixedCode = @"public class Foo
33+
{
34+
public void Bar()
35+
{
36+
if ( new object() is bool b && b)
37+
{
38+
return;
39+
}
40+
}
41+
}";
42+
43+
DiagnosticResult[] expected =
44+
{
45+
this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 13),
46+
this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 13),
47+
this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 36),
48+
};
49+
50+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
51+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
52+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
53+
}
54+
55+
[Fact]
56+
public async Task TestTupleDeconstructionAsync()
57+
{
58+
var testCode = @"public class Foo
59+
{
60+
public void Bar()
61+
{
62+
var (a, (b, c), d) = (1, (2, (3)), 4);
63+
}
64+
}";
65+
var fixedCode = @"public class Foo
66+
{
67+
public void Bar()
68+
{
69+
var (a, (b, c), d) = (1, (2, 3), 4);
70+
}
71+
}";
72+
73+
DiagnosticResult[] expected =
74+
{
75+
this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 38),
76+
this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 38),
77+
this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 40),
78+
};
79+
80+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
81+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
82+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
83+
}
84+
}
85+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using StyleCop.Analyzers.Test.MaintainabilityRules;
9+
using Xunit;
10+
11+
public class SA1400CSharp7UnitTests : SA1400UnitTests
12+
{
13+
/// <summary>
14+
/// Verifies that local functions, which do not support access modifiers, do not trigger SA1400.
15+
/// </summary>
16+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
17+
[Fact]
18+
public async Task TestLocalFunctionAsync()
19+
{
20+
var testCode = @"
21+
internal class ClassName
22+
{
23+
public void MethodName()
24+
{
25+
void LocalFunction()
26+
{
27+
}
28+
}
29+
}
30+
";
31+
32+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
33+
}
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1401CSharp7UnitTests : SA1401UnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1402CSharp7ForClassUnitTests : SA1402ForClassUnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1402CSharp7ForDelegateUnitTests : SA1402ForDelegateUnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1402CSharp7ForEnumUnitTests : SA1402ForEnumUnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1402CSharp7ForInterfaceUnitTests : SA1402ForInterfaceUnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1402CSharp7ForStructUnitTests : SA1402ForStructUnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1403CSharp7UnitTests : SA1403UnitTests
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.MaintainabilityRules;
7+
8+
public class SA1404CSharp7UnitTests : SA1404UnitTests
9+
{
10+
}
11+
}

0 commit comments

Comments
 (0)