diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index f589d9e45..7e2562327 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -483,6 +483,11 @@ private static bool IsPreviousTokenApartByWhitespace(LinkedListNode token private static bool IsPreviousTokenApartByWhitespace(LinkedListNode tokenNode, out bool hasRedundantWhitespace) { + if (tokenNode.Value.Extent.StartLineNumber != tokenNode.Previous.Value.Extent.StartLineNumber) + { + hasRedundantWhitespace = false; + return true; + } var actualWhitespaceSize = tokenNode.Value.Extent.StartColumnNumber - tokenNode.Previous.Value.Extent.EndColumnNumber; hasRedundantWhitespace = actualWhitespaceSize - whiteSpaceSize > 0; return whiteSpaceSize == actualWhitespaceSize; diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 23bf18350..36da74f45 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -39,17 +39,27 @@ Describe "UseWhitespace" { It "Should not find violation if an open brace follows a whitespace" { $def = 'if($true) {}' - Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } It "Should not find violation if an open brace follows a foreach member invocation" { $def = '(1..5).foreach{$_}' - Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } It "Should not find violation if an open brace follows a where member invocation" { $def = '(1..5).where{$_}' - Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty + } + + It "Should not find violation if an open brace is on the next line" { + $def = @' +if ($true) +{ + foo +} +'@ + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } }