Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions tools/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/CommandName.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = "<doesn't follow the Capitalization Conventions>"
ModuleCmdletExNum = $ModuleCmdletExNum
}
Expand Down Expand Up @@ -108,22 +109,12 @@ function Measure-CommandName {
$Severity = "Warning"
}
if ($global:CommandParameterPair[$i].ParameterName -eq "<doesn't follow the Capitalization Conventions>") {
$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]@{
Expand Down