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

Commit b55a9f9

Browse files
ajafffjkillian
authored andcommitted
Fix regression in restrict-plus-operands (#2454)
Fixes: #2443 [bugfix] `restrict-plus-operands` fixes regression where every assignment and comparison was checked
1 parent 4e06c18 commit b55a9f9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/rules/restrictPlusOperandsRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Rule extends Lint.Rules.TypedRule {
4343

4444
function walk(ctx: Lint.WalkContext<void>, program: ts.Program) {
4545
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
46-
if (isBinaryExpression(node)) {
46+
if (isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
4747
const tc = program.getTypeChecker();
4848
const leftType = getBaseTypeOfLiteralType(tc.getTypeAtLocation(node.left));
4949
const rightType = getBaseTypeOfLiteralType(tc.getTypeAtLocation(node.right));

test/rules/restrict-plus-operands/test.ts.lint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ var good7 = pair.first + (10 as MyNumber);
5959
var good8 = "5.5" + pair.second;
6060
var good9 = ("5.5" as MyString) + pair.second;
6161
const good10 = 'hello' + (someBoolean ? 'a' : 'b') + (() => someBoolean ? 'c' : 'd')() + 'e';
62+
63+
// don't check other binary expressions
64+
const balls = true;
65+
balls === true;

0 commit comments

Comments
 (0)