Skip to content

Commit 2fbc3a2

Browse files
committed
Implement code review feedback
1 parent 051dd50 commit 2fbc3a2

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FixAllContextHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,32 @@ public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Comp
143143

144144
// Note that the following loop to obtain syntax and semantic diagnostics for each document cannot operate
145145
// on parallel due to our use of a single CompilationWithAnalyzers instance.
146-
var diagnostics = ImmutableArray<Diagnostic>.Empty;
146+
var diagnostics = ImmutableArray.CreateBuilder<Diagnostic>();
147147
foreach (var document in documents)
148148
{
149149
var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
150150
var syntaxDiagnostics = await GetAnalyzerSyntaxDiagnosticsAsync(compilationWithAnalyzers, syntaxTree, cancellationToken).ConfigureAwait(false);
151-
diagnostics = diagnostics.AddRange(syntaxDiagnostics);
151+
diagnostics.AddRange(syntaxDiagnostics);
152152

153153
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
154154
var semanticDiagnostics = await GetAnalyzerSemanticDiagnosticsAsync(compilationWithAnalyzers, semanticModel, default(TextSpan?), cancellationToken).ConfigureAwait(false);
155-
diagnostics = diagnostics.AddRange(semanticDiagnostics);
155+
diagnostics.AddRange(semanticDiagnostics);
156156
}
157157

158158
foreach (var analyzer in analyzers)
159159
{
160-
diagnostics = diagnostics.AddRange(await GetAnalyzerCompilationDiagnosticsAsync(compilationWithAnalyzers, ImmutableArray.Create(analyzer), cancellationToken).ConfigureAwait(false));
160+
diagnostics.AddRange(await GetAnalyzerCompilationDiagnosticsAsync(compilationWithAnalyzers, ImmutableArray.Create(analyzer), cancellationToken).ConfigureAwait(false));
161161
}
162162

163163
if (includeCompilerDiagnostics)
164164
{
165165
// This is the special handling for cases where code fixes operate on warnings produced by the C#
166166
// compiler, as opposed to being created by specific analyzers.
167167
var compilerDiagnostics = compilation.GetDiagnostics(cancellationToken);
168-
diagnostics = diagnostics.AddRange(compilerDiagnostics);
168+
diagnostics.AddRange(compilerDiagnostics);
169169
}
170170

171-
return diagnostics;
171+
return diagnostics.ToImmutable();
172172
}
173173

174174
private static ImmutableDictionary<string, ImmutableArray<Type>> GetAllAnalyzers()

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1412FixAllProvider.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ public override Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
2424
case FixAllScope.Document:
2525
fixAction = CodeAction.Create(
2626
title,
27-
cancellationToken => this.GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
27+
cancellationToken => GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
2828
nameof(SA1412FixAllProvider));
2929
break;
3030

3131
case FixAllScope.Project:
3232
fixAction = CodeAction.Create(
3333
title,
34-
cancellationToken => this.GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken), fixAllContext.Project),
34+
cancellationToken => GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
3535
nameof(SA1412FixAllProvider));
3636
break;
3737

3838
case FixAllScope.Solution:
3939
fixAction = CodeAction.Create(
4040
title,
41-
cancellationToken => this.GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
41+
cancellationToken => GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
4242
nameof(SA1412FixAllProvider));
4343
break;
4444

@@ -68,7 +68,7 @@ private static async Task<Solution> FixDocumentAsync(Solution solution, Document
6868
return await SA1412CodeFixProvider.GetTransformedSolutionAsync(document, cancellationToken).ConfigureAwait(false);
6969
}
7070

71-
private async Task<Solution> GetDocumentFixesAsync(FixAllContext fixAllContext)
71+
private static async Task<Solution> GetDocumentFixesAsync(FixAllContext fixAllContext)
7272
{
7373
var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
7474
ImmutableArray<Diagnostic> diagnostics;
@@ -80,7 +80,7 @@ private async Task<Solution> GetDocumentFixesAsync(FixAllContext fixAllContext)
8080
return await FixDocumentAsync(fixAllContext.Document.Project.Solution, fixAllContext.Document.Id, diagnostics, fixAllContext.CodeActionEquivalenceKey, fixAllContext.CancellationToken).ConfigureAwait(false);
8181
}
8282

83-
private async Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray<Document> documents)
83+
private static async Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray<Document> documents)
8484
{
8585
var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext).ConfigureAwait(false);
8686

@@ -99,15 +99,15 @@ private async Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext,
9999
return solution;
100100
}
101101

102-
private Task<Solution> GetProjectFixesAsync(FixAllContext fixAllContext, Project project)
102+
private static Task<Solution> GetProjectFixesAsync(FixAllContext fixAllContext)
103103
{
104-
return this.GetSolutionFixesAsync(fixAllContext, project.Documents.ToImmutableArray());
104+
return GetSolutionFixesAsync(fixAllContext, fixAllContext.Project.Documents.ToImmutableArray());
105105
}
106106

107-
private Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext)
107+
private static Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext)
108108
{
109109
ImmutableArray<Document> documents = fixAllContext.Solution.Projects.SelectMany(i => i.Documents).ToImmutableArray();
110-
return this.GetSolutionFixesAsync(fixAllContext, documents);
110+
return GetSolutionFixesAsync(fixAllContext, documents);
111111
}
112112
}
113113
}

0 commit comments

Comments
 (0)