You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-36Lines changed: 57 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ Installation
62
62
```powershell
63
63
Import-Module PSScriptAnalyzer
64
64
```
65
-
If you have previous version of PSScriptAnalyzer installed on your machine, you may need to override old binaries by copying content of [``~/ProjectRoot/PSScriptAnalyzer``] to PSModulePath.
65
+
If you have previous version of PSScriptAnalyzer installed on your machine, you may need to override old binaries by copying content of [``~/ProjectRoot/PSScriptAnalyzer``] to PSModulePath.
66
66
67
67
To confirm installation: run ```Get-ScriptAnalyzerRule``` in the PowerShell console to obtain the built-in rules
68
68
@@ -78,11 +78,11 @@ You can suppress a rule by decorating a script/function or script/function param
78
78
param()
79
79
80
80
Write-Verbose -Message "I'm making a difference!"
81
-
81
+
82
82
}
83
-
83
+
84
84
All rule violations within the scope of the script/function/parameter you decorate will be suppressed.
85
-
85
+
86
86
To suppress a message on a specific parameter, set the `SuppressMessageAttribute`'s `CheckId` parameter to the name of the parameter:
87
87
88
88
function SuppressTwoVariables()
@@ -100,75 +100,96 @@ Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression
The above example demonstrates how to suppress rule violations for internal functions using the `SuppressMessageAttribute`'s `Scope` property.
112
112
113
113
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.
Profiles that describe ScriptAnalyzer rules to include/exclude based on `Severity` can be created and supplied to `Invoke-ScriptAnalyzer` using the `-profile` parameter. This enables a user to create custom configuration for a specific environment.
152
+
Settings that describe ScriptAnalyzer rules to include/exclude based on `Severity` can be created and supplied to
153
+
`Invoke-ScriptAnalyzer` using the `-Setting` parameter. This enables a user to create a custom configuration for a specific environment.
154
+
155
+
Using Settings support:
154
156
155
-
Using Profile support:
157
+
The following example excludes two rules from the default set of rules and any rule
158
+
that does not output an Error or Warning diagnostic record.
156
159
157
160
```powershell
158
-
$myProfile = @{
159
-
Severity='Warning'
160
-
IncludeRules=@('PSAvoidUsingCmdletAliases',
161
-
'PSAvoidUsingPositionalParameters',
162
-
'PSAvoidUsingInternalURLs'
163
-
'PSAvoidUninitializedVariable')
164
-
ExcludeRules=@('PSAvoidUsingCmdletAliases'
165
-
'PSAvoidUninitializedVariable')
161
+
# ScriptAnalyzerSettings.psd1
162
+
@{
163
+
Severity=@('Error','Warning')
164
+
ExcludeRules=@('PSAvoidUsingCmdletAliases',
165
+
'PSAvoidUsingWriteHost')
166
166
}
167
+
```
168
+
169
+
Then invoke that settings file when using `Invoke-ScriptAnalyzer`:
0 commit comments