From 06050cb9e0b27a7e32f1346b1809fad7b9b0a82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= Date: Fri, 25 Aug 2023 15:17:26 +0200 Subject: [PATCH 1/4] fix: 117:101 error Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator @typescript-eslint/prefer-nullish-coalescing --- dev/ts/pages/index.ts | 2 +- dev/ts/shared/main.ts | 4 ++-- src/component/helpers/validators.ts | 2 +- src/component/parser/json/converter/ProcessConverter.ts | 2 +- test/e2e/helpers/visu/image-snapshot-config.ts | 2 +- test/performance/helpers/metrics-chromium.ts | 2 +- test/unit/helpers/bpmn-model-expect.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev/ts/pages/index.ts b/dev/ts/pages/index.ts index 4920abf07e..04a22504b2 100644 --- a/dev/ts/pages/index.ts +++ b/dev/ts/pages/index.ts @@ -47,7 +47,7 @@ function configureFitOnLoadCheckBox(): void { function updateFitConfig(config: FitOptions): void { log('Updating fit config', config); - fitOptions.margin = config.margin || fitOptions.margin; + fitOptions.margin = config.margin ?? fitOptions.margin; if (config.type) { fitOptions.type = config.type; } diff --git a/dev/ts/shared/main.ts b/dev/ts/shared/main.ts index 87416201de..a6e31e262c 100644 --- a/dev/ts/shared/main.ts +++ b/dev/ts/shared/main.ts @@ -217,7 +217,7 @@ function logOnlyStatusKoNotifier(errorMsg: string): void { } function getFitOptionsFromParameters(config: BpmnVisualizationDemoConfiguration, parameters: URLSearchParams): FitOptions { - const fitOptions: FitOptions = config.loadOptions?.fit || {}; + const fitOptions: FitOptions = config.loadOptions?.fit ?? {}; const parameterFitType: string = parameters.get('fitTypeOnLoad'); if (parameterFitType) { // As the parameter is a string, and the load/fit APIs accept only enum to avoid error, we need to convert it @@ -320,7 +320,7 @@ export function startBpmnVisualization(config: BpmnVisualizationDemoConfiguratio statusKoNotifier = config.statusKoNotifier ?? logOnlyStatusKoNotifier; log('Configuring Load Options'); - loadOptions = config.loadOptions || {}; + loadOptions = config.loadOptions ?? {}; loadOptions.fit = getFitOptionsFromParameters(config, parameters); loadOptions.modelFilter = configurePoolsFilteringFromParameters(parameters); diff --git a/src/component/helpers/validators.ts b/src/component/helpers/validators.ts index ae2ddc820e..b985df31c2 100644 --- a/src/component/helpers/validators.ts +++ b/src/component/helpers/validators.ts @@ -28,7 +28,7 @@ export function ensureInRange(value: number, min: number, max: number, defaultVa * @internal */ export function ensurePositiveValue(input: number | undefined | null): number { - return Math.max(input || 0, 0); + return Math.max(input ?? 0, 0); } /** diff --git a/src/component/parser/json/converter/ProcessConverter.ts b/src/component/parser/json/converter/ProcessConverter.ts index 7b26d1b8e4..38d3dcb1ef 100644 --- a/src/component/parser/json/converter/ProcessConverter.ts +++ b/src/component/parser/json/converter/ProcessConverter.ts @@ -371,7 +371,7 @@ const buildMarkers = (bpmnElement: TActivity): ShapeBpmnMarkerKind[] => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the multiInstanceLoopCharacteristics field is not on all types, but it's already tested // @ts-ignore const multiInstanceLoopCharacteristics = ensureIsArray(bpmnElement.multiInstanceLoopCharacteristics, true)[0]; - if (standardLoopCharacteristics || standardLoopCharacteristics === '') { + if (standardLoopCharacteristics ?? standardLoopCharacteristics === '') { markers.push(ShapeBpmnMarkerKind.LOOP); } else if (multiInstanceLoopCharacteristics) { markers.push(multiInstanceLoopCharacteristics.isSequential ? ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL : ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL); diff --git a/test/e2e/helpers/visu/image-snapshot-config.ts b/test/e2e/helpers/visu/image-snapshot-config.ts index df999ab76a..7f4d11b3a5 100644 --- a/test/e2e/helpers/visu/image-snapshot-config.ts +++ b/test/e2e/helpers/visu/image-snapshot-config.ts @@ -71,7 +71,7 @@ export class ImageSnapshotConfigurator { configLog(`Using dedicated image snapshot threshold for '${fileName}'`); const simplePlatformName = getSimplePlatformName(); configLog(`Simple platform name: ${simplePlatformName}`); - failureThreshold = config[simplePlatformName] || failureThreshold; + failureThreshold = config[simplePlatformName] ?? failureThreshold; } else { configLog(`Using default image snapshot threshold for '${fileName}'`); } diff --git a/test/performance/helpers/metrics-chromium.ts b/test/performance/helpers/metrics-chromium.ts index 77428709a9..f10ac666e8 100644 --- a/test/performance/helpers/metrics-chromium.ts +++ b/test/performance/helpers/metrics-chromium.ts @@ -94,7 +94,7 @@ const supportedMetrics = new Set([ function buildMetricsObject(metrics?: Array): Metrics { const result: Metrics = {}; - for (const metric of metrics || []) { + for (const metric of metrics ?? []) { if (supportedMetrics.has(metric.name)) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/test/unit/helpers/bpmn-model-expect.ts b/test/unit/helpers/bpmn-model-expect.ts index 4e884738ea..5ee13c529c 100644 --- a/test/unit/helpers/bpmn-model-expect.ts +++ b/test/unit/helpers/bpmn-model-expect.ts @@ -114,7 +114,7 @@ export const verifyShape = ( expect(bpmnElement.markers).toHaveLength(0); } - if (('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) || 'bpmnElementGlobalTaskKind' in expectedShape) { + if (('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) ?? 'bpmnElementGlobalTaskKind' in expectedShape) { expect(bpmnElement instanceof ShapeBpmnCallActivity).toBeTruthy(); expect((bpmnElement as ShapeBpmnCallActivity).callActivityKind).toEqual(expectedShape.bpmnElementCallActivityKind); expect((bpmnElement as ShapeBpmnCallActivity).globalTaskKind).toEqual(expectedShape.bpmnElementGlobalTaskKind); From cc2534ff5f61ce01f76150595edbfd03c8d1b32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= Date: Fri, 25 Aug 2023 17:18:04 +0200 Subject: [PATCH 2/4] revert bad changes --- src/component/parser/json/converter/ProcessConverter.ts | 6 +----- test/unit/helpers/bpmn-model-expect.ts | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/component/parser/json/converter/ProcessConverter.ts b/src/component/parser/json/converter/ProcessConverter.ts index 38d3dcb1ef..ff9b71f21c 100644 --- a/src/component/parser/json/converter/ProcessConverter.ts +++ b/src/component/parser/json/converter/ProcessConverter.ts @@ -365,13 +365,9 @@ export default class ProcessConverter { const buildMarkers = (bpmnElement: TActivity): ShapeBpmnMarkerKind[] => { const markers: ShapeBpmnMarkerKind[] = []; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the standardLoopCharacteristics field is not on all types, but it's already tested - // @ts-ignore const standardLoopCharacteristics = bpmnElement.standardLoopCharacteristics; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the multiInstanceLoopCharacteristics field is not on all types, but it's already tested - // @ts-ignore const multiInstanceLoopCharacteristics = ensureIsArray(bpmnElement.multiInstanceLoopCharacteristics, true)[0]; - if (standardLoopCharacteristics ?? standardLoopCharacteristics === '') { + if (standardLoopCharacteristics !== undefined) { markers.push(ShapeBpmnMarkerKind.LOOP); } else if (multiInstanceLoopCharacteristics) { markers.push(multiInstanceLoopCharacteristics.isSequential ? ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL : ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL); diff --git a/test/unit/helpers/bpmn-model-expect.ts b/test/unit/helpers/bpmn-model-expect.ts index 5ee13c529c..0adca9def9 100644 --- a/test/unit/helpers/bpmn-model-expect.ts +++ b/test/unit/helpers/bpmn-model-expect.ts @@ -43,7 +43,7 @@ export interface ExpectedActivityShape extends ExpectedShape { export interface ExpectedCallActivityShape extends ExpectedActivityShape { bpmnElementGlobalTaskKind?: GlobalTaskKind; - bpmnElementCallActivityKind?: ShapeBpmnCallActivityKind; + bpmnElementCallActivityKind: ShapeBpmnCallActivityKind; } export interface ExpectedEventShape extends ExpectedShape { @@ -114,7 +114,7 @@ export const verifyShape = ( expect(bpmnElement.markers).toHaveLength(0); } - if (('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) ?? 'bpmnElementGlobalTaskKind' in expectedShape) { + if ('bpmnElementCallActivityKind' in expectedShape || 'bpmnElementGlobalTaskKind' in expectedShape) { expect(bpmnElement instanceof ShapeBpmnCallActivity).toBeTruthy(); expect((bpmnElement as ShapeBpmnCallActivity).callActivityKind).toEqual(expectedShape.bpmnElementCallActivityKind); expect((bpmnElement as ShapeBpmnCallActivity).globalTaskKind).toEqual(expectedShape.bpmnElementGlobalTaskKind); From 39790ce9e311c3f5869246fec39aa125d6306e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= Date: Fri, 25 Aug 2023 18:20:18 +0200 Subject: [PATCH 3/4] fix test --- test/unit/helpers/bpmn-model-expect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/helpers/bpmn-model-expect.ts b/test/unit/helpers/bpmn-model-expect.ts index 0adca9def9..83cc546b45 100644 --- a/test/unit/helpers/bpmn-model-expect.ts +++ b/test/unit/helpers/bpmn-model-expect.ts @@ -114,7 +114,7 @@ export const verifyShape = ( expect(bpmnElement.markers).toHaveLength(0); } - if ('bpmnElementCallActivityKind' in expectedShape || 'bpmnElementGlobalTaskKind' in expectedShape) { + if ('bpmnElementCallActivityKind' in expectedShape) { expect(bpmnElement instanceof ShapeBpmnCallActivity).toBeTruthy(); expect((bpmnElement as ShapeBpmnCallActivity).callActivityKind).toEqual(expectedShape.bpmnElementCallActivityKind); expect((bpmnElement as ShapeBpmnCallActivity).globalTaskKind).toEqual(expectedShape.bpmnElementGlobalTaskKind); From 031e096a50299a1035c892f38515793f3876afd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= Date: Mon, 28 Aug 2023 12:05:58 +0200 Subject: [PATCH 4/4] Fix tests helper --- test/unit/helpers/bpmn-model-expect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/helpers/bpmn-model-expect.ts b/test/unit/helpers/bpmn-model-expect.ts index 83cc546b45..7433f9c8e8 100644 --- a/test/unit/helpers/bpmn-model-expect.ts +++ b/test/unit/helpers/bpmn-model-expect.ts @@ -114,7 +114,7 @@ export const verifyShape = ( expect(bpmnElement.markers).toHaveLength(0); } - if ('bpmnElementCallActivityKind' in expectedShape) { + if ('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) { expect(bpmnElement instanceof ShapeBpmnCallActivity).toBeTruthy(); expect((bpmnElement as ShapeBpmnCallActivity).callActivityKind).toEqual(expectedShape.bpmnElementCallActivityKind); expect((bpmnElement as ShapeBpmnCallActivity).globalTaskKind).toEqual(expectedShape.bpmnElementGlobalTaskKind);