diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index f589d9e45..86795d705 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -390,7 +390,8 @@ private IEnumerable FindParameterViolations(Ast ast) testAst => testAst is CommandAst, true); foreach (CommandAst commandAst in commandAsts) { - List commandParameterAstElements = commandAst.FindAll(testAst => true, searchNestedScriptBlocks: false).ToList(); + List commandParameterAstElements = commandAst.FindAll( + testAst => testAst.Parent == commandAst, searchNestedScriptBlocks: false).ToList(); for (int i = 0; i < commandParameterAstElements.Count - 1; i++) { IScriptExtent leftExtent = commandParameterAstElements[i].Extent; diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 23bf18350..38437076e 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -474,11 +474,11 @@ bar -h i ` } It "Should fix script to always have 1 space between parameters except when using colon syntax but not by default" { - $def = 'foo -bar $baz -ParameterName: $ParameterValue' + $def = 'foo -bar $baz -ParameterName: $ParameterValue "$PSScriptRoot\module.psd1"' Invoke-Formatter -ScriptDefinition $def | Should -BeExactly $def -Because 'CheckParameter configuration is not turned on by default (yet) as the setting is new' Invoke-Formatter -ScriptDefinition $def -Settings $settings | - Should -BeExactly 'foo -bar $baz -ParameterName: $ParameterValue' + Should -BeExactly 'foo -bar $baz -ParameterName: $ParameterValue "$PSScriptRoot\module.psd1"' } It "Should fix script when newlines are involved" {