Skip to content

Commit

Permalink
chore(binding-coap): enable strict-boolean-expressions and null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 18, 2023
1 parent 227be53 commit ea9a4c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
5 changes: 4 additions & 1 deletion packages/binding-coap/.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"]
}
}
13 changes: 6 additions & 7 deletions packages/binding-coap/src/coap-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class CoapClient implements ProtocolClient {
});
req.on("error", (err: Error) => reject(err));
(async () => {
if (content && content.body) {
if (content != null) {
const buffer = await content.toBuffer();
req.setOption("Content-Format", content.type);
req.write(buffer);
Expand Down Expand Up @@ -159,8 +159,7 @@ export default class CoapClient implements ProtocolClient {
debug(`CoapClient received Content-Format: ${res.headers["Content-Format"]}`);

// FIXME does not work with blockwise because of node-coap
let contentType = res.headers["Content-Format"];
if (!contentType) contentType = form.contentType;
const contentType = res.headers["Content-Format"] ?? form.contentType ?? ContentSerdes.DEFAULT;

res.on("data", (data: Buffer) => {
next(new Content(`${contentType}`, Readable.from(res.payload)));
Expand Down Expand Up @@ -203,10 +202,10 @@ export default class CoapClient implements ProtocolClient {

const options: CoapRequestParams = {
agent: this.agent,
hostname: requestUri.hostname || "",
port: requestUri.port ? parseInt(requestUri.port, 10) : 5683,
pathname: requestUri.pathname || "",
query: requestUri.query || "",
hostname: requestUri.hostname ?? "",
port: requestUri.port != null ? parseInt(requestUri.port, 10) : 5683,
pathname: requestUri.pathname ?? "",
query: requestUri.query ?? "",
observe: false,
multicast: false,
confirmable: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,7 @@ export default class CoapServer implements ProtocolServer {
res.end();

res.on("finish", (err: Error) => {
if (err) {
error(`CoapServer on port ${this.port} failed on observe with: ${err.message}`);
}
error(`CoapServer on port ${this.port} failed on observe with: ${err.message}`);
thing.handleUnobserveProperty(affordanceKey, listener, interactionOptions);
});

Expand Down
3 changes: 2 additions & 1 deletion packages/binding-coap/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": ".."
"rootDir": "..",
"strictNullChecks": true
},
"include": ["*.ts", "**/*.ts", "../src/**/*.ts"]
}

0 comments on commit ea9a4c8

Please sign in to comment.