From c8973f657959503794d532d7aa97be8d469ec392 Mon Sep 17 00:00:00 2001 From: pamapa Date: Tue, 24 Aug 2021 09:35:58 +0200 Subject: [PATCH] feat: #4 reduce eslint errors of restrict-plus-operands --- src/utils/JoseUtil.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/utils/JoseUtil.ts b/src/utils/JoseUtil.ts index 703e3e641..7f88e072b 100644 --- a/src/utils/JoseUtil.ts +++ b/src/utils/JoseUtil.ts @@ -46,8 +46,7 @@ export class JoseUtil { } } else { Log.error("JoseUtil.validateJwt: Unsupported key type", key && key.kty); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("Unsupported key type: " + key && key.kty); + throw new Error("Unsupported key type: " + (key ? String(key.kty) : "undefined")); } return JoseUtil._validateJwt(jwt, key, issuer, audience, clockSkew, now, timeInsensitive); @@ -74,8 +73,7 @@ export class JoseUtil { } if (payload.iss !== issuer) { Log.error("JoseUtil._validateJwt: Invalid issuer in token", payload.iss); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("Invalid issuer in token: " + payload.iss); + throw new Error("Invalid issuer in token: " + String(payload.iss)); } if (!payload.aud) { @@ -85,13 +83,11 @@ export class JoseUtil { const validAudience = payload.aud === audience || (Array.isArray(payload.aud) && payload.aud.indexOf(audience) >= 0); if (!validAudience) { Log.error("JoseUtil._validateJwt: Invalid audience in token", payload.aud); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("Invalid audience in token: " + payload.aud); + throw new Error("Invalid audience in token: " + String(payload.aud)); } if (payload.azp && payload.azp !== audience) { Log.error("JoseUtil._validateJwt: Invalid azp in token", payload.azp); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("Invalid azp in token: " + payload.azp); + throw new Error("Invalid azp in token: " + String(payload.azp)); } if (!timeInsensitive) { @@ -104,14 +100,12 @@ export class JoseUtil { } if (lowerNow < payload.iat) { Log.error("JoseUtil._validateJwt: iat is in the future", payload.iat); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("iat is in the future: " + payload.iat); + throw new Error("iat is in the future: " + String(payload.iat)); } if (payload.nbf && lowerNow < payload.nbf) { Log.error("JoseUtil._validateJwt: nbf is in the future", payload.nbf); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("nbf is in the future: " + payload.nbf); + throw new Error("nbf is in the future: " + String(payload.nbf)); } if (!payload.exp) { @@ -120,8 +114,7 @@ export class JoseUtil { } if (payload.exp < upperNow) { Log.error("JoseUtil._validateJwt: exp is in the past", payload.exp); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - throw new Error("exp is in the past:" + payload.exp); + throw new Error("exp is in the past: " + String(payload.exp)); } }