File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,17 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1010$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer - ScriptDefinition (Get-Content - Raw " $directory \RuleSuppression.ps1" )
1111$violations = Invoke-ScriptAnalyzer " $directory \RuleSuppression.ps1"
1212
13+ $ruleSuppressionBad = @'
14+ Function do-something
15+ {
16+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingUserNameAndPassWordParams", "username")]
17+ Param(
18+ $username,
19+ $password
20+ )
21+ }
22+ '@
23+
1324Describe " RuleSuppressionWithoutScope" {
1425 Context " Function" {
1526 It " Does not raise violations" {
@@ -37,6 +48,14 @@ Describe "RuleSuppressionWithoutScope" {
3748 $suppression.Count | Should Be 1
3849 }
3950 }
51+
52+ Context " Bad Rule Suppression" {
53+ It " Throws a non-terminating error" {
54+ Invoke-ScriptAnalyzer - ScriptDefinition $ruleSuppressionBad - IncludeRule " PSAvoidUsingUserNameAndPassWordParams" - ErrorVariable errorRecord 2> $null
55+ $errorRecord.Count | Should Be 1
56+ $errorRecord.FullyQualifiedErrorId | Should match " suppression message attribute error"
57+ }
58+ }
4059}
4160
4261Describe " RuleSuppressionWithScope" {
You can’t perform that action at this time.
0 commit comments