Skip to content

Commit 2287a13

Browse files
AlexandraDoreyAlexandra Doreybergmeister
authored
Fix for PSUseConsistantWhiteSpace when using statement is present (#2091)
* Add failng test that should pass * Try simple fix * Test and Fix for test * Update Tests/Rules/UseConsistentWhitespace.tests.ps1 Co-authored-by: Christoph Bergmeister <[email protected]> * Fix encoding --------- Co-authored-by: Alexandra Dorey <[email protected]> Co-authored-by: Christoph Bergmeister <[email protected]>
1 parent ea73edc commit 2287a13

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Engine/FindAstPositionVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
333333

334334
public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatementAst)
335335
{
336-
return Visit(usingStatementAst);
336+
return AstVisitAction.Continue;
337337
}
338338
#endif
339339

Tests/Rules/UseConsistentWhitespace.tests.ps1

+15-2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ $ht = @{
212212
$ruleConfiguration.CheckSeparator = $false
213213
$ruleConfiguration.IgnoreAssignmentOperatorInsideHashTable = $true
214214
}
215+
216+
It "Should not find violation if assignment operator is in multi-line hash table and a using statement is present" {
217+
$def = @'
218+
using namespace System.IO
219+
220+
$ht = @{
221+
variable = 3
222+
other = 4
223+
}
224+
'@
225+
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty
226+
}
227+
215228
It "Should not find violation if assignment operator is in multi-line hash table" {
216229
$def = @'
217230
$ht = @{
@@ -628,11 +641,11 @@ bar -h i `
628641
}
629642

630643
It "Should fix script when a parameter value is a script block spanning multiple lines" {
631-
$def = {foo {
644+
$def = {foo {
632645
bar
633646
} -baz}
634647

635-
$expected = {foo {
648+
$expected = {foo {
636649
bar
637650
} -baz}
638651
Invoke-Formatter -ScriptDefinition "$def" -Settings $settings |

0 commit comments

Comments
 (0)