Skip to content

Commit 51c8414

Browse files
author
Kapil Borle
committed
Update AvoidAlias rule documentation
1 parent b69b813 commit 51c8414

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

RuleDocumentation/AvoidAlias.md

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

4-
##Description
4+
## Description
55
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

@@ -12,16 +12,30 @@ When developing PowerShell content that will potentially need to be maintained o
1212

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

15-
##How to Fix
15+
## How to Fix
1616
Use the full cmdlet name and not an alias.
1717

18-
##Example
19-
###Wrong:
18+
## Alias Whitelist
19+
To prevent `PSScriptAnalyzer` from flagging your preferred aliases, create a whitelist of the aliases in your settings file and point `PSScriptAnalyzer` to use the settings file. For example, to disable `PSScriptAnalyzer` from flagging `cd`, which is an alias of `Set-Location`, set the settings file content to the following.
20+
21+
```PowerShell
22+
# PSScriptAnalyzerSettings.psd1
23+
@{
24+
'Rules' = @{
25+
'PSAvoidUsingCmdletAliases' = @{
26+
'Whitelist' = @('cd')
27+
}
28+
}
29+
}
30+
```
31+
32+
## Example
33+
### Wrong:
2034
``` PowerShell
2135
gps | Where-Object {$_.WorkingSet -gt 20000000}
2236
```
2337

24-
###Correct:
38+
### Correct:
2539
``` PowerShell
2640
Get-Process | Where-Object {$_.WorkingSet -gt 20000000}
2741
```

0 commit comments

Comments
 (0)