diff --git a/tools/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/CommandName.psm1 b/tools/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/CommandName.psm1 index e2ba7e672b67..e85d43d6ce22 100644 --- a/tools/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/CommandName.psm1 +++ b/tools/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/CommandName.psm1 @@ -52,6 +52,7 @@ function Measure-CommandName { if ($CommandAst.InvocationOperator -eq "Unknown") { $CommandName = $CommandAst.CommandElements[0].Extent.Text $GetCommand = Get-Command $CommandName -ErrorAction SilentlyContinue + $ActualName = $GetCommand.Name if ($null -eq $GetCommand) { # CommandName is not valid. # Redo import-module @@ -74,10 +75,10 @@ function Measure-CommandName { } return $true } - if ($CommandName -cnotmatch "^([A-Z][a-z]+)+-([A-Z][a-z0-9]*)+$") { + if ($CommandName -cne $ActualName) { # CommandName doesn't follow the Capitalization Conventions. $global:CommandParameterPair += @{ - CommandName = $CommandName + CommandName = "$CommandName#@#$ActualName" ParameterName = "" ModuleCmdletExNum = $ModuleCmdletExNum } @@ -108,22 +109,12 @@ function Measure-CommandName { $Severity = "Warning" } if ($global:CommandParameterPair[$i].ParameterName -eq "") { - $Message = "$($CommandParameterPair[$i].CommandName) doesn't follow the Capitalization Conventions." + $CommandName, $CorrectName = $CommandParameterPair[$i].CommandName -split "#@#" + $Message = "$CommandName doesn't follow the Capitalization Conventions." $RuleName = [RuleNames]::Capitalization_Conventions_Violated $RuleSuppressionID = "5101" - $name = $($CommandParameterPair[$i].CommandName) - $textInfo = (Get-Culture).TextInfo - $CorrectName = $textInfo.ToTitleCase(($name -split "-")[0]) - if($name -match "Az"){ - $CorrectName += "-Az" - $CorrectName += $textInfo.ToTitleCase(($name -split "Az")[1]) - } - else{ - $CorrectName += "-" - $CorrectName += $textInfo.ToTitleCase(($name -split "-")[1]) - } $Remediation = "Check the Capitalization Conventions. Suggest format: $CorrectName" - $Severity = "Warning" + $Severity = "Error" } $ModuleCmdletExNum = $($CommandParameterPair[$i].ModuleCmdletExNum) $Result = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]@{