Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for PSUseConsistantWhiteSpace when using statement is present #2091

Merged
merged 6 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Engine/FindAstPositionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit

public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatementAst)
{
return Visit(usingStatementAst);
return AstVisitAction.Continue;
}
#endif

Expand Down
17 changes: 15 additions & 2 deletions Tests/Rules/UseConsistentWhitespace.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 namespace System.IO

$ht = @{
variable = 3
other = 4
}
'@
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty
}

It "Should not find violation if assignment operator is in multi-line hash table" {
$def = @'
$ht = @{
Expand Down Expand Up @@ -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 |
Expand Down