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

UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace configuration #1349

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: 2 additions & 0 deletions Rules/UseConsistentWhitespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ private IEnumerable<DiagnosticRecord> FindInnerBraceViolations(TokenOperations t
|| !IsPreviousTokenOnSameLine(lCurly)
|| lCurly.Next.Value.Kind == TokenKind.NewLine
|| lCurly.Next.Value.Kind == TokenKind.LineContinuation
|| lCurly.Next.Value.Kind == TokenKind.RCurly
)
{
continue;
Expand All @@ -268,6 +269,7 @@ private IEnumerable<DiagnosticRecord> FindInnerBraceViolations(TokenOperations t
|| rCurly.Previous.Value.Kind == TokenKind.LCurly
|| rCurly.Previous.Value.Kind == TokenKind.NewLine
|| rCurly.Previous.Value.Kind == TokenKind.LineContinuation
|| rCurly.Previous.Value.Kind == TokenKind.AtCurly
)
{
continue;
Expand Down
17 changes: 14 additions & 3 deletions Tests/Rules/UseConsistentWhitespace.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,15 @@ foo
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
Test-CorrectionExtentFromContent $def $violations 1 '' ' '
}

It "Should find a violation if there is more than 1 space inside empty curly braces" {
$def = 'if($true) { }'

It "Should find a violation if there is more than 1 space after opening brace" {
$def = 'if($true) { Get-Item }'
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
}

It "Should find a violation if there is more than 1 space before closing brace" {
$def = 'if($true) { Get-Item }'
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
}
Expand All @@ -344,6 +350,11 @@ foo
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
}

It "Should not find a violation for an empty hashtable" {
$def = '$hashtable = @{}'
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
}

It "Should not find a violation if a new-line is after the opening brace" {
$def = @'
if ($true) {
Expand Down