Skip to content

Commit 6c0e725

Browse files
committed
Fix that SA1649 does not support simple names
1 parent 8831b09 commit 6c0e725

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1649UnitTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public async Task VerifyStyleCopNamingConventionForGenericTypeAsync(string typeK
169169

170170
var expectedDiagnostic = this.CSharpDiagnostic().WithLocation("TestType`3.cs", 3, 13 + typeKeyword.Length);
171171
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None, "TestType`3.cs").ConfigureAwait(false);
172+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, "TestType.cs").ConfigureAwait(false);
172173
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, "TestType{T1,T2,T3}.cs").ConfigureAwait(false);
173174
await this.VerifyRenameAsync(testCode, "TestType{T1,T2,T3}.cs", CancellationToken.None).ConfigureAwait(false);
174175
}
@@ -194,6 +195,9 @@ public async Task VerifyMetadataNamingConventionForGenericTypeAsync(string typeK
194195

195196
var expectedDiagnostic = this.CSharpDiagnostic().WithLocation("TestType{T1,T2,T3}.cs", 3, 13 + typeKeyword.Length);
196197
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None, "TestType{T1,T2,T3}.cs").ConfigureAwait(false);
198+
199+
expectedDiagnostic = this.CSharpDiagnostic().WithLocation("TestType.cs", 3, 13 + typeKeyword.Length);
200+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None, "TestType.cs").ConfigureAwait(false);
197201
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, "TestType`3.cs").ConfigureAwait(false);
198202
await this.VerifyRenameAsync(testCode, "TestType`3.cs", CancellationToken.None).ConfigureAwait(false);
199203
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1649FileNameMustMatchTypeName.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public void HandleSyntaxTreeAction(SyntaxTreeAnalysisContext context)
9898

9999
if (string.Compare(fileName, expectedFileName, StringComparison.OrdinalIgnoreCase) != 0)
100100
{
101+
if (this.fileNamingConvention == FileNamingConvention.StyleCop
102+
&& string.Compare(fileName, GetSimpleFileName(firstTypeDeclaration), StringComparison.OrdinalIgnoreCase) == 0)
103+
{
104+
return;
105+
}
106+
101107
var properties = ImmutableDictionary.Create<string, string>()
102108
.Add(ExpectedFileNameKey, expectedFileName);
103109

@@ -123,6 +129,11 @@ private static string GetStyleCopFileName(TypeDeclarationSyntax firstTypeDeclara
123129
return $"{firstTypeDeclaration.Identifier.ValueText}{{{typeParameterList}}}.cs";
124130
}
125131

132+
private static string GetSimpleFileName(TypeDeclarationSyntax firstTypeDeclaration)
133+
{
134+
return $"{firstTypeDeclaration.Identifier.ValueText}.cs";
135+
}
136+
126137
private static string GetMetadataFileName(TypeDeclarationSyntax firstTypeDeclaration)
127138
{
128139
if (firstTypeDeclaration.TypeParameterList == null)

0 commit comments

Comments
 (0)