From 515ac41ba7c0ce82f386b4031e096068c3611f2f Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 7 Oct 2019 07:41:43 +0100 Subject: [PATCH 1/2] UseConsistentWhitespace: Ignore empty hashtable for CheckInnerBrace configuration --- Rules/UseConsistentWhitespace.cs | 2 ++ Tests/Rules/UseConsistentWhitespace.tests.ps1 | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index f4f2be6ad..e38696bdb 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -243,6 +243,7 @@ private IEnumerable FindInnerBraceViolations(TokenOperations t || !IsPreviousTokenOnSameLine(lCurly) || lCurly.Next.Value.Kind == TokenKind.NewLine || lCurly.Next.Value.Kind == TokenKind.LineContinuation + || lCurly.Next.Value.Kind == TokenKind.RCurly ) { continue; @@ -268,6 +269,7 @@ private IEnumerable 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; diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 24ecbe78a..b81cc9ea6 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -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 ' ' ' ' } @@ -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) { From 7cff5010b70bfc52c937b368d95acf5d431e0f84 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 7 Oct 2019 07:43:24 +0100 Subject: [PATCH 2/2] tweak test --- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index b81cc9ea6..fa6be6769 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -335,7 +335,7 @@ foo } It "Should find a violation if there is more than 1 space before closing brace" { - $def = 'if($true) { Get-Item }' + $def = 'if($true) { Get-Item }' $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' }