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

Commit 110afa0

Browse files
committed
Fix lint errors in restrictPlusOperandsRule.ts
1 parent 3dc40d0 commit 110afa0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/rules/restrictPlusOperandsRule.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {
5151
const leftTypeStr = getBaseTypeOfLiteralType(leftType);
5252
const rightType = tc.getTypeAtLocation(node.right);
5353
const rightTypeStr = getBaseTypeOfLiteralType(rightType);
54-
if (leftTypeStr === "invalid" || rightTypeStr === "invalid" || leftTypeStr !== rightTypeStr) {
55-
const actualTypes = `, but found ${getTypeString(tc, node.left, leftType)} + ${getTypeString(tc, node.right, rightType)}`;
54+
if (
55+
leftTypeStr === "invalid" ||
56+
rightTypeStr === "invalid" ||
57+
leftTypeStr !== rightTypeStr
58+
) {
59+
const actualTypes = `, but found ${getTypeString(
60+
tc,
61+
node.left,
62+
leftType,
63+
)} + ${getTypeString(tc, node.right, rightType)}`;
5664
let message = Rule.INVALID_TYPES_ERROR + actualTypes;
5765
if (leftTypeStr === "string" || rightTypeStr === "string") {
5866
message += Rule.SUGGEST_TEMPLATE_LITERALS;
@@ -66,7 +74,11 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {
6674

6775
function getTypeString(tc: ts.TypeChecker, node: ts.Node, type: ts.Type) {
6876
const typeString = tc.typeToString(type, node);
69-
if (typeString === "undefined[]" && ts.isArrayLiteralExpression(node) && !node.elements.length) {
77+
if (
78+
typeString === "undefined[]" &&
79+
ts.isArrayLiteralExpression(node) &&
80+
node.elements.length === 0
81+
) {
7082
// Special case literal "[]" arrays that would otherwise be emitted as undefined[].
7183
return "[]";
7284
}

0 commit comments

Comments
 (0)