Skip to content

Commit e461f10

Browse files
authored
UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace configuration (#1349)
* UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace configuration * tweak test
1 parent 2260653 commit e461f10

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Rules/UseConsistentWhitespace.cs

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ private IEnumerable<DiagnosticRecord> FindInnerBraceViolations(TokenOperations t
243243
|| !IsPreviousTokenOnSameLine(lCurly)
244244
|| lCurly.Next.Value.Kind == TokenKind.NewLine
245245
|| lCurly.Next.Value.Kind == TokenKind.LineContinuation
246+
|| lCurly.Next.Value.Kind == TokenKind.RCurly
246247
)
247248
{
248249
continue;
@@ -268,6 +269,7 @@ private IEnumerable<DiagnosticRecord> FindInnerBraceViolations(TokenOperations t
268269
|| rCurly.Previous.Value.Kind == TokenKind.LCurly
269270
|| rCurly.Previous.Value.Kind == TokenKind.NewLine
270271
|| rCurly.Previous.Value.Kind == TokenKind.LineContinuation
272+
|| rCurly.Previous.Value.Kind == TokenKind.AtCurly
271273
)
272274
{
273275
continue;

Tests/Rules/UseConsistentWhitespace.tests.ps1

+14-3
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,15 @@ foo
327327
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
328328
Test-CorrectionExtentFromContent $def $violations 1 '' ' '
329329
}
330-
331-
It "Should find a violation if there is more than 1 space inside empty curly braces" {
332-
$def = 'if($true) { }'
330+
331+
It "Should find a violation if there is more than 1 space after opening brace" {
332+
$def = 'if($true) { Get-Item }'
333+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
334+
Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
335+
}
336+
337+
It "Should find a violation if there is more than 1 space before closing brace" {
338+
$def = 'if($true) { Get-Item }'
333339
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
334340
Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
335341
}
@@ -344,6 +350,11 @@ foo
344350
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
345351
}
346352

353+
It "Should not find a violation for an empty hashtable" {
354+
$def = '$hashtable = @{}'
355+
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
356+
}
357+
347358
It "Should not find a violation if a new-line is after the opening brace" {
348359
$def = @'
349360
if ($true) {

0 commit comments

Comments
 (0)