-
Notifications
You must be signed in to change notification settings - Fork 223
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
Add new ParseError level to ScriptFileMarkerLevel and only have it send parse errors #888
Merged
TylerLeonhardt
merged 5 commits into
PowerShell:master
from
TylerLeonhardt:add-new-parseerror-sev
Mar 25, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8f56fa
Add new PSSA 1.18 ParseError Severity
TylerLeonhardt 4937f56
ignore parseerrors from PSSA
TylerLeonhardt a81d4ae
address feedback
TylerLeonhardt 0e05c92
back to empty list since we supply parse errors in PSES again
TylerLeonhardt a57fbd0
address feedback
TylerLeonhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,20 +33,22 @@ public class MarkerCorrection | |
/// </summary> | ||
public enum ScriptFileMarkerLevel | ||
{ | ||
/// <summary> | ||
/// The marker represents an informational message. | ||
/// </summary> | ||
Information = 0, | ||
|
||
/// <summary> | ||
/// The marker represents a warning message. | ||
/// </summary> | ||
Warning, | ||
|
||
/// <summary> | ||
/// The marker represents an error message. | ||
/// </summary> | ||
Error | ||
/// <summary> | ||
/// Information: This warning is trivial, but may be useful. They are recommended by PowerShell best practice. | ||
/// </summary> | ||
Information = 0, | ||
/// <summary> | ||
/// WARNING: This warning may cause a problem or does not follow PowerShell's recommended guidelines. | ||
/// </summary> | ||
Warning = 1, | ||
/// <summary> | ||
/// 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 | ||
}; | ||
|
||
/// <summary> | ||
|
@@ -62,7 +64,7 @@ public class ScriptFileMarker | |
/// Gets or sets the marker's message string. | ||
/// </summary> | ||
public string Message { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the ruleName associated with this marker. | ||
/// </summary> | ||
|
@@ -162,36 +164,27 @@ internal static ScriptFileMarker FromDiagnosticRecord(PSObject psObject) | |
}; | ||
} | ||
|
||
string severity = diagnosticRecord.Severity.ToString(); | ||
if (!Enum.TryParse(severity, out ScriptFileMarkerLevel level)) | ||
{ | ||
throw new ArgumentException( | ||
string.Format( | ||
"The provided DiagnosticSeverity value '{0}' is unknown.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: Using string interpolation ( |
||
severity), | ||
"diagnosticSeverity"); | ||
} | ||
|
||
return new ScriptFileMarker | ||
{ | ||
Message = $"{diagnosticRecord.Message as string}", | ||
RuleName = $"{diagnosticRecord.RuleName as string}", | ||
Level = GetMarkerLevelFromDiagnosticSeverity((diagnosticRecord.Severity as Enum).ToString()), | ||
Level = level, | ||
ScriptRegion = ScriptRegion.Create(diagnosticRecord.Extent as IScriptExtent), | ||
Correction = correction, | ||
Source = "PSScriptAnalyzer" | ||
}; | ||
} | ||
|
||
private static ScriptFileMarkerLevel GetMarkerLevelFromDiagnosticSeverity( | ||
string diagnosticSeverity) | ||
{ | ||
switch (diagnosticSeverity) | ||
{ | ||
case "Information": | ||
return ScriptFileMarkerLevel.Information; | ||
case "Warning": | ||
return ScriptFileMarkerLevel.Warning; | ||
case "Error": | ||
return ScriptFileMarkerLevel.Error; | ||
default: | ||
throw new ArgumentException( | ||
string.Format( | ||
"The provided DiagnosticSeverity value '{0}' is unknown.", | ||
diagnosticSeverity), | ||
"diagnosticSeverity"); | ||
} | ||
} | ||
#endregion | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is supposed to be a readonly empty value, it can't be a
List<T>
.Otherwise, if we need to return a mutable collection, we should either:
s_emptyScriptMarkerResult
, but instead return anew List<T>()
every time.If we return
s_emptyScriptMarkerResult
and the caller then mutates it, those additions will become permanently added tos_emptyScriptMarkerResult
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. I've switched to just some new lists.