@@ -62,28 +62,8 @@ RUNNING SCRIPT ANALYZER ON A NEW SCRIPT, MODULE OR DSC RESOURCE
6262 explicitly violate. Suppress those rules as necessary but try to avoid
6363 "knee jerk" suppression of rules. Analyze the diagnostic output and the part
6464 of your script that violates the rule to be sure you understand the reason for
65- the warning and that it is indeed OK to suppress the rule.
66-
67- There are several ways to suppress rules. You can suppress a rule globally
68- by using the ExcludeRule parameter when invoking the script analyzer e.g.:
69-
70- PS C:\> Invoke-ScriptAnalyzer -Path . -ExcludeRule `
71- PSProvideDefaultParameterValue, PSAvoidUsingWMICmdlet
72-
73- Note that the ExcludeRule parameter takes an array of strings i.e. rule names.
74-
75- Sometimes you will want to suppress a rule for part of your script but not for
76- the entire script. PSScriptAnalyzer allows you to suppress rules at the
77- script, function and class scope. You can use the .NET Framework
78- System.Diagnoctics.CodeAnalysis.SuppressMesssageAttribute in your script
79- like so:
80-
81- function Commit-Change() {
82- [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseApprovedVerbs",
83- "", Scope="Function",
84- Target="*")]
85- param()
86- }
65+ the warning and that it is indeed OK to suppress the rule. For information on
66+ how to suppress rules see the RULE SUPPRESSION section below.
8767
8868RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
8969
@@ -150,17 +130,49 @@ RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
150130 3 PSPossibleIncorrectComparisonWithNull
151131 1 PSAvoidUsingComputerNameHardcoded
152132
153- I may decide to table the PSAvoidUsingInvokeExpression for the moment and
154- focus on the rest, especially the PSUseDeclaredVarsMoreThanAssigments,
133+ I may decide to exclude the PSAvoidUsingInvokeExpression rule for the moment
134+ and focus on the rest, especially the PSUseDeclaredVarsMoreThanAssigments,
155135 PSAvoidUninitializedVariable and PSPossibleIncorrectComparisonWithNull rules.
156136
157137 As you fix rules, go back and enable more rules as you have time to address
158- the issues. While getting a completely clean run through every rule is a
138+ the associated issues. In some cases, you may want to suppress a rule at
139+ the function, script or class scope instead of globally excluding rule. See
140+ the RULE SUPPRESSION section below.
141+
142+ While getting a completely clean run through every rule is a
159143 noble goal, it may not always be feasible. You have to weigh the gain of
160144 passing the rule and eliminating a "potential" issue with changing script
161145 and possibly introducing a new problem. In the end, for existing scripts,
162146 it is usually best to have evaluated the rule violations that you deem the
163147 most valuable to address.
148+
149+ RULE SUPPRESSSION
150+
151+ Rule suppression allows you to turn off rule verification on a function,
152+ scripts or class definition. This allows you to exclude only specified
153+ scripts or functions from verification of a rule instead of globally
154+ excluding the rule.
155+
156+ There are several ways to suppress rules. You can suppress a rule globally
157+ by using the ExcludeRule parameter when invoking the script analyzer e.g.:
158+
159+ PS C:\> Invoke-ScriptAnalyzer -Path . -ExcludeRule `
160+ PSProvideDefaultParameterValue, PSAvoidUsingWMICmdlet
161+
162+ Note that the ExcludeRule parameter takes an array of strings i.e. rule names.
163+
164+ Sometimes you will want to suppress a rule for part of your script but not for
165+ the entire script. PSScriptAnalyzer allows you to suppress rules at the
166+ script, function and class scope. You can use the .NET Framework
167+ System.Diagnoctics.CodeAnalysis.SuppressMesssageAttribute in your script
168+ like so:
169+
170+ function Commit-Change() {
171+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseApprovedVerbs",
172+ "", Scope="Function",
173+ Target="*")]
174+ param()
175+ }
164176
165177EXTENSIBILITY
166178
0 commit comments