Skip to content

Commit

Permalink
chore(examples): enable eslint/strict-boolean-expressions and strictN…
Browse files Browse the repository at this point in the history
…ullChecks
  • Loading branch information
danielpeintner committed Sep 22, 2023
1 parent a38b05b commit 71bb9dd
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
11 changes: 6 additions & 5 deletions examples/scripts/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/smart-coffee-machine-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions examples/scripts/smart-coffee-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand All @@ -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);
}
5 changes: 4 additions & 1 deletion packages/examples/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "../../.eslintrc.js"
"extends": "../../.eslintrc.js",
"rules": {
"@typescript-eslint/strict-boolean-expressions": ["error"]
}
}
6 changes: 3 additions & 3 deletions packages/examples/src/scripts/countdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ WoT.produce({
"startCountdown",
async (params: WoT.InteractionOutput, options): Promise<WoT.InteractionInput> => {
let initValue = 100;
if (params) {
if (params != null) {
const value = await params.value();
if (typeof value === "number") {
initValue = value as number;
Expand All @@ -147,7 +147,7 @@ WoT.produce({
thing.setActionHandler(
"stopCountdown",
async (params: WoT.InteractionOutput, options): Promise<WoT.InteractionInput> => {
if (params) {
if (params != null) {
const value = await params.value();
if (typeof value === "string" && countdowns.has(value)) {
const as = countdowns.get(value);
Expand All @@ -170,7 +170,7 @@ WoT.produce({
thing.setActionHandler(
"monitorCountdown",
async (params: WoT.InteractionOutput, options): Promise<WoT.InteractionInput> => {
if (params) {
if (params != null) {
const value = await params.value();
if (typeof value === "string" && countdowns.has(value)) {
const as = countdowns.get(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
if (makeCoffeep.result) {
if (makeCoffeep.result != null) {
log("Enjoy your drink!", makeCoffeep);
} else {
log("Failed making your drink:", makeCoffeep);
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/scripts/smart-coffee-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>; // : 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";
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"target": "ES2018",
"sourceMap": false,
"removeComments": false
"removeComments": false,
"strictNullChecks": true
},
"include": ["src/**/*"],
"references": [{ "path": "../td-tools" }]
Expand Down

0 comments on commit 71bb9dd

Please sign in to comment.