@@ -62,28 +62,8 @@ RUNNING SCRIPT ANALYZER ON A NEW SCRIPT, MODULE OR DSC RESOURCE
62
62
explicitly violate. Suppress those rules as necessary but try to avoid
63
63
"knee jerk" suppression of rules. Analyze the diagnostic output and the part
64
64
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.
87
67
88
68
RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
89
69
@@ -150,17 +130,49 @@ RUNNING SCRIPT ANALYZER ON AN EXISTING SCRIPT, MODULE OR DSC RESOURCE
150
130
3 PSPossibleIncorrectComparisonWithNull
151
131
1 PSAvoidUsingComputerNameHardcoded
152
132
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,
155
135
PSAvoidUninitializedVariable and PSPossibleIncorrectComparisonWithNull rules.
156
136
157
137
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
159
143
noble goal, it may not always be feasible. You have to weigh the gain of
160
144
passing the rule and eliminating a "potential" issue with changing script
161
145
and possibly introducing a new problem. In the end, for existing scripts,
162
146
it is usually best to have evaluated the rule violations that you deem the
163
147
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
+ }
164
176
165
177
EXTENSIBILITY
166
178
0 commit comments