Skip to content

Commit d21154c

Browse files
Fixing explanation of the Scope parameter.
1 parent 4efa348 commit d21154c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ You can suppress a rule by decorating a script/function or script/function param
5353
5454
}
5555

56+
All rule violations within the scope of the script/function/parameter you decorate will be suppressed.
57+
5658
To suppress a message on a specific parameter, set the `SuppressMessageAttribute`'s `CheckId` parameter to the name of the parameter:
5759

5860
function SuppressTwoVariables()
@@ -63,25 +65,24 @@ To suppress a message on a specific parameter, set the `SuppressMessageAttribute
6365
{
6466
}
6567
}
66-
67-
To suppress a rule for an entire function/script, decorate the `param` block of the script/function and set the `SuppressMessageAttribute's` `Scope` property to `Function`:
68+
69+
Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression to functions or classes within the attribute's scope. Use the value `Function` to suppress violations on all functions within the attribute's scope. Use the value `Class` to suppress violoations on all classes within the attribute's scope:
70+
6871

6972
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideCommentHelp", "", Scope="Function")]
7073
param(
7174
)
7275

73-
74-
You can also suppress a rule for an entire class using `Class` as the value of the `Scope` property:
75-
76-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Scope="Class")]
77-
class TestClass
76+
function InternalFunction
7877
{
79-
<#
80-
... snip ...
81-
#>
78+
param()
79+
80+
Write-Verbose -Message "I am invincible!"
8281
}
82+
83+
The above example demonstrates how to suppress rule violations for internal functions using the `SuppressMessageAttribute`'s `Scope` property.
8384

84-
Finally, you can restrict suppression inside a scope by setting the `SuppressMessageAttribute's` `Target` property to a regular expression that causes the script analyzer to skip functions/variables/parameters/objects whose names match the regular expression.
85+
You can further restrict suppression based on a function/parameter/class/variable/object's name by setting the `SuppressMessageAttribute's` `Target` property to a regular expression. Any function/parameter/class/variable/object whose name matches the regular expression is skipped.
8586

8687
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPositionalParameters", Scope="Function", Target="PositionalParametersAllowed")]
8788
Param(

0 commit comments

Comments
 (0)