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

Commit

Permalink
Fix lint errors in restrictPlusOperandsRule.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Apr 16, 2019
1 parent 3dc40d0 commit 110afa0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/rules/restrictPlusOperandsRule.ts
Expand Up @@ -51,8 +51,16 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {
const leftTypeStr = getBaseTypeOfLiteralType(leftType);
const rightType = tc.getTypeAtLocation(node.right);
const rightTypeStr = getBaseTypeOfLiteralType(rightType);
if (leftTypeStr === "invalid" || rightTypeStr === "invalid" || leftTypeStr !== rightTypeStr) {
const actualTypes = `, but found ${getTypeString(tc, node.left, leftType)} + ${getTypeString(tc, node.right, rightType)}`;
if (
leftTypeStr === "invalid" ||
rightTypeStr === "invalid" ||
leftTypeStr !== rightTypeStr
) {
const actualTypes = `, but found ${getTypeString(
tc,
node.left,
leftType,
)} + ${getTypeString(tc, node.right, rightType)}`;
let message = Rule.INVALID_TYPES_ERROR + actualTypes;
if (leftTypeStr === "string" || rightTypeStr === "string") {
message += Rule.SUGGEST_TEMPLATE_LITERALS;
Expand All @@ -66,7 +74,11 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) {

function getTypeString(tc: ts.TypeChecker, node: ts.Node, type: ts.Type) {
const typeString = tc.typeToString(type, node);
if (typeString === "undefined[]" && ts.isArrayLiteralExpression(node) && !node.elements.length) {
if (
typeString === "undefined[]" &&
ts.isArrayLiteralExpression(node) &&
node.elements.length === 0
) {
// Special case literal "[]" arrays that would otherwise be emitted as undefined[].
return "[]";
}
Expand Down

0 comments on commit 110afa0

Please sign in to comment.