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
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,14 @@ Announcements
14
14
15
15
Introduction
16
16
============
17
-
PSScriptAnalyzer is a static code checker for Windows PowerShell modules and scripts. PSScriptAnalyzer checks the quality of Windows PowerShell code by running a set of rules.
18
-
The rules are based on PowerShell best practices identified by PowerShell Team and the community. It generates DiagnosticResults (errors and warnings) to inform users about potential
17
+
PSScriptAnalyzer is a static code checker for Windows PowerShell modules and scripts. PSScriptAnalyzer checks the quality of Windows PowerShell code by running a set of rules.
18
+
The rules are based on PowerShell best practices identified by PowerShell Team and the community. It generates DiagnosticResults (errors and warnings) to inform users about potential
19
19
code defects and suggests possible solutions for improvements.
20
20
21
-
PSScriptAnalyzer is shipped with a collection of built-in rules that checks various aspects of PowerShell code such as presence of uninitialized variables, usage of PSCredential Type,
21
+
PSScriptAnalyzer is shipped with a collection of built-in rules that checks various aspects of PowerShell code such as presence of uninitialized variables, usage of PSCredential Type,
22
22
usage of Invoke-Expression etc. Additional functionalities such as exclude/include specific rules are also supported.
To confirm installation: run ```Get-ScriptAnalyzerRule``` in the PowerShell console to obtain the built-in rules
82
+
To confirm installation: run `Get-ScriptAnalyzerRule` in the PowerShell console to obtain the built-in rules
83
83
84
84
Suppressing Rules
85
85
=================
@@ -112,7 +112,7 @@ function SuppressTwoVariables()
112
112
}
113
113
```
114
114
115
-
Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression to functions or classes within the attribute's scope.
115
+
Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression to functions or classes within the attribute's scope.
116
116
117
117
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:
118
118
@@ -173,8 +173,8 @@ Param(
173
173
174
174
Settings Support in ScriptAnalyzer
175
175
========================================
176
-
Settings that describe ScriptAnalyzer rules to include/exclude based on ```Severity``` can be created and supplied to
177
-
```Invoke-ScriptAnalyzer``` using the ```Setting``` parameter. This enables a user to create a custom configuration for a specific environment.
176
+
Settings that describe ScriptAnalyzer rules to include/exclude based on `Severity` can be created and supplied to
177
+
`Invoke-ScriptAnalyzer` using the `Setting` parameter. This enables a user to create a custom configuration for a specific environment.
178
178
179
179
Using Settings support:
180
180
@@ -237,12 +237,12 @@ public System.Collections.Generic.IEnumerable<IRule> GetRule(string[] moduleName
237
237
238
238
Violation Correction
239
239
====================
240
-
Most violations can be fixed by replacing the violation causing content with the correct alternative.
240
+
Most violations can be fixed by replacing the violation causing content with the correct alternative.
241
241
242
-
In an attempt to provide the user with the ability to correct the violation we provide a property, ```SuggestedCorrections```, in each DiagnosticRecord instance,
242
+
In an attempt to provide the user with the ability to correct the violation we provide a property, `SuggestedCorrections`, in each DiagnosticRecord instance,
243
243
that contains information needed to rectify the violation.
244
244
245
-
For example, consider a script ```C:\tmp\test.ps1``` with the following content:
245
+
For example, consider a script `C:\tmp\test.ps1` with the following content:
An alias is an alternate name or nickname for a CMDLet or for a command element, such as a function, script, file, or executable file.
5
+
An alias is an alternate name or nickname for a CMDLet or for a command element, such as a function, script, file, or executable file.
6
6
You can use the alias instead of the command name in any Windows PowerShell commands.
7
7
8
-
Every PowerShell author learns the actual command names, but different authors learn and use different aliases. Aliases can make code difficult to read, understand and
8
+
Every PowerShell author learns the actual command names, but different authors learn and use different aliases. Aliases can make code difficult to read, understand and
9
9
impact availability.
10
10
11
11
When developing PowerShell content that will potentially need to be maintained over time, either by the original author or others, you should use full command names.
12
12
13
13
The use of full command names also allows for syntax highlighting in sites and applications like GitHub and Visual Studio Code.
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidGlobalVars.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
-
#AvoidGlobalVars
1
+
#AvoidGlobalVars
2
2
**Severity Level: Warning**
3
3
4
4
##Description
5
-
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.
6
-
Variables and functions that are present when Windows PowerShell starts have been created in the global scope.
5
+
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.
6
+
Variables and functions that are present when Windows PowerShell starts have been created in the global scope.
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidNullOrEmptyHelpMessageAttribute.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
#AvoidNullOrEmtpyHelpMessageAttribute
1
+
#AvoidNullOrEmtpyHelpMessageAttribute
2
2
**Severity Level: Warning**
3
3
4
4
##Description
5
-
The value of the ```HelpMessage``` attribute should not be an empty string or a null value as this causes PowerShell's interpreter to throw an mirror when executing the
6
-
function or CMDLet.
5
+
The value of the `HelpMessage` attribute should not be an empty string or a null value as this causes PowerShell's interpreter to throw an mirror when executing the
6
+
function or cmdlet.
7
7
8
8
##How to Fix
9
-
Specify a value for the ```HelpMessage``` attribute.
9
+
Specify a value for the `HelpMessage` attribute.
10
10
11
11
##Example
12
12
###Wrong:
@@ -15,7 +15,7 @@ Function BadFuncEmptyHelpMessageEmpty
15
15
{
16
16
Param(
17
17
[Parameter(HelpMessage='')]
18
-
[String]
18
+
[String]
19
19
$Param
20
20
)
21
21
@@ -26,7 +26,7 @@ Function BadFuncEmptyHelpMessageNull
26
26
{
27
27
Param(
28
28
[Parameter(HelpMessage=$null)]
29
-
[String]
29
+
[String]
30
30
$Param
31
31
)
32
32
@@ -37,7 +37,7 @@ Function BadFuncEmptyHelpMessageNoAssignment
Copy file name to clipboardExpand all lines: RuleDocumentation/AvoidShouldContinueWithoutForce.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
-
#AvoidShouldContinueWithoutForce
1
+
#AvoidShouldContinueWithoutForce
2
2
**Severity Level: Warning**
3
3
4
4
##Description
5
5
Functions that use ShouldContinue should have a boolean force parameter to allow user to bypass it.
6
6
7
-
You can get more details by running ```Get-Help about_Functions_CmdletBindingAttribute``` and ```Get-Help about_Functions_Advanced_Methods``` command in Windows PowerShell.
7
+
You can get more details by running `Get-Help about_Functions_CmdletBindingAttribute` and `Get-Help about_Functions_Advanced_Methods` command in Windows PowerShell.
8
8
9
9
##How to Fix
10
-
Call the ```ShouldContinue``` method in advanced functions when ```ShouldProcess``` method returns ```$true```.
10
+
Call the `ShouldContinue` method in advanced functions when `ShouldProcess` method returns `$true`.
11
11
12
12
##Example
13
13
###Wrong:
14
-
```PowerShell
14
+
```PowerShell
15
15
Function Test-ShouldContinue
16
16
{
17
17
[CmdletBinding(SupportsShouldProcess=$true)]
@@ -20,7 +20,7 @@ Function Test-ShouldContinue
20
20
$MyString = 'blah'
21
21
)
22
22
23
-
if ($PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
23
+
if ($PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
24
24
{
25
25
...
26
26
}
@@ -38,7 +38,7 @@ Function Test-ShouldContinue
38
38
[Switch]$Force
39
39
)
40
40
41
-
if ($PsBoundParameters.ContainsKey('force') -or $PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
41
+
if ($Force -or $PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
0 commit comments