Skip to content
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
5 changes: 5 additions & 0 deletions Rules/UseConsistentWhitespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ private static bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> token

private static bool IsPreviousTokenApartByWhitespace(LinkedListNode<Token> 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;
Expand Down
16 changes: 13 additions & 3 deletions Tests/Rules/UseConsistentWhitespace.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Expand Down