Skip to content

Commit 0637a36

Browse files
author
Kapil Borle
committed
Ignore no whitespace if new line after binary operator
1 parent 14121d1 commit 0637a36

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Rules/UseConsistentWhitespace.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ private IEnumerable<DiagnosticRecord> FindOperatorViolations(TokenOperations tok
315315
}
316316

317317
var hasWhitespaceBefore = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode);
318-
var hasWhitespaceAfter = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next);
318+
var hasWhitespaceAfter = tokenNode.Next.Value.Kind == TokenKind.NewLine
319+
|| IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next);
319320

320321
if (!hasWhitespaceAfter || !hasWhitespaceBefore)
321322
{

Tests/Rules/UseConsistentWhitespace.tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ $x = 1
173173
'@
174174
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null
175175
}
176+
177+
It "Should not find violation if a binary operator is followed by new line" {
178+
$def = @'
179+
$x = $true -and
180+
$false
181+
'@
182+
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null
183+
}
184+
176185
}
177186

178187
Context "When a comma is not followed by a space" {

0 commit comments

Comments
 (0)