@@ -34,6 +34,7 @@ public class InvokeScriptAnalyzerCommand : PSCmdlet, IOutputWriter
34
34
35
35
#region Private variables
36
36
List < string > processedPaths ;
37
+ private int totalDiagnosticCount = 0 ;
37
38
#endregion // Private variables
38
39
39
40
#region Parameters
@@ -412,6 +413,10 @@ protected override void EndProcessing()
412
413
{
413
414
ScriptAnalyzer . Instance . CleanUp ( ) ;
414
415
base . EndProcessing ( ) ;
416
+
417
+ if ( EnableExit ) {
418
+ this . Host . SetShouldExit ( totalDiagnosticCount ) ;
419
+ }
415
420
}
416
421
417
422
protected override void StopProcessing ( )
@@ -426,7 +431,10 @@ protected override void StopProcessing()
426
431
427
432
private void ProcessInput ( )
428
433
{
429
- WriteToOutput ( RunAnalysis ( ) ) ;
434
+ // collect to array to avoid double enumeration
435
+ var diagnosticRecords = RunAnalysis ( ) . ToArray ( ) ;
436
+ WriteToOutput ( diagnosticRecords ) ;
437
+ totalDiagnosticCount += diagnosticRecords . Length ;
430
438
}
431
439
432
440
private IEnumerable < DiagnosticRecord > RunAnalysis ( )
@@ -454,7 +462,7 @@ private IEnumerable<DiagnosticRecord> RunAnalysis()
454
462
return diagnostics ;
455
463
}
456
464
457
- private void WriteToOutput ( IEnumerable < DiagnosticRecord > diagnosticRecords )
465
+ private void WriteToOutput ( DiagnosticRecord [ ] diagnosticRecords )
458
466
{
459
467
foreach ( ILogger logger in ScriptAnalyzer . Instance . Loggers )
460
468
{
@@ -507,11 +515,6 @@ private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
507
515
}
508
516
}
509
517
}
510
-
511
- if ( EnableExit . IsPresent )
512
- {
513
- this . Host . SetShouldExit ( diagnosticRecords . Count ( ) ) ;
514
- }
515
518
}
516
519
517
520
private void ProcessPath ( )
@@ -535,4 +538,4 @@ private bool OverrideSwitchParam(bool paramValue, string paramName)
535
538
536
539
#endregion // Private Methods
537
540
}
538
- }
541
+ }
0 commit comments