Skip to content

Commit aa66551

Browse files
authored
UseConsistentWhitespace: Fix CheckParameter bug when using interpolated string (#1498)
1 parent 2d37016 commit aa66551

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Rules/UseConsistentWhitespace.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ private IEnumerable<DiagnosticRecord> FindParameterViolations(Ast ast)
390390
testAst => testAst is CommandAst, true);
391391
foreach (CommandAst commandAst in commandAsts)
392392
{
393-
List<Ast> commandParameterAstElements = commandAst.FindAll(testAst => true, searchNestedScriptBlocks: false).ToList();
393+
List<Ast> commandParameterAstElements = commandAst.FindAll(
394+
testAst => testAst.Parent == commandAst, searchNestedScriptBlocks: false).ToList();
394395
for (int i = 0; i < commandParameterAstElements.Count - 1; i++)
395396
{
396397
IScriptExtent leftExtent = commandParameterAstElements[i].Extent;

Tests/Rules/UseConsistentWhitespace.tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,11 @@ bar -h i `
474474
}
475475

476476
It "Should fix script to always have 1 space between parameters except when using colon syntax but not by default" {
477-
$def = 'foo -bar $baz -ParameterName: $ParameterValue'
477+
$def = 'foo -bar $baz -ParameterName: $ParameterValue "$PSScriptRoot\module.psd1"'
478478
Invoke-Formatter -ScriptDefinition $def |
479479
Should -BeExactly $def -Because 'CheckParameter configuration is not turned on by default (yet) as the setting is new'
480480
Invoke-Formatter -ScriptDefinition $def -Settings $settings |
481-
Should -BeExactly 'foo -bar $baz -ParameterName: $ParameterValue'
481+
Should -BeExactly 'foo -bar $baz -ParameterName: $ParameterValue "$PSScriptRoot\module.psd1"'
482482
}
483483

484484
It "Should fix script when newlines are involved" {

0 commit comments

Comments
 (0)