From 05e9bd4235f87c8d2773ad980e8a7f356afc5c2a Mon Sep 17 00:00:00 2001 From: Alexandra Dorey Date: Tue, 1 Apr 2025 19:37:30 -0300 Subject: [PATCH 1/5] Add failng test that should pass --- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 03a6fbc35..d7b640630 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -212,6 +212,19 @@ $ht = @{ $ruleConfiguration.CheckSeparator = $false $ruleConfiguration.IgnoreAssignmentOperatorInsideHashTable = $true } + It "Should not find violation if assignment operator is in multi-line hash table and a using statement is present" { + $def = @' +using system + +$ht = @{ + variable = 3 + other = 4 +} +'@ + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null + } + + It "Should not find violation if assignment operator is in multi-line hash table" { $def = @' $ht = @{ @@ -628,11 +641,11 @@ bar -h i ` } It "Should fix script when a parameter value is a script block spanning multiple lines" { - $def = {foo { + $def = {foo { bar } -baz} - $expected = {foo { + $expected = {foo { bar } -baz} Invoke-Formatter -ScriptDefinition "$def" -Settings $settings | From 1268930a4e4a06bdec8a687024bda1adecadf1d2 Mon Sep 17 00:00:00 2001 From: Alexandra Dorey Date: Tue, 1 Apr 2025 19:52:15 -0300 Subject: [PATCH 2/5] Try simple fix --- Engine/FindAstPositionVisitor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/FindAstPositionVisitor.cs b/Engine/FindAstPositionVisitor.cs index 05532c456..459581cbc 100644 --- a/Engine/FindAstPositionVisitor.cs +++ b/Engine/FindAstPositionVisitor.cs @@ -333,7 +333,7 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatementAst) { - return Visit(usingStatementAst); + return AstVisitAction.Continue; } #endif From 971aac427cc35397422600e92b7b70561954cb60 Mon Sep 17 00:00:00 2001 From: Alexandra Dorey Date: Tue, 1 Apr 2025 20:30:08 -0300 Subject: [PATCH 3/5] Test and Fix for test --- NuGet.Config | 2 +- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index f003b0fbd..20ba1a21a 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,4 +1,4 @@ - + diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index d7b640630..4a8766ab8 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -212,9 +212,10 @@ $ht = @{ $ruleConfiguration.CheckSeparator = $false $ruleConfiguration.IgnoreAssignmentOperatorInsideHashTable = $true } + It "Should not find violation if assignment operator is in multi-line hash table and a using statement is present" { $def = @' -using system +using namespace System.IO $ht = @{ variable = 3 @@ -224,7 +225,6 @@ $ht = @{ Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null } - It "Should not find violation if assignment operator is in multi-line hash table" { $def = @' $ht = @{ From 5fd25d4648c14a5e079a998b6a8f093b676a3dbb Mon Sep 17 00:00:00 2001 From: AlexandraDorey-Magnet <139377801+AlexandraDorey@users.noreply.github.com> Date: Thu, 3 Apr 2025 16:05:55 -0300 Subject: [PATCH 4/5] Update Tests/Rules/UseConsistentWhitespace.tests.ps1 Co-authored-by: Christoph Bergmeister --- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 4a8766ab8..952e49909 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -222,7 +222,7 @@ $ht = @{ other = 4 } '@ - Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } It "Should not find violation if assignment operator is in multi-line hash table" { From 0fe9d12eb8c0b01242a72cbb4830e3565b0b4725 Mon Sep 17 00:00:00 2001 From: Alexandra Dorey Date: Thu, 3 Apr 2025 16:09:13 -0300 Subject: [PATCH 5/5] Fix encoding --- NuGet.Config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuGet.Config b/NuGet.Config index 20ba1a21a..f003b0fbd 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,4 +1,4 @@ - +