Skip to content

Commit

Permalink
Make sure that you can suppress ParseErrors
Browse files Browse the repository at this point in the history
All findings are returned by default, but if you exclude ParseErrors in -Severity we won't emit them.
  • Loading branch information
JamesWTruher committed Feb 1, 2019
1 parent edaca8e commit 37c095c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Engine/Generic/RuleSeverity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public enum RuleSeverity : uint
/// ERROR: This warning is likely to cause a problem or does not follow PowerShell's required guidelines.
/// </summary>
Error = 2,

/// <summary>
/// ERROR: This diagnostic is caused by an actual parsing error, and is generated only by the engine.
/// </summary>
ParseError = 3,
};
}
10 changes: 6 additions & 4 deletions Engine/ScriptAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,9 @@ public IEnumerable<DiagnosticRecord> AnalyzeScriptDefinition(string scriptDefini

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

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

// First, add all parse errors
if ( relevantParseErrors != null )
// First, add all parse errors if they've been requested
int emitParseErrors = severity == null ? 1 : severity.Count(item => item == "ParseError");
if ( relevantParseErrors != null && emitParseErrors == 1 )
{
List<DiagnosticRecord> results = new List<DiagnosticRecord>();
foreach ( var parseError in relevantParseErrors )
Expand Down

0 comments on commit 37c095c

Please sign in to comment.