Skip to content

Commit f027bfc

Browse files
author
Kapil Borle
committed
Fix README and rule documetation
* Change CMDLets to cmdlets * Change ``` for inline code to `
1 parent 5bee2c0 commit f027bfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+252
-260
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Announcements
1414

1515
Introduction
1616
============
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
1919
code defects and suggests possible solutions for improvements.
2020

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,
2222
usage of Invoke-Expression etc. Additional functionalities such as exclude/include specific rules are also supported.
2323

24-
PSScriptAnalyzer CMDLets
24+
PSScriptAnalyzer Cmdlets
2525
======================
2626
``` PowerShell
2727
Get-ScriptAnalyzerRule [-CustomizedRulePath <string[]>] [-Name <string[]>] [<CommonParameters>] [-Severity <string[]>]
@@ -79,7 +79,7 @@ cd path/to/PSScriptAnalyzer
7979
Import-Module /path/to/PSScriptAnalyzer/out/PSScriptAnalyzer
8080
```
8181

82-
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
8383

8484
Suppressing Rules
8585
=================
@@ -112,7 +112,7 @@ function SuppressTwoVariables()
112112
}
113113
```
114114

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.
116116

117117
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:
118118

@@ -173,8 +173,8 @@ Param(
173173

174174
Settings Support in ScriptAnalyzer
175175
========================================
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.
178178

179179
Using Settings support:
180180

@@ -237,12 +237,12 @@ public System.Collections.Generic.IEnumerable<IRule> GetRule(string[] moduleName
237237

238238
Violation Correction
239239
====================
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.
241241

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,
243243
that contains information needed to rectify the violation.
244244

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:
246246
``` PowerShell
247247
PS> Get-Content C:\tmp\test.ps1
248248
gci C:\

RuleDocumentation/AvoidAlias.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
#AvoidAlias
1+
#AvoidAlias
22
**Severity Level: Warning**
33

44
##Description
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.
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.
66
You can use the alias instead of the command name in any Windows PowerShell commands.
77

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
99
impact availability.
1010

1111
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.
1212

1313
The use of full command names also allows for syntax highlighting in sites and applications like GitHub and Visual Studio Code.
1414

1515
##How to Fix
16-
Use the full CMDLet name and not an alias.
16+
Use the full cmdlet name and not an alias.
1717

1818
##Example
19-
###Wrong:
19+
###Wrong:
2020
``` PowerShell
2121
gps | Where-Object {$_.WorkingSet -gt 20000000}
2222
```
2323

24-
###Correct:
24+
###Correct:
2525
``` PowerShell
2626
Get-Process | Where-Object {$_.WorkingSet -gt 20000000}
2727
```

RuleDocumentation/AvoidDefaultTrueValueSwitchParameter.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#AvoidDefaultTrueValueSwitchParameter
1+
#AvoidDefaultTrueValueSwitchParameter
22
**Severity Level: Warning**
33

44
##Description
@@ -8,7 +8,7 @@ Switch parameters for commands should default to false.
88
Change the default value of the switch parameter to be false.
99

1010
##Example
11-
###Wrong:
11+
###Wrong:
1212
``` PowerShell
1313
function Test-Script
1414
{
@@ -17,15 +17,15 @@ function Test-Script
1717
(
1818
[String]
1919
$Param1,
20-
20+
2121
[switch]
2222
$Switch=$True
2323
)
2424
...
2525
}
2626
```
2727

28-
###Correct:
28+
###Correct:
2929
``` PowerShell
3030
function Test-Script
3131
{

RuleDocumentation/AvoidEmptyCatchBlock.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#AvoidEmptyCatchBlock
1+
#AvoidEmptyCatchBlock
22
**Severity Level: Warning**
33

44
##Description
5-
Empty catch blocks are considered a poor design choice as they result in the errors occurring in a ```try``` block not being acted upon.
6-
7-
While this does not inherently lead to issues, they should be avoid where possible.
5+
Empty catch blocks are considered a poor design choice as they result in the errors occurring in a `try` block not being acted upon.
6+
7+
While this does not inherently lead to issues, they should be avoided wherever possible.
88

99
##How to Fix
1010
Use ```Write-Error``` or ```throw``` statements within the catch block.

RuleDocumentation/AvoidGlobalVars.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#AvoidGlobalVars
1+
#AvoidGlobalVars
22
**Severity Level: Warning**
33

44
##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.
77

88
Globally scoped variables include:
99
* Automatic variables

RuleDocumentation/AvoidInvokingEmptyMembers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#AvoidInvokingEmptyMembers
1+
#AvoidInvokingEmptyMembers
22
**Severity Level: Warning**
33

44
##Description
55
Invoking non-constant members can cause potential bugs. Please double check the syntax to make sure that invoked members are constants.
66

77
##How to Fix
8-
Provide the requested members for a given type or class.
8+
Provide the requested members for a given type or class.
99

1010
##Example
11-
###Wrong:
11+
###Wrong:
1212
``` PowerShell
1313
$MyString = "abc"
1414
$MyString.('len'+'gth')
1515
```
1616

17-
###Correct:
17+
###Correct:
1818
``` PowerShell
1919
$MyString = "abc"
2020
$MyString.('length')

RuleDocumentation/AvoidNullOrEmptyHelpMessageAttribute.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#AvoidNullOrEmtpyHelpMessageAttribute
1+
#AvoidNullOrEmtpyHelpMessageAttribute
22
**Severity Level: Warning**
33

44
##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.
77

88
##How to Fix
9-
Specify a value for the ```HelpMessage``` attribute.
9+
Specify a value for the `HelpMessage` attribute.
1010

1111
##Example
1212
###Wrong:
@@ -15,7 +15,7 @@ Function BadFuncEmptyHelpMessageEmpty
1515
{
1616
Param(
1717
[Parameter(HelpMessage='')]
18-
[String]
18+
[String]
1919
$Param
2020
)
2121
@@ -26,7 +26,7 @@ Function BadFuncEmptyHelpMessageNull
2626
{
2727
Param(
2828
[Parameter(HelpMessage=$null)]
29-
[String]
29+
[String]
3030
$Param
3131
)
3232
@@ -37,7 +37,7 @@ Function BadFuncEmptyHelpMessageNoAssignment
3737
{
3838
Param(
3939
[Parameter(HelpMessage)]
40-
[String]
40+
[String]
4141
$Param
4242
)
4343
@@ -51,7 +51,7 @@ Function GoodFuncHelpMessage
5151
{
5252
Param(
5353
[Parameter(HelpMessage='This is helpful')]
54-
[String]
54+
[String]
5555
$Param
5656
)
5757

RuleDocumentation/AvoidReservedCharInCmdlet.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#AvoidReservedCharInCmdlet
1+
#AvoidReservedCharInCmdlet
22
**Severity Level: Error**
33

44
##Description
5-
You cannot use following reserved characters in a function or CMDLet name as these can cause parsing or runtime errors.
5+
You cannot use following reserved characters in a function or cmdlet name as these can cause parsing or runtime errors.
66

7-
Reserved Characters include: ```#,(){}[]&/\\$^;:\"'<>|?@`*%+=~```
7+
Reserved Characters include: `#,(){}[]&/\\$^;:\"'<>|?@`*%+=~`
88

99
##How to Fix
1010
Remove reserved characters from names.
1111

1212
##Example
13-
###Wrong:
13+
###Wrong:
1414
``` PowerShell
1515
function MyFunction[1]
1616
{...}

RuleDocumentation/AvoidReservedParams.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#AvoidReservedParams
1+
#AvoidReservedParams
22
**Severity Level: Error**
33

44
##Description
@@ -8,14 +8,14 @@ You cannot use reserved common parameters in an advanced function.
88
Change the name of the parameter.
99

1010
##Example
11-
###Wrong:
11+
###Wrong:
1212
``` PowerShell
1313
function Test
1414
{
1515
[CmdletBinding]
1616
Param
1717
(
18-
$ErrorVariable,
18+
$ErrorVariable,
1919
$Parameter2
2020
)
2121
}
@@ -28,7 +28,7 @@ function Test
2828
[CmdletBinding]
2929
Param
3030
(
31-
$Err,
31+
$Err,
3232
$Parameter2
3333
)
3434
}

RuleDocumentation/AvoidShouldContinueWithoutForce.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#AvoidShouldContinueWithoutForce
1+
#AvoidShouldContinueWithoutForce
22
**Severity Level: Warning**
33

44
##Description
55
Functions that use ShouldContinue should have a boolean force parameter to allow user to bypass it.
66

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.
88

99
##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`.
1111

1212
##Example
1313
###Wrong:
14-
``` PowerShell
14+
``` PowerShell
1515
Function Test-ShouldContinue
1616
{
1717
[CmdletBinding(SupportsShouldProcess=$true)]
@@ -20,7 +20,7 @@ Function Test-ShouldContinue
2020
$MyString = 'blah'
2121
)
2222
23-
if ($PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
23+
if ($PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
2424
{
2525
...
2626
}
@@ -38,7 +38,7 @@ Function Test-ShouldContinue
3838
[Switch]$Force
3939
)
4040
41-
if ($PsBoundParameters.ContainsKey('force') -or $PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
41+
if ($Force -or $PsCmdlet.ShouldContinue("ShouldContinue Query", "ShouldContinue Caption"))
4242
{
4343
...
4444
}

RuleDocumentation/AvoidTrapStatement.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#AvoidTrapStatement
1+
#AvoidTrapStatement
22
**Severity Level: Warning**
33

44
##Description
5-
The ```Trap``` keyword specifies a list of statements to run when a terminating error occurs.
5+
The `Trap` keyword specifies a list of statements to run when a terminating error occurs.
66

77
Trap statements handle the terminating errors and allow execution of the script or function to continue instead of stopping.
88

9-
Traps are intended for the use of administrators and not for script and CMDLet developers. PowerShell scripts and CMDLets should make use
10-
of ```try{} catch{} finally{}``` statements.
9+
Traps are intended for the use of administrators and not for script and cmdlet developers. PowerShell scripts and cmdlets should make use
10+
of `try{} catch{} finally{}` statements.
1111

1212
##How to Fix
13-
Replace ```Trap``` statements with ```try{} catch{} finally{}``` statements.
13+
Replace `Trap` statements with `try{} catch{} finally{}` statements.
1414

1515
##Example
16-
###Wrong:
16+
###Wrong:
1717
``` PowerShell
18-
function Test-Trap
18+
function Test-Trap
1919
{
2020
trap {"Error found: $_"}
2121
}
2222
```
2323

24-
###Correct:
24+
###Correct:
2525
``` PowerShell
26-
function Test-Trap
26+
function Test-Trap
2727
{
28-
try
28+
try
2929
{
3030
$a = New-Object "NonExistentObjectType"
3131
$a | Get-Member

0 commit comments

Comments
 (0)