Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

binary-expression-operand-order: Allow both sides to be literals #2873

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
2 changes: 1 addition & 1 deletion src/rules/binaryExpressionOperandOrderRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Rule extends Lint.Rules.AbstractRule {

function walk(ctx: Lint.WalkContext<void>): void {
ts.forEachChild(ctx.sourceFile, function cb(node) {
if (isBinaryExpression(node) && isLiteral(node.left) && !isAllowedOrderedOperator(node)) {
if (isBinaryExpression(node) && isLiteral(node.left) && !isLiteral(node.right) && !isAllowedOrderedOperator(node)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
ts.forEachChild(node, cb);
Expand Down
6 changes: 6 additions & 0 deletions test/rules/binary-expression-operand-order/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ undefined != x;
"key" in x;
"foo", x;

// Allows literals on both sides.
1 + 1;
1 + 1 + 1;
1 + x + 1;
~~~~~ [0]

[0]: Literal expression should be on the right-hand side of a binary expression.