Skip to content

Commit 37c095c

Browse files
committed
Make sure that you can suppress ParseErrors
All findings are returned by default, but if you exclude ParseErrors in -Severity we won't emit them.
1 parent edaca8e commit 37c095c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Engine/Generic/RuleSeverity.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public enum RuleSeverity : uint
2222
/// ERROR: This warning is likely to cause a problem or does not follow PowerShell's required guidelines.
2323
/// </summary>
2424
Error = 2,
25+
26+
/// <summary>
27+
/// ERROR: This diagnostic is caused by an actual parsing error, and is generated only by the engine.
28+
/// </summary>
29+
ParseError = 3,
2530
};
2631
}

Engine/ScriptAnalyzer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScriptDefinition(string scriptDefini
15261526

15271527
var relevantParseErrors = RemoveTypeNotFoundParseErrors(errors, out List<DiagnosticRecord> diagnosticRecords);
15281528

1529-
// Add parse errors first!
1530-
if ( relevantParseErrors != null )
1529+
int emitParseErrors = severity == null ? 1 : severity.Count(item => item == "ParseError");
1530+
// Add parse errors first if requested!
1531+
if ( relevantParseErrors != null && emitParseErrors == 1)
15311532
{
15321533
List<DiagnosticRecord> results = new List<DiagnosticRecord>();
15331534
foreach ( var parseError in relevantParseErrors )
@@ -1878,8 +1879,9 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
18781879
#endif //!PSV3
18791880
var relevantParseErrors = RemoveTypeNotFoundParseErrors(errors, out diagnosticRecords);
18801881

1881-
// First, add all parse errors
1882-
if ( relevantParseErrors != null )
1882+
// First, add all parse errors if they've been requested
1883+
int emitParseErrors = severity == null ? 1 : severity.Count(item => item == "ParseError");
1884+
if ( relevantParseErrors != null && emitParseErrors == 1 )
18831885
{
18841886
List<DiagnosticRecord> results = new List<DiagnosticRecord>();
18851887
foreach ( var parseError in relevantParseErrors )

0 commit comments

Comments
 (0)