no-cmdlet-aliases
What it does
Section titled “What it does”Reports a command written with one of the default aliases of Windows PowerShell and PowerShell 7 (gci, ls, %, ?, iex and so on). The table is the one of a Windows host.
Why it matters
Section titled “Why it matters”Aliases are for typing at a prompt. In a script they are less readable (% and ? are not words), may be absent or mean another command on a platform (ls is the native command on Linux), and users can redefine them.
To fix, write the full name of the cmdlet.
Example
Section titled “Example”gci -Recurse | % { $_ }Get-ChildItem | ? Name -eq xls1..3 | %{ $_ }Get-ChildItem | Where-Object { $_ } | foreach { $_ }$x = dirWrite-Output ls& ls -la& Get-ChildItemConfiguration
Section titled “Configuration”powershell: lint: rules: no-cmdlet-aliases: warn # off (default), warn, errorEnabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line no-cmdlet-aliases in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| psscriptanalyzer | PSAvoidUsingCmdletAliases |
partial | The table is fixed (a Windows host’s); PSScriptAnalyzer reads the aliases of the host it runs on, so on Linux ls and cat are not aliases there, and user-defined aliases are not known. No fix that expands the alias. & ls is reported at the &. |