Skip to content

Commit

Permalink
fix: enable prefer-nullish-coalescing eslint rule (eclipse-thingweb#1123
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JKRhb authored Oct 16, 2023
1 parent e7e8fc7 commit 595d818
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": ["error"],
"@typescript-eslint/prefer-nullish-coalescing": "error",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-http/src/codecs/tuya-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class HttpTuyaCodec implements ContentCodec {
const success = parsedBody.success ?? false;

if (!success) {
throw new Error(parsedBody.msg != null ? parsedBody.msg : JSON.stringify(parsedBody));
throw new Error(parsedBody.msg ?? JSON.stringify(parsedBody));
}

for (const value of Object.values(parsedBody.result ?? {})) {
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-mbus/src/mbus-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class MBusClient implements ProtocolClient {
debug(`Creating new MbusConnection for ${hostAndPort}`);
this._connections.set(
hostAndPort,
new MBusConnection(host, port, { connectionTimeout: form["mbus:timeout"] || DEFAULT_TIMEOUT })
new MBusConnection(host, port, { connectionTimeout: form["mbus:timeout"] ?? DEFAULT_TIMEOUT })
);
connection = this._connections.get(hostAndPort);
if (!connection) {
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-modbus/src/modbus-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class ModbusClient implements ProtocolClient {
debug(`Creating new ModbusConnection for ${hostAndPort}`);

connection = new ModbusConnection(host, port, {
connectionTimeout: form["modbus:timeout"] || DEFAULT_TIMEOUT,
connectionTimeout: form["modbus:timeout"] ?? DEFAULT_TIMEOUT,
});
this._connections.set(hostAndPort, connection);
} else {
Expand Down
8 changes: 4 additions & 4 deletions packages/binding-netconf/src/netconf-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export default class NetconfClient implements ProtocolClient {
const port = parseInt(url.port);
const xpathQuery = url.pathname;
const method = this.methodFromForm(form, "EDIT-CONFIG");
let NSs = form["nc:NSs"] || {};
const target = form["nc:target"] || DEFAULT_TARGET;
let NSs = form["nc:NSs"] ?? {};
const target = form["nc:target"] ?? DEFAULT_TARGET;

if (this.client.getRouter() === null) {
try {
Expand Down Expand Up @@ -112,8 +112,8 @@ export default class NetconfClient implements ProtocolClient {
const port = parseInt(url.port);
const xpathQuery = url.pathname;
const method = this.methodFromForm(form, "RPC");
let NSs = form["nc:NSs"] || {};
const target = form["nc:target"] || DEFAULT_TARGET;
let NSs = form["nc:NSs"] ?? {};
const target = form["nc:target"] ?? DEFAULT_TARGET;
let result: string;

if (this.client.getRouter() === null) {
Expand Down
12 changes: 6 additions & 6 deletions packages/binding-opcua/src/opcua-protocol-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function findBasicDataTypeC(
return callback(new Error("Internal Error"));
}

browseResult.references = browseResult.references || /* istanbul ignore next */ [];
browseResult.references = browseResult.references ?? /* istanbul ignore next */ [];
const baseDataType = browseResult.references[0].nodeId;
return findBasicDataTypeC(session, baseDataType, callback);
});
Expand Down Expand Up @@ -335,7 +335,7 @@ export class OPCUAProtocolClient implements ProtocolClient {
session,
form,
argumentDefinition,
callResult.outputArguments || []
callResult.outputArguments ?? []
);
return output;
});
Expand Down Expand Up @@ -571,7 +571,7 @@ export class OPCUAProtocolClient implements ProtocolClient {

const { name, dataType, /* description, */ arrayDimensions, valueRank } = argument;

if (bodyInput[name || "null"] === undefined) {
if (bodyInput[name ?? "null"] === undefined) {
throw new Error("missing value in bodyInput for argument " + name);
}
const basicDataType = await this._findBasicDataType(session, dataType);
Expand All @@ -587,7 +587,7 @@ export class OPCUAProtocolClient implements ProtocolClient {
: VariantArrayType.Matrix;

const n = (a: unknown) => Buffer.from(JSON.stringify(a));
const v = await this._contentToVariant(content2.type, n(bodyInput[name || "null"]), basicDataType);
const v = await this._contentToVariant(content2.type, n(bodyInput[name ?? "null"]), basicDataType);

variants.push({
dataType: basicDataType,
Expand All @@ -607,14 +607,14 @@ export class OPCUAProtocolClient implements ProtocolClient {
): Promise<Content> {
const outputArguments = (argumentDefinition.outputArguments || []) as unknown as Argument[];

const contentType = form.contentType || "application/json";
const contentType = form.contentType ?? "application/json";

const body: Record<string, unknown> = {};
for (let index = 0; index < outputArguments.length; index++) {
const argument = outputArguments[index];
const { name } = argument;
const element = _variantToJSON(outputVariants[index], contentType);
body[name || "null"] = element;
body[name ?? "null"] = element;
}

return new Content("application/json", Readable.from(JSON.stringify(body)));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codecs/text-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class TextCodec implements ContentCodec {
private subMediaType: string;

constructor(subMediaType?: string) {
this.subMediaType = subMediaType == null ? "text/plain" : subMediaType;
this.subMediaType = subMediaType ?? "text/plain";
}

getMediaType(): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/td-tools/src/thing-model-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export class ThingModelHelpers {
const regex = "{{.*?}}";
const modelString = JSON.stringify(model);
// first check if model needs map
let keys: string[] = modelString.match(new RegExp(regex, "g")) || [];
let keys: string[] = modelString.match(new RegExp(regex, "g")) ?? [];
keys = keys.map((el) => el.replace("{{", "").replace("}}", ""));
let isValid = true;
let errors;
Expand Down

0 comments on commit 595d818

Please sign in to comment.