Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion Engine/ScriptAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
IScriptExtent extent;
string message = string.Empty;
string ruleName = string.Empty;
string ruleSuppressionID = string.Empty;
IEnumerable<CorrectionExtent> suggestedCorrections;

if (psobject != null && psobject.ImmediateBaseObject != null)
Expand All @@ -1282,6 +1283,7 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,
message = psobject.Properties["Message"].Value.ToString();
extent = (IScriptExtent)psobject.Properties["Extent"].Value;
ruleName = psobject.Properties["RuleName"].Value.ToString();
ruleSuppressionID = psobject.Properties["RuleSuppressionID"].Value?.ToString();
suggestedCorrections = (IEnumerable<CorrectionExtent>)psobject.Properties["SuggestedCorrections"].Value;
}
catch (Exception ex)
Expand All @@ -1292,7 +1294,11 @@ internal IEnumerable<DiagnosticRecord> GetExternalRecord(Ast ast, Token[] token,

if (!string.IsNullOrEmpty(message))
{
diagnostics.Add(new DiagnosticRecord(message, extent, ruleName, severity, filePath) { SuggestedCorrections = suggestedCorrections });
diagnostics.Add(new DiagnosticRecord(message, extent, ruleName, severity, filePath)
{
SuggestedCorrections = suggestedCorrections,
RuleSuppressionID = ruleSuppressionID,
});
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions ScriptRuleDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ $suggestedCorrections.add($correctionExtent) | out-null
"Extent" = $ast.Extent
"RuleName" = $PSCmdlet.MyInvocation.InvocationName
"Severity" = "Warning"
"Severity" = "Warning"
"RuleSuppressionID" = "MyRuleSuppressionID"
"SuggestedCorrections" = $suggestedCorrections
}
```
Expand Down
5 changes: 5 additions & 0 deletions Tests/Engine/CustomizedRule.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ Describe "Test importing correct customized rules" {
Where-Object { $_.Message -eq $message }

$customizedRulePath.Count | Should -Be 0
}

It "will set RuleSuppressionID" {
$violations = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule
$violations[0].RuleSuppressionID | Should -Be "MyRuleSuppressionID"
}

if (!$testingLibraryUsage)
Expand Down
3 changes: 2 additions & 1 deletion Tests/Engine/samplerule/samplerule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function Measure-RequiresRunAsAdministrator
$dr = New-Object `
-Typename "Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord" `
-ArgumentList "This is help",$extent,$PSCmdlet.MyInvocation.InvocationName,Warning,$null,$null,$l
return $dr
$dr.RuleSuppressionID = "MyRuleSuppressionID"
return $dr
}
Export-ModuleMember -Function Measure*