Skip to content

Commit 6d421c2

Browse files
Code review update: Updated SA1402CodeFixProvider to use FileNameHelpers for getting the file name for the new document.
1 parent db2de9b commit 6d421c2

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1402CodeFixProvider.cs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ private static async Task<Solution> GetTransformedSolutionAsync(Document documen
6363
}
6464

6565
DocumentId extractedDocumentId = DocumentId.CreateNewId(document.Project.Id);
66-
var extractedDocumentName = GetExtractedDocumentName(memberDeclarationSyntax) + ".cs";
66+
string suffix;
67+
FileNameHelpers.GetFileNameAndSuffix(document.Name, out suffix);
68+
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
69+
string extractedDocumentName = FileNameHelpers.GetConventionalFileName(memberDeclarationSyntax, settings.DocumentationRules.FileNamingConvention) + suffix;
6770

6871
List<SyntaxNode> nodesToRemoveFromExtracted = new List<SyntaxNode>();
6972
SyntaxNode previous = node;
@@ -93,8 +96,8 @@ private static async Task<Solution> GetTransformedSolutionAsync(Document documen
9396
}
9497
}
9598

99+
// Add the new file
96100
SyntaxNode extractedDocumentNode = root.RemoveNodes(nodesToRemoveFromExtracted, SyntaxRemoveOptions.KeepUnbalancedDirectives);
97-
98101
Solution updatedSolution = document.Project.Solution.AddDocument(extractedDocumentId, extractedDocumentName, extractedDocumentNode, document.Folders);
99102

100103
// Make sure to also add the file to linked projects
@@ -109,30 +112,5 @@ private static async Task<Solution> GetTransformedSolutionAsync(Document documen
109112

110113
return updatedSolution;
111114
}
112-
113-
private static string GetExtractedDocumentName(MemberDeclarationSyntax memberDeclarationSyntax)
114-
{
115-
string extractedDocumentName = NamedTypeHelpers.GetNameOrIdentifier(memberDeclarationSyntax);
116-
117-
var typeDeclarationSyntax = memberDeclarationSyntax as TypeDeclarationSyntax;
118-
var delegateDeclarationSyntax = memberDeclarationSyntax as DelegateDeclarationSyntax;
119-
120-
if (typeDeclarationSyntax != null)
121-
{
122-
if (typeDeclarationSyntax.TypeParameterList?.Parameters.Count > 0)
123-
{
124-
extractedDocumentName += "`" + typeDeclarationSyntax.TypeParameterList.Parameters.Count;
125-
}
126-
}
127-
else if (delegateDeclarationSyntax != null)
128-
{
129-
if (delegateDeclarationSyntax.TypeParameterList?.Parameters.Count > 0)
130-
{
131-
extractedDocumentName += "`" + delegateDeclarationSyntax.TypeParameterList.Parameters.Count;
132-
}
133-
}
134-
135-
return extractedDocumentName;
136-
}
137115
}
138116
}

0 commit comments

Comments
 (0)