Skip to content

Commit 7540bc2

Browse files
committed
Modify the format of the help document
1 parent fa95d29 commit 7540bc2

File tree

4 files changed

+97
-7
lines changed

4 files changed

+97
-7
lines changed

RuleDocumentation/AvoidAlias.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
#AvoidAlias
1+
#AvoidAlias
2+
**Severity Level: Warning**
3+
24

35
##Description
46

57
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. But when writing scripts that will potentially need to be maintained over time, either by the original author or another Windows PowerShell scripter, please consider using full cmdlet name instead of alias. Aliases can introduce these problems, readability, understandability and availability.
68

7-
**Severity Level: Warning**
9+
##How to Fix
810

9-
##Example
11+
Please consider using full cmdlet name instead of alias.
1012

11-
gps | where-object {$_.WorkingSet -gt 20000000}
13+
##Example
1214

13-
cls
15+
Wrong: gps | where-object {$_.WorkingSet -gt 20000000}
1416

15-
##How to Fix
16-
Please consider using full cmdlet name instead of alias.
17+
Correct: get-process | where-object {$_.WorkingSet -gt 20000000}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#AvoidDefaultTrueValueSwitchParameter
2+
**Severity Level: Warning**
3+
4+
5+
##Description
6+
7+
Switch Parameters Should Not Default To True
8+
9+
10+
##How to Fix
11+
12+
Please change the default value of the switch parameter to be false.
13+
14+
##Example
15+
16+
Wrong:
17+
Param
18+
( …
19+
$Param1,
20+
[switch]
21+
$switch=$true
22+
23+
)
24+
25+
Correct:
26+
Param
27+
( …
28+
$Param1,
29+
[switch]
30+
$switch=$false
31+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#AvoidEmptyCatchBlock
2+
**Severity Level: Warning**
3+
4+
##Description
5+
6+
Empty catch blocks are considered poor design decisions because if an error occurs in the try block, this error is simply swallowed and not acted upon. While this does not inherently lead to bad things. It can and this should be avoided if possible.
7+
8+
##How to Fix
9+
10+
To fix a violation of this rule, using Write-Error or throw statements in catch blocks.
11+
12+
##Example
13+
Wrong:
14+
try
15+
{
16+
1/0
17+
}
18+
catch [DivideByZeroException]
19+
{
20+
21+
}
22+
23+
Correct:
24+
try
25+
{
26+
1/0
27+
}
28+
catch [DivideByZeroException]
29+
{
30+
Write-Error "DivideByZeroException"
31+
}

RuleDocumentation/AvoidGlobalVars.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#AvoidGlobalVars
2+
**Severity Level: Warning**
3+
4+
##Description
5+
6+
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. Variables and functions that are present when Windows PowerShell starts have been created in the global scope. This includes automatic variables and preference variables. This also includes the variables, aliases, and functions that are in your Windows PowerShell profiles.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. Variables and functions that are present when Windows PowerShell starts have been created in the global scope. This includes automatic variables and preference variables. This also includes the variables, aliases, and functions that are in your Windows PowerShell profiles.
7+
8+
##How to Fix
9+
10+
To fix a violation of this rule, please consider to use other scope modifiers.
11+
12+
##Example
13+
Wrong:
14+
$Global:var1 = $null
15+
16+
function NotGlobal ($var)
17+
{
18+
$a = $var + $var1
19+
}
20+
21+
Correct:
22+
$Global:var1 = $null
23+
24+
function NotGlobal ($var1,$var2)
25+
{
26+
$a = $var1 + $var2
27+
}

0 commit comments

Comments
 (0)