From 71bb9dd85566588606f76a41670c912ed05de914 Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Fri, 22 Sep 2023 11:15:42 +0200 Subject: [PATCH] chore(examples): enable eslint/strict-boolean-expressions and strictNullChecks --- examples/scripts/countdown.js | 11 +++++----- .../scripts/smart-coffee-machine-client.js | 2 +- examples/scripts/smart-coffee-machine.js | 20 +++++++++---------- packages/examples/.eslintrc.json | 5 ++++- packages/examples/src/scripts/countdown.ts | 6 +++--- .../scripts/smart-coffee-machine-client.ts | 2 +- .../src/scripts/smart-coffee-machine.ts | 2 +- packages/examples/tsconfig.json | 3 ++- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/examples/scripts/countdown.js b/examples/scripts/countdown.js index 3c4f425bd..b6963f0e9 100644 --- a/examples/scripts/countdown.js +++ b/examples/scripts/countdown.js @@ -80,7 +80,7 @@ WoT.produce({ const listToDelete = []; for (const id of countdowns.keys()) { const as = countdowns.get(id); - if (as !== undefined && as.output !== undefined) { + if ((as === null || as === void 0 ? void 0 : as.output) !== undefined) { const prev = as.output; as.output--; console.log("\t" + id + ", from " + prev + " to " + as.output); @@ -111,8 +111,9 @@ WoT.produce({ }); // set action handlers (using async-await) thing.setActionHandler("startCountdown", async (params, options) => { + var _a; let initValue = 100; - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "number") { initValue = value; @@ -125,11 +126,11 @@ WoT.produce({ }; const ii = resp; console.log("init countdown value = " + JSON.stringify(resp)); - countdowns.set(resp.href !== undefined ? resp.href : "", resp); + countdowns.set((_a = resp.href) !== null && _a !== void 0 ? _a : "", resp); return ii; }); thing.setActionHandler("stopCountdown", async (params, options) => { - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "string" && countdowns.has(value)) { const as = countdowns.get(value); @@ -149,7 +150,7 @@ WoT.produce({ } }); thing.setActionHandler("monitorCountdown", async (params, options) => { - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "string" && countdowns.has(value)) { const as = countdowns.get(value); diff --git a/examples/scripts/smart-coffee-machine-client.js b/examples/scripts/smart-coffee-machine-client.js index 9dba78129..a2ab64378 100644 --- a/examples/scripts/smart-coffee-machine-client.js +++ b/examples/scripts/smart-coffee-machine-client.js @@ -49,7 +49,7 @@ WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) = uriVariables: { drinkId: "latte", size: "l", quantity: 3 }, }); const makeCoffeep = await (makeCoffee === null || makeCoffee === void 0 ? void 0 : makeCoffee.value()); - if (makeCoffeep.result) { + if (makeCoffeep.result != null) { log("Enjoy your drink!", makeCoffeep); } else { log("Failed making your drink:", makeCoffeep); diff --git a/examples/scripts/smart-coffee-machine.js b/examples/scripts/smart-coffee-machine.js index 7ee48f729..9f039eede 100644 --- a/examples/scripts/smart-coffee-machine.js +++ b/examples/scripts/smart-coffee-machine.js @@ -20,6 +20,15 @@ let possibleDrinks; let maintenanceNeeded; let schedules; let servedCounter; +function readFromSensor(sensorType) { + // Actual implementation of reading data from a sensor can go here + // For the sake of example, let's just return a value + return 100; +} +function notify(subscribers, msg) { + // Actual implementation of notifying subscribers with a message can go here + console.log(msg); +} WoT.produce({ title: "Smart-Coffee-Machine", description: `A smart coffee machine with a range of capabilities. @@ -366,7 +375,7 @@ Assumes one medium americano if not specified, but time and mode are mandatory f thing.setActionHandler("setSchedule", async (params, options) => { const paramsp = await params.value(); // : any = await Helpers.parseInteractionOutput(params); // Check if uriVariables are provided - if (paramsp && typeof paramsp === "object" && "time" in paramsp && "mode" in paramsp) { + if (paramsp != null && typeof paramsp === "object" && "time" in paramsp && "mode" in paramsp) { // Use default values if not provided paramsp.drinkId = "drinkId" in paramsp ? paramsp.drinkId : "americano"; paramsp.size = "size" in paramsp ? paramsp.size : "m"; @@ -388,12 +397,3 @@ Assumes one medium americano if not specified, but time and mode are mandatory f .catch((e) => { console.log(e); }); -function readFromSensor(sensorType) { - // Actual implementation of reading data from a sensor can go here - // For the sake of example, let's just return a value - return 100; -} -function notify(subscribers, msg) { - // Actual implementation of notifying subscribers with a message can go here - console.log(msg); -} diff --git a/packages/examples/.eslintrc.json b/packages/examples/.eslintrc.json index c4237119e..70b9f134b 100644 --- a/packages/examples/.eslintrc.json +++ b/packages/examples/.eslintrc.json @@ -1,3 +1,6 @@ { - "extends": "../../.eslintrc.js" + "extends": "../../.eslintrc.js", + "rules": { + "@typescript-eslint/strict-boolean-expressions": ["error"] + } } diff --git a/packages/examples/src/scripts/countdown.ts b/packages/examples/src/scripts/countdown.ts index fa7c2e25c..a0a31c3df 100644 --- a/packages/examples/src/scripts/countdown.ts +++ b/packages/examples/src/scripts/countdown.ts @@ -127,7 +127,7 @@ WoT.produce({ "startCountdown", async (params: WoT.InteractionOutput, options): Promise => { let initValue = 100; - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "number") { initValue = value as number; @@ -147,7 +147,7 @@ WoT.produce({ thing.setActionHandler( "stopCountdown", async (params: WoT.InteractionOutput, options): Promise => { - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "string" && countdowns.has(value)) { const as = countdowns.get(value); @@ -170,7 +170,7 @@ WoT.produce({ thing.setActionHandler( "monitorCountdown", async (params: WoT.InteractionOutput, options): Promise => { - if (params) { + if (params != null) { const value = await params.value(); if (typeof value === "string" && countdowns.has(value)) { const as = countdowns.get(value); diff --git a/packages/examples/src/scripts/smart-coffee-machine-client.ts b/packages/examples/src/scripts/smart-coffee-machine-client.ts index 05e745c35..4fffb504c 100644 --- a/packages/examples/src/scripts/smart-coffee-machine-client.ts +++ b/packages/examples/src/scripts/smart-coffee-machine-client.ts @@ -61,7 +61,7 @@ WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) = uriVariables: { drinkId: "latte", size: "l", quantity: 3 }, }); const makeCoffeep = (await makeCoffee?.value()) as Record; - if (makeCoffeep.result) { + if (makeCoffeep.result != null) { log("Enjoy your drink!", makeCoffeep); } else { log("Failed making your drink:", makeCoffeep); diff --git a/packages/examples/src/scripts/smart-coffee-machine.ts b/packages/examples/src/scripts/smart-coffee-machine.ts index 896ebe947..b18ef02a5 100644 --- a/packages/examples/src/scripts/smart-coffee-machine.ts +++ b/packages/examples/src/scripts/smart-coffee-machine.ts @@ -396,7 +396,7 @@ Assumes one medium americano if not specified, but time and mode are mandatory f const paramsp = (await params.value()) as Record; // : any = await Helpers.parseInteractionOutput(params); // Check if uriVariables are provided - if (paramsp && typeof paramsp === "object" && "time" in paramsp && "mode" in paramsp) { + if (paramsp != null && typeof paramsp === "object" && "time" in paramsp && "mode" in paramsp) { // Use default values if not provided paramsp.drinkId = "drinkId" in paramsp ? paramsp.drinkId : "americano"; paramsp.size = "size" in paramsp ? paramsp.size : "m"; diff --git a/packages/examples/tsconfig.json b/packages/examples/tsconfig.json index 63049fbba..a563b226b 100644 --- a/packages/examples/tsconfig.json +++ b/packages/examples/tsconfig.json @@ -5,7 +5,8 @@ "rootDir": "src", "target": "ES2018", "sourceMap": false, - "removeComments": false + "removeComments": false, + "strictNullChecks": true }, "include": ["src/**/*"], "references": [{ "path": "../td-tools" }]