UseCorrectCasing

严重性级别:信息

DESCRIPTION

这是样式/格式规则。 PowerShell尽可能不区分大小写,所以指令包名称、参数、关键词和运算符的大小写其实无关紧要。 尽管如此,此规则仍可确保一致的大小写,以便清晰易读。 使用小写关键字有助于将它们与命令区分开来。 使用小写运算符有助于将它们与参数区分开来。

方式

  • 对类型名称使用精确大小写。
  • 使用 cmdlet 及其参数的精确大小写。
  • 对语言关键字和运算符使用小写。

配置

Rules = @{
    PSUseCorrectCasing = @{
        Enable        = $true
        CheckCommands = $true
        CheckKeyword  = $true
        CheckOperator = $true
    }
}

参数

启用:bool (默认值为 $false

在 ScriptAnalyzer 调用期间启用或禁用规则。

CheckCommands:bool (默认值为 $true

如果成立,要求所有命令和参数名的案例均与其规范套管一致。

CheckKeyword: bool (默认值为 $true

如果为 true,则要求所有关键字的大小写。

CheckOperator:bool (默认值为 $true

如果为 true,则要求所有运算符的大小写。 例如: -eq-ne-gt

例子

错误的方式

ForEach ($file in Get-childitem -Recurse) {
    $file.Extension -EQ '.txt'
}

invoke-command { 'foo' } -runasadministrator

正确方法

foreach ($file in Get-ChildItem -Recurse) {
    $file.Extension -eq '.txt'
}

Invoke-Command { 'foo' } -RunAsAdministrator