Skip to content

Commit d6424c2

Browse files
committed
Add custom file header fix all provider
1 parent 7116802 commit d6424c2

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal class FileHeaderCodeFixProvider : CodeFixProvider
4747
/// <inheritdoc/>
4848
public override FixAllProvider GetFixAllProvider()
4949
{
50-
return CustomFixAllProviders.BatchFixer;
50+
return FixAll.Instance;
5151
}
5252

5353
/// <inheritdoc/>
@@ -67,6 +67,11 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
6767
}
6868

6969
private static async Task<Document> GetTransformedDocumentAsync(Document document, CancellationToken cancellationToken)
70+
{
71+
return document.WithSyntaxRoot(await GetTransformedSyntaxRootAsync(document, cancellationToken).ConfigureAwait(false));
72+
}
73+
74+
private static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(Document document, CancellationToken cancellationToken)
7075
{
7176
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
7277
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
@@ -96,7 +101,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
96101
}
97102
}
98103

99-
return document.WithSyntaxRoot(newSyntaxRoot);
104+
return newSyntaxRoot;
100105
}
101106

102107
private static SyntaxNode ReplaceWellFormedMultiLineCommentHeader(Document document, SyntaxNode root, StyleCopSettings settings, int commentIndex, XmlFileHeader header)
@@ -460,5 +465,22 @@ private static SyntaxTriviaList RemoveHeaderDecorationLines(SyntaxTriviaList tri
460465

461466
return trivia;
462467
}
468+
469+
private class FixAll : DocumentBasedFixAllProvider
470+
{
471+
public static FixAllProvider Instance { get; } = new FixAll();
472+
473+
protected override string CodeActionTitle => DocumentationResources.SA1633CodeFix;
474+
475+
protected override Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
476+
{
477+
if (diagnostics.IsEmpty)
478+
{
479+
return null;
480+
}
481+
482+
return GetTransformedSyntaxRootAsync(document, fixAllContext.CancellationToken);
483+
}
484+
}
463485
}
464486
}

0 commit comments

Comments
 (0)