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
@@ -188,7 +188,7 @@ Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests
188
188
189
189
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) or higher is installed
190
190
* In the root folder of your local repository, run:
191
-
```PowerShell
191
+
```powershell
192
192
./build -Test
193
193
```
194
194
@@ -251,7 +251,7 @@ Suppressing Rules
251
251
You can suppress a rule by decorating a script/function or script/function parameter with .NET's [SuppressMessageAttribute](https://docs.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.suppressmessageattribute).
252
252
`SuppressMessageAttribute`'s constructor takes two parameters: a category and a check ID. Set the `categoryID` parameter to the name of the rule you want to suppress and set the `checkID` parameter to a null or empty string. You can optionally add a third named parameter with a justification for suppressing the message:
253
253
254
-
```PowerShell
254
+
```powershell
255
255
function SuppressMe()
256
256
{
257
257
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification='Just an example')]
@@ -265,7 +265,7 @@ function SuppressMe()
265
265
All rule violations within the scope of the script/function/parameter you decorate will be suppressed.
266
266
267
267
To suppress a message on a specific parameter, set the `SuppressMessageAttribute`'s `CheckId` parameter to the name of the parameter:
@@ -280,7 +280,7 @@ Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression
280
280
281
281
Use the value `Function` to suppress violations on all functions within the attribute's scope. Use the value `Class` to suppress violations on all classes within the attribute's scope:
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 or a glob pattern. Few examples are given below.
297
297
298
298
Suppress `PSAvoidUsingWriteHost` rule violation in `start-bar` and `start-baz` but not in `start-foo` and `start-bam`:
If you place a PSScriptAnayzer settings file named `PSScriptAnalyzerSettings.psd1` in your project root, PSScriptAnalyzer will discover it if you pass the project root as the `Path` parameter.
Copy file name to clipboardExpand all lines: RuleDocumentation/AlignAssignmentStatement.md
+14-9
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,11 @@
4
4
5
5
## Description
6
6
7
-
Consecutive assignment statements are more readable if they are aligned. By aligned, we imply that the `equal` sign for all the assignment statements should be in the same column.
7
+
Consecutive assignment statements are more readable if they are aligned. By aligned, we imply that
8
+
the `equal` sign for all the assignment statements should be in the same column.
8
9
9
-
The rule looks for key (property) value pairs in a hashtable (DSC configuration) to check if they are aligned or not. Consider the following example in which the key value pairs are not aligned.
10
+
The rule looks for key (property) value pairs in a hashtable (DSC configuration) to check if they
11
+
are aligned or not. Consider the following example in which the key value pairs are not aligned.
10
12
11
13
```powershell
12
14
$hashtable = @{
@@ -24,17 +26,18 @@ $hashtable = @{
24
26
}
25
27
```
26
28
27
-
The rule will ignore hashtables in which the assignment statements are on the same line. For example, the rule will ignore `$h = {a = 1; b = 2}`.
29
+
The rule ignores hashtables in which the assignment statements are on the same line. For example,
30
+
the rule ignores `$h = {a = 1; b = 2}`.
28
31
29
32
## Configuration
30
33
31
34
```powershell
32
-
Rules = @{
33
-
PSAlignAssignmentStatement = @{
34
-
Enable = $true
35
-
CheckHashtable = $true
36
-
}
35
+
Rules = @{
36
+
PSAlignAssignmentStatement = @{
37
+
Enable = $true
38
+
CheckHashtable = $true
37
39
}
40
+
}
38
41
```
39
42
40
43
### Parameters
@@ -45,4 +48,6 @@ Enable or disable the rule during ScriptAnalyzer invocation.
45
48
46
49
#### CheckHashtable: bool (Default value is `$false`)
47
50
48
-
Enforce alignment of assignment statements in a hashtable and in a DSC Configuration. There is only one switch for hasthable and DSC configuration because the property value pairs in a DSC configuration are parsed as key value pairs of a hashtable.
51
+
Enforce alignment of assignment statements in a hashtable and in a DSC Configuration. There is only
52
+
one switch for hasthable and DSC configuration because the property value pairs in a DSC
53
+
configuration are parsed as key-value pairs of a hashtable.
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidAssignmentToAutomaticVariable.md
+9-6
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,11 @@
4
4
5
5
## Description
6
6
7
-
`PowerShell` exposes some of its built-in variables that are known as automatic variables. Many of them are read-only and PowerShell would throw an error when trying to assign an value on those. Other automatic variables should only be assigned to in certain special cases to achieve a certain effect as a special technique.
7
+
PowerShell has built-in variables known as automatic variables. Many of them are read-only and
8
+
PowerShell throws an error when trying to assign an value on those. Other automatic variables should
9
+
only be assigned in certain special cases to achieve a certain effect as a special technique.
8
10
9
-
To understand more about automatic variables, see ```Get-Help about_Automatic_Variables```.
11
+
To understand more about automatic variables, see `Get-Help about_Automatic_Variables`.
10
12
11
13
## How
12
14
@@ -16,18 +18,19 @@ Use variable names in functions or their parameters that do not conflict with au
16
18
17
19
### Wrong
18
20
19
-
The variable `$Error` is an automatic variables that exists in the global scope and should therefore never be used as a variable or parameter name.
21
+
The variable `$Error` is an automatic variables that exists in the global scope and should therefore
22
+
never be used as a variable or parameter name.
20
23
21
-
```PowerShell
24
+
```powershell
22
25
function foo($Error){ }
23
26
```
24
27
25
-
```PowerShell
28
+
```powershell
26
29
function Get-CustomErrorMessage($ErrorMessage){ $Error = "Error occurred: $ErrorMessage" }
27
30
```
28
31
29
32
### Correct
30
33
31
-
```PowerShell
34
+
```powershell
32
35
function Get-CustomErrorMessage($ErrorMessage){ $FinalErrorMessage = "Error occurred: $ErrorMessage" }
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidDefaultValueForMandatoryParameter.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,15 @@
4
4
5
5
## Description
6
6
7
-
Mandatory parameters should not have a default values because there is no scenario where the default can be used because `PowerShell` will prompt anyway if the parameter value is not specified when calling the function.
7
+
Mandatory parameters should not have a default values because there is no scenario where the default
8
+
can be used. PowerShell prompts for a value if the parameter value is not specified when calling the
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidGlobalAliases.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,13 @@
4
4
5
5
## Description
6
6
7
-
Globally scoped aliases override existing aliases within the sessions with matching names. This name collision can cause difficult to debug issues for consumers of modules and scripts.
7
+
Globally scoped aliases override existing aliases within the sessions with matching names. This name
8
+
collision can cause difficult to debug issues for consumers of modules and scripts.
8
9
9
-
To understand more about scoping, see ```Get-Help about_Scopes```.
10
+
To understand more about scoping, see `Get-Help about_Scopes`.
10
11
11
-
**NOTE** This rule is not available in PowerShell version 3 and 4 due to the `StaticParameterBinder.BindCommand` API that the rule uses internally.
12
+
**NOTE** This rule is not available in PowerShell version 3 or 4 because it uses the
13
+
`StaticParameterBinder.BindCommand` API.
12
14
13
15
## How
14
16
@@ -18,12 +20,12 @@ Use other scope modifiers for new aliases.
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidGlobalFunctions.md
+6-5
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,11 @@
4
4
5
5
## Description
6
6
7
-
Globally scoped functions override existing functions within the sessions with matching names. This name collision can cause difficult to debug issues for consumers of modules.
7
+
Globally scoped functions override existing functions within the sessions with matching names. This
8
+
name collision can cause difficult to debug issues for consumers of modules.
8
9
9
10
10
-
To understand more about scoping, see ```Get-Help about_Scopes```.
11
+
To understand more about scoping, see `Get-Help about_Scopes`.
11
12
12
13
## How
13
14
@@ -17,12 +18,12 @@ Use other scope modifiers for functions.
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidGlobalVars.md
+12-10
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,17 @@
4
4
5
5
## Description
6
6
7
-
A variable is a unit of memory in which values are stored. Windows PowerShell controls access to variables, functions, aliases, and drives through a mechanism known as scoping.
8
-
Variables and functions that are present when Windows PowerShell starts have been created in the global scope.
7
+
A variable is a unit of memory in which values are stored. PowerShell controls access to variables,
8
+
functions, aliases, and drives through a mechanism known as scoping. Variables and functions that
9
+
are present when PowerShell starts have been created in the global scope.
9
10
10
11
Globally scoped variables include:
11
-
* Automatic variables
12
-
* Preference variables
13
-
* Variables, aliases, and functions that are in your Windows PowerShell profiles
14
12
15
-
To understand more about scoping, see ```Get-Help about_Scopes```.
13
+
- Automatic variables
14
+
- Preference variables
15
+
- Variables, aliases, and functions that are in your PowerShell profiles
16
+
17
+
To understand more about scoping, see `Get-Help about_Scopes`.
16
18
17
19
## How
18
20
@@ -22,20 +24,20 @@ Use other scope modifiers for variables.
0 commit comments