Skip to content

Commit

Permalink
UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace c…
Browse files Browse the repository at this point in the history
…onfiguration (PowerShell#1349)

* UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace configuration

* tweak test
  • Loading branch information
bergmeister committed Oct 7, 2019
1 parent 2260653 commit e461f10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit e461f10

Please sign in to comment.