Skip to content

Commit

Permalink
Dropping support for variable expressions enclosed in braces for now,…
Browse files Browse the repository at this point in the history
… until everything else works as expected
  • Loading branch information
BenedekFarkas committed Jun 21, 2024
1 parent 487e4c0 commit 45d7cb3
Showing 1 changed file with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ function Measure-VariableNameCasing
continue
}

# Skip variable expressions enclosed in braces.
if ($variableName.Contains('{'))
{
continue
}

# Check if the variable is an automatic variable.
$automaticVariable = $automaticVariableNames | Where-Object {
$PSItem -eq $variableName } | Select-Object -First 1
Expand Down Expand Up @@ -197,22 +203,6 @@ function Measure-VariableNameCasing
continue
}

# Setting up helper variables to check variable names with or without braces, e.g., $variableName or
# ${variableName}.
$firstLetterIndex = [Math]::Max($variableName.IndexOf('$'), $variableName.IndexOf('{')) + 1
$variableNameHasBraces = $variableName.Contains('{')
$bracelessVariableName = $bracedVariableName = $null
if ($variableNameHasBraces)
{
$bracelessVariableName = $variableName.Replace('{', '').Replace('}', '')
$bracedVariableName = $variableName
}
else
{
$bracelessVariableName = $variableName
$bracedVariableName = '${' + $variableName.Substring(1) + '}'
}

# Find the nearest parent function of the variable.
$nearestParentFunction = (Find-AstNearestParent -AstObject $variable -ParentType ([FunctionDefinitionAst]))

Expand All @@ -228,7 +218,7 @@ function Measure-VariableNameCasing

# Check if the variable is a parameter.
$matchingParameter = $functionParameterNamesWithParents[$nearestParentFunctionName] | Where-Object {
$PSItem -eq $bracelessVariableName -or $PSItem -eq $bracedVariableName } | Select-Object -First 1
$PSItem -eq $variableName } | Select-Object -First 1

# If the variable is not a parameter, check if it starts with a lowercase letter.
if ($null -eq $matchingParameter)
Expand Down Expand Up @@ -259,8 +249,7 @@ function Measure-VariableNameCasing
}
# If a parameter is found, check if it's used with the declared casing. The '-ceq' operator should work
# here, but it doesn't.
elseif (-not $matchingParameter.Equals($bracelessVariableName, 'InvariantCulture') -and
-not $matchingParameter.Equals($bracedVariableName, 'InvariantCulture'))
elseif (-not $matchingParameter.Equals($variableName, 'InvariantCulture'))
{
$correctionExtent = New-Object -TypeName $correctionTypeName -ArgumentList @(
$variable.Extent
Expand Down

0 comments on commit 45d7cb3

Please sign in to comment.