Skip to content

Commit

Permalink
fixup! refactor: enable strict-boolean-expressions globally
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 17, 2023
1 parent 137ac46 commit df58d57
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/binding-modbus/src/modbus-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class ModbusClient implements ProtocolClient {
const parsed = new URL(form.href);
const port = parsed.port ? parseInt(parsed.port, 10) : DEFAULT_PORT;
let body;
if (content) {
if (content != null) {
body = await content.toBuffer();
}
const formValidated = this.validateAndFillDefaultForm(form, body?.byteLength);
Expand All @@ -160,7 +160,7 @@ export default class ModbusClient implements ProtocolClient {
const host = parsed.hostname;
const hostAndPort = host + ":" + port;

if (body) {
if (body != null) {
this.validateBufferLength(formValidated, body);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/binding-mqtt/src/mqtt-broker-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class MqttBrokerServer implements ProtocolServer {
const topic = encodeURIComponent(name) + "/properties/" + encodeURIComponent(propertyName);
const property = thing.properties[propertyName];

const writeOnly = property.writeOnly ?? false;
const writeOnly: boolean = property.writeOnly ?? false;
if (!writeOnly) {
const href = this.brokerURI + "/" + topic;
const form = new TD.Form(href, ContentSerdes.DEFAULT);
Expand All @@ -167,7 +167,7 @@ export default class MqttBrokerServer implements ProtocolServer {
};
thing.handleObserveProperty(propertyName, observeListener, { formIndex: property.forms.length - 1 });
}
const readOnly = property.readOnly ?? false;
const readOnly: boolean = property.readOnly ?? false;
if (!readOnly) {
const href = this.brokerURI + "/" + topic + "/writeproperty";
this.broker.subscribe(topic + "/writeproperty");
Expand Down Expand Up @@ -236,7 +236,7 @@ export default class MqttBrokerServer implements ProtocolServer {
// connecting to the actions
debug(`MqttBrokerServer at ${this.brokerURI} received message for '${receivedTopic}'`);
const thing = this.things.get(segments[this.THING_NAME_SEGMENT_INDEX]);
if (thing) {
if (thing != null) {
if (segments[this.INTERACTION_TYPE_SEGMENT_INDEX] === "actions") {
const action = thing.actions[segments[this.INTERACTION_NAME_SEGMENT_INDEX]];
if (action != null) {
Expand All @@ -251,7 +251,7 @@ export default class MqttBrokerServer implements ProtocolServer {
) {
// connecting to the writeable properties
const thing = this.things.get(segments[this.THING_NAME_SEGMENT_INDEX]);
if (thing) {
if (thing != null) {
if (segments[this.INTERACTION_TYPE_SEGMENT_INDEX] === "properties") {
const property = thing.properties[segments[this.INTERACTION_NAME_SEGMENT_INDEX]];
if (property != null) {
Expand Down Expand Up @@ -364,7 +364,7 @@ export default class MqttBrokerServer implements ProtocolServer {
}
}

if (removedThing) {
if (removedThing != null) {
info(`MqttBrokerServer succesfully destroyed '${removedThing.title}'`);
} else {
info(`MqttBrokerServer failed to destroy thing with thingId '${thingId}'`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("MQTT client implementation", () => {
if (!eventReceived) {
eventReceived = true;
} else {
if (!x.data) {
if (x.data == null) {
done(new Error("No data received"));
return;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ describe("MQTT client implementation", () => {
if (!eventReceived) {
eventReceived = true;
} else {
if (!x.data) {
if (x.data == null) {
done(new Error("No data received"));
return;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/binding-opcua/src/opcua-protocol-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class OPCUAProtocolClient implements ProtocolClient {

private async _withConnection<T>(form: OPCUAForm, next: (connection: OPCUAConnection) => Promise<T>): Promise<T> {
const endpoint = form.href;
if (!endpoint || !endpoint.match(/^opc.tcp:\/\//)) {
const matchesScheme: boolean = endpoint?.match(/^opc.tcp:\/\//) != null;
if (!matchesScheme) {
debug(`invalid opcua:endpoint ${endpoint} specified`);
throw new Error("Invalid OPCUA endpoint " + endpoint);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/binding-websockets/src/ws-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export default class WebSocketServer implements ProtocolServer {
const form = new TD.Form(href, ContentSerdes.DEFAULT);
const ops = [];

const writeOnly = property.writeOnly ?? false;
const readOnly = property.readOnly ?? false;
const writeOnly: boolean = property.writeOnly ?? false;
const readOnly: boolean = property.readOnly ?? false;

if (!writeOnly) {
ops.push("readproperty", "observeproperty", "unobserveproperty");
Expand Down Expand Up @@ -209,7 +209,8 @@ export default class WebSocketServer implements ProtocolServer {
}
};

if (property.writeOnly ?? false) {
const writeOnly: boolean = property.writeOnly ?? false;
if (writeOnly) {
for (let formIndex = 0; formIndex < thing.properties[propertyName].forms.length; formIndex++) {
thing
.handleObserveProperty(propertyName, observeListener, { formIndex })
Expand Down

0 comments on commit df58d57

Please sign in to comment.