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

Commit

Permalink
binary-expression-operand-order: Allow both sides to be literals (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and adidahiya committed Jun 5, 2017
1 parent a88462d commit df7594b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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.

0 comments on commit df7594b

Please sign in to comment.