Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-ScriptAnalyzer: Stream diagnostics instead of batching #2062

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,29 +434,39 @@ private void ProcessInput()
WriteToOutput(RunAnalysis());
}

private List<DiagnosticRecord> RunAnalysis()
private IEnumerable<DiagnosticRecord> RunAnalysis()
{
if (!IsFileParameterSet())
{
return ScriptAnalyzer.Instance.AnalyzeScriptDefinition(scriptDefinition, out _, out _);
foreach (var record in ScriptAnalyzer.Instance.AnalyzeScriptDefinition(scriptDefinition, out _, out _))
{
yield return record;
}
yield break;
}

var diagnostics = new List<DiagnosticRecord>();
foreach (string path in this.processedPaths)
foreach (var path in this.processedPaths)
{
if (!ShouldProcess(path, $"Analyzing path with Fix={this.fix} and Recurse={this.recurse}"))
{
continue;
}

if (fix)
{
ShouldProcess(path, $"Analyzing and fixing path with Recurse={this.recurse}");
diagnostics.AddRange(ScriptAnalyzer.Instance.AnalyzeAndFixPath(path, this.ShouldProcess, this.recurse));
foreach (var record in ScriptAnalyzer.Instance.AnalyzeAndFixPath(path, this.ShouldProcess, this.recurse))
{
yield return record;
}
}
else
{
ShouldProcess(path, $"Analyzing path with Recurse={this.recurse}");
diagnostics.AddRange(ScriptAnalyzer.Instance.AnalyzePath(path, this.ShouldProcess, this.recurse));
foreach (var record in ScriptAnalyzer.Instance.AnalyzePath(path, this.ShouldProcess, this.recurse))
{
yield return record;
}
}
}

return diagnostics;
}

private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
Expand Down