Skip to content

Commit 3943377

Browse files
committed
Check more operators
1 parent d3da1e4 commit 3943377

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Rules/UseConsistentWhitespace.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,29 @@ private IEnumerable<DiagnosticRecord> FindOperatorViolations(TokenOperations tok
547547
else if (tokenHasBinaryFlag // binary flag is set but not unary
548548
// include other (non-expression) binary operators
549549
|| TokenTraits.HasTrait(tokenNode.Value.Kind, TokenFlags.AssignmentOperator)
550+
|| tokenNode.Value.Kind == TokenKind.Redirection
550551
|| tokenNode.Value.Kind == TokenKind.AndAnd
551552
|| tokenNode.Value.Kind == TokenKind.OrOr
553+
#if !(NET452 || PSV6) // include both parts of ternary operator but only for PS7+
554+
|| TokenTraits.HasTrait(tokenNode.Value.Kind, TokenFlags.TernaryOperator)
555+
|| tokenNode.Value.Kind == TokenKind.Colon
556+
#endif
552557
) {
553558
checkLeftSide = true;
554559
checkRightSide = true;
555560
}
561+
// Treat call and dot source operators as unary with operand on right.
562+
else if ((tokenNode.Value.Kind == TokenKind.Dot || tokenNode.Value.Kind == TokenKind.Ampersand)
563+
&& tokenOperations.GetAstPosition(tokenNode.Value) is CommandAst)
564+
{
565+
checkRightSide = true;
566+
}
567+
#if !(NET452) // Treat background operator as unary with operand on left (only exists in PS6+)
568+
else if (tokenNode.Value.Kind == TokenKind.Ampersand)
569+
{
570+
checkLeftSide = true;
571+
}
572+
#endif
556573
else // Token is not an operator
557574
{
558575
continue;

0 commit comments

Comments
 (0)