Skip to content

Commit 17afb7b

Browse files
committed
Address code review feedback
1 parent 9bff5a2 commit 17afb7b

File tree

9 files changed

+41
-98
lines changed

9 files changed

+41
-98
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForClassCSharp11UnitTests.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForClassCSharp11UnitTests : SA1402ForClassCSharp10Uni
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalClassExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public class TestClass1 {{ }}
24+
public class TestClass1 { }
2625
27-
file class TestClass2 {{ }}
26+
file class TestClass2 { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831

3932
/// <summary>
@@ -44,20 +37,14 @@ await this.VerifyCSharpDiagnosticAsync(
4437
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
4538
public async Task VerifyFileLocalStaticClassExemptionAsync()
4639
{
47-
var testCode = $@"namespace TestNamespace;
40+
var testCode = @"namespace TestNamespace;
4841
49-
public class TestClass1 {{ }}
42+
public class TestClass1 { }
5043
51-
file static class TestClass2 {{ }}
44+
file static class TestClass2 { }
5245
";
5346

54-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
55-
56-
await this.VerifyCSharpDiagnosticAsync(
57-
testCode,
58-
this.GetSettings(),
59-
Array.Empty<DiagnosticResult>(),
60-
CancellationToken.None).ConfigureAwait(false);
47+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
6148
}
6249
}
6350
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForDelegateCSharp11UnitTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForDelegateCSharp11UnitTests : SA1402ForDelegateCShar
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalDelegateExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public class TestClass {{ }}
24+
public class TestClass { }
2625
2726
file delegate void TestDelegate();
2827
";
2928

30-
var expectedDiagnostic = Diagnostic().WithLocation(0);
31-
32-
await VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForEnumCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForEnumCSharp11UnitTests : SA1402ForEnumCSharp10UnitT
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalEnumExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public class TestClass1 {{ }}
24+
public class TestClass1 { }
2625
27-
file enum TestEnum {{ }}
26+
file enum TestEnum { }
2827
";
2928

30-
var expectedDiagnostic = Diagnostic().WithLocation(0);
31-
32-
await VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForInterfaceCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForInterfaceCSharp11UnitTests : SA1402ForInterfaceCSh
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalInterfaceExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public interface TestInterface1 {{ }}
24+
public interface TestInterface1 { }
2625
27-
file interface TestInterface2 {{ }}
26+
file interface TestInterface2 { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForRecordCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForRecordCSharp11UnitTests : SA1402ForRecordCSharp10U
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalRecordExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public record TestRecord1 {{ }}
24+
public record TestRecord1 { }
2625
27-
file record TestRecord2 {{ }}
26+
file record TestRecord2 { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForRecordClassCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForRecordClassCSharp11UnitTests : SA1402ForRecordClas
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalRecordClassExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public class TestClass {{ }}
24+
public class TestClass { }
2625
27-
file record class TestRecordClass {{ }}
26+
file record class TestRecordClass { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForRecordStructCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForRecordStructCSharp11UnitTests : SA1402ForRecordStr
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalRecordStructExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public class TestClass {{ }}
24+
public class TestClass { }
2625
27-
file record struct TestRecordStruct {{ }}
26+
file record struct TestRecordStruct { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1402ForStructCSharp11UnitTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
55
{
6-
using System;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
@@ -20,20 +19,14 @@ public partial class SA1402ForStructCSharp11UnitTests : SA1402ForStructCSharp10U
2019
[WorkItem(3803, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3803")]
2120
public async Task VerifyFileLocalStructExemptionAsync()
2221
{
23-
var testCode = $@"namespace TestNamespace;
22+
var testCode = @"namespace TestNamespace;
2423
25-
public struct TestStruct1 {{ }}
24+
public struct TestStruct1 { }
2625
27-
file struct TestStruct2 {{ }}
26+
file struct TestStruct2 { }
2827
";
2928

30-
var expectedDiagnostic = this.Diagnostic().WithLocation(0);
31-
32-
await this.VerifyCSharpDiagnosticAsync(
33-
testCode,
34-
this.GetSettings(),
35-
Array.Empty<DiagnosticResult>(),
36-
CancellationToken.None).ConfigureAwait(false);
29+
await this.VerifyCSharpDiagnosticAsync(testCode, this.GetSettings(), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3730
}
3831
}
3932
}

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1402FileMayOnlyContainASingleType.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCop
9999
private static IEnumerable<MemberDeclarationSyntax> GetTopLevelTypeDeclarations(SyntaxNode root, StyleCopSettings settings)
100100
{
101101
var allTypeDeclarations = root.DescendantNodes(descendIntoChildren: node => ContainsTopLevelTypeDeclarations(node)).OfType<MemberDeclarationSyntax>().ToList();
102-
var relevantTypeDeclarations = allTypeDeclarations.Where(x => IsRelevantType(x, settings)).Where(x => !IsFileLocalType(x)).ToList();
102+
var relevantTypeDeclarations = allTypeDeclarations.Where(x => IsRelevantType(x, settings)).ToList();
103103
return relevantTypeDeclarations;
104104
}
105105

@@ -110,6 +110,11 @@ private static bool ContainsTopLevelTypeDeclarations(SyntaxNode node)
110110

111111
private static bool IsRelevantType(SyntaxNode node, StyleCopSettings settings)
112112
{
113+
if (IsFileLocalType(node))
114+
{
115+
return false;
116+
}
117+
113118
var topLevelTypes = settings.MaintainabilityRules.TopLevelTypes;
114119
var isRelevant = false;
115120

0 commit comments

Comments
 (0)