From 792e4d1f719ab90e39cb67d41a55485543c14cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souchet=20C=C3=A9line?= <4921914+csouchet@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:54:56 +0200 Subject: [PATCH] chore(eslint): use @typescript-eslint/stylistic rules (#2821) - Introduced the `plugin:@typescript-eslint/stylistic` rules. - Disabled `@typescript-eslint/consistent-type-definitions` rule - Addressed linting issues identified by `plugin:@typescript-eslint/stylistic`. --- .eslintrc.js | 3 + dev/ts/component/DropFileUserInterface.ts | 6 +- dev/ts/pages/diagram-navigation.ts | 4 +- dev/ts/pages/elements-identification.ts | 12 ++-- dev/ts/pages/index.ts | 16 +++--- dev/ts/pages/overlays.ts | 2 +- dev/ts/shared/main.ts | 2 +- src/component/helpers/array-utils.ts | 4 +- src/component/mxgraph/BpmnCellRenderer.ts | 4 +- src/component/mxgraph/initializer.ts | 1 + src/component/mxgraph/overlay/converter.ts | 4 +- .../mxgraph/renderer/StyleComputer.ts | 4 +- src/component/mxgraph/shape/event-shapes.ts | 2 +- src/component/mxgraph/style/style-updater.ts | 2 +- src/component/mxgraph/style/utils.ts | 2 +- .../json/converter/CollaborationConverter.ts | 6 +- .../parser/json/converter/DiagramConverter.ts | 24 ++++---- .../parser/json/converter/ProcessConverter.ts | 16 +++--- src/component/parser/json/converter/utils.ts | 20 +++---- src/component/parser/json/warnings.ts | 8 +-- src/component/parser/parsing-messages.ts | 2 +- src/component/registry/bpmn-model-registry.ts | 14 ++--- .../bpmn/internal/shape/ShapeBpmnElement.ts | 4 +- test/config/jest.image.ts | 4 +- test/e2e/bpmn.elements.collapsed.test.ts | 4 +- test/integration/BpmnVisualization.test.ts | 2 +- .../cross.css.and.style.api.test.ts | 8 +-- test/integration/diagram.navigation.test.ts | 2 +- test/integration/helpers/model-expect.ts | 53 ++++++++--------- .../helpers/semantic-with-svg-utils.ts | 6 +- .../mxGraph.model.style.api.test.ts | 18 +++--- .../performance/bpmn.load.performance.test.ts | 2 +- .../bpmn.navigation.performance.test.ts | 2 +- test/performance/helpers/metrics-chromium.ts | 2 +- test/performance/helpers/perf-utils.ts | 4 +- test/shared/overlays.ts | 6 +- .../json/BpmnJsonParser.sub.process.test.ts | 8 +-- .../registry/bpmn-model-registry.test.ts | 8 +-- test/unit/helpers/JsonBuilder.ts | 57 +++++++++---------- test/unit/helpers/JsonTestUtils.ts | 4 +- 40 files changed, 176 insertions(+), 176 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 248ca7d069..73c397f19f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -47,6 +47,7 @@ module.exports = { extends: [ 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. + 'plugin:@typescript-eslint/stylistic', ], parserOptions: { // This setting is required if you want to use rules which require type information @@ -74,6 +75,8 @@ module.exports = { }, ], '@typescript-eslint/consistent-type-imports': ['error'], + // We choose to disable it and choose later if we want to enable it. See https://github.com/process-analytics/bpmn-visualization-js/pull/2821. + '@typescript-eslint/consistent-type-definitions': 'off', }, }, ], diff --git a/dev/ts/component/DropFileUserInterface.ts b/dev/ts/component/DropFileUserInterface.ts index 0376fde591..c63b5fd85c 100644 --- a/dev/ts/component/DropFileUserInterface.ts +++ b/dev/ts/component/DropFileUserInterface.ts @@ -134,14 +134,14 @@ export class DropFileUserInterface { private getAddClassCallback(containerToBeFaded: HTMLElement, isDocument: boolean, outerContainerId?: string) { return function (this: Document | HTMLElement): void { - isDocument ? (this).querySelector('#' + outerContainerId).classList.add('dragging') : (this).classList.add('dragging'); + isDocument ? (this as Document).querySelector('#' + outerContainerId).classList.add('dragging') : (this as HTMLElement).classList.add('dragging'); containerToBeFaded.classList.add('faded'); }; } private getRemoveClassCallback(containerToBeFaded: HTMLElement, isDocument: boolean, outerContainerId?: string) { return function (this: Document | HTMLElement): void { - isDocument ? (this).querySelector('#' + outerContainerId).classList.remove('dragging') : (this).classList.remove('dragging'); + isDocument ? (this as Document).querySelector('#' + outerContainerId).classList.remove('dragging') : (this as HTMLElement).classList.remove('dragging'); containerToBeFaded.classList.remove('faded'); }; } @@ -155,7 +155,7 @@ export class DropFileUserInterface { } catch (e) { logErrorAndOpenAlert(e); } finally { - isDocument ? (this).querySelector('#' + outerContainerId).classList.remove('dragging') : (this).classList.remove('dragging'); + isDocument ? (this as Document).querySelector('#' + outerContainerId).classList.remove('dragging') : (this as HTMLElement).classList.remove('dragging'); containerToBeFaded.classList.remove('faded'); } }; diff --git a/dev/ts/pages/diagram-navigation.ts b/dev/ts/pages/diagram-navigation.ts index 0d7d9d27f9..6780aceadf 100644 --- a/dev/ts/pages/diagram-navigation.ts +++ b/dev/ts/pages/diagram-navigation.ts @@ -26,7 +26,7 @@ function configureFitAndZoomButtons(): void { } function configureZoomThrottleInput(parameters: URLSearchParams): HTMLInputElement { - const elZoomThrottle = document.getElementById('zoom-throttle'); + const elZoomThrottle = document.getElementById('zoom-throttle') as HTMLInputElement; if (parameters.get('zoomThrottle')) { elZoomThrottle.value = parameters.get('zoomThrottle'); } @@ -34,7 +34,7 @@ function configureZoomThrottleInput(parameters: URLSearchParams): HTMLInputEleme } function configureZoomDebounceInput(parameters: URLSearchParams): HTMLInputElement { - const elZoomDebounce = document.getElementById('zoom-debounce'); + const elZoomDebounce = document.getElementById('zoom-debounce') as HTMLInputElement; if (parameters.get('zoomDebounce')) { elZoomDebounce.value = parameters.get('zoomDebounce'); } diff --git a/dev/ts/pages/elements-identification.ts b/dev/ts/pages/elements-identification.ts index cd50e89fea..17ebff7779 100644 --- a/dev/ts/pages/elements-identification.ts +++ b/dev/ts/pages/elements-identification.ts @@ -182,7 +182,7 @@ function updateSelectedBPMNElements(bpmnKind: ShapeBpmnElementKind): void { } function updateTextArea(elementsByKinds: BpmnElement[], bpmnKind: string): void { - const textArea = document.getElementById('elements-result'); + const textArea = document.getElementById('elements-result') as HTMLTextAreaElement; const textHeader = `Found ${elementsByKinds.length} ${bpmnKind}(s)`; log(textHeader); @@ -193,13 +193,13 @@ function updateTextArea(elementsByKinds: BpmnElement[], bpmnKind: string): void } function resetTextArea(): void { - const textArea = document.getElementById('elements-result'); + const textArea = document.getElementById('elements-result') as HTMLTextAreaElement; textArea.value = ''; } function configureControls(): void { - const selectedKindElt = document.getElementById('bpmn-kinds-select'); - selectedKindElt.onchange = event => updateSelectedBPMNElements((event.target).value as ShapeBpmnElementKind); + const selectedKindElt = document.getElementById('bpmn-kinds-select') as HTMLSelectElement; + selectedKindElt.onchange = event => updateSelectedBPMNElements((event.target as HTMLSelectElement).value as ShapeBpmnElementKind); document.addEventListener('diagramLoaded', () => updateSelectedBPMNElements(selectedKindElt.value as ShapeBpmnElementKind), false); document.getElementById('clear-btn').onclick = function () { @@ -213,7 +213,7 @@ function configureControls(): void { }; // display overlay option - const checkboxDisplayOverlaysElt = document.getElementById('checkbox-display-overlays'); + const checkboxDisplayOverlaysElt = document.getElementById('checkbox-display-overlays') as HTMLInputElement; checkboxDisplayOverlaysElt.addEventListener('change', function () { isOverlaysDisplayed = this.checked; log('Request overlays display:', isOverlaysDisplayed); @@ -222,7 +222,7 @@ function configureControls(): void { checkboxDisplayOverlaysElt.checked = isOverlaysDisplayed; // use CSS or API to style the BPMN elements - const checkboxUseCSSElt = document.getElementById('checkbox-css-style'); + const checkboxUseCSSElt = document.getElementById('checkbox-css-style') as HTMLInputElement; checkboxUseCSSElt.addEventListener('change', function () { useCSS = this.checked; log('Request CSS style feature:', useCSS); diff --git a/dev/ts/pages/index.ts b/dev/ts/pages/index.ts index 04a22504b2..53ca88d651 100644 --- a/dev/ts/pages/index.ts +++ b/dev/ts/pages/index.ts @@ -35,9 +35,9 @@ let fitOnLoad = true; let fitOptions: FitOptions = {}; function configureFitOnLoadCheckBox(): void { - const fitOnLoadElt = document.getElementById('fitOnLoad'); + const fitOnLoadElt = document.getElementById('fitOnLoad') as HTMLInputElement; fitOnLoadElt.onchange = event => { - fitOnLoad = (event.target).checked; + fitOnLoad = (event.target as HTMLInputElement).checked; log('Fit on load updated!', fitOnLoad); updateLoadOptions(fitOnLoad ? fitOptions : {}); }; @@ -59,9 +59,9 @@ function updateFitConfig(config: FitOptions): void { } function configureFitTypeSelect(): void { - const fitTypeSelectedElt = document.getElementById('fitType-selected'); + const fitTypeSelectedElt = document.getElementById('fitType-selected') as HTMLSelectElement; fitTypeSelectedElt.onchange = event => { - updateFitConfig({ type: (event.target).value as FitType }); + updateFitConfig({ type: (event.target as HTMLSelectElement).value as FitType }); fit(fitOptions); }; @@ -73,9 +73,9 @@ function configureFitTypeSelect(): void { } function configureFitMarginInput(): void { - const fitMarginElt = document.getElementById('fit-margin'); + const fitMarginElt = document.getElementById('fit-margin') as HTMLInputElement; fitMarginElt.onchange = event => { - updateFitConfig({ margin: Number((event.target).value) }); + updateFitConfig({ margin: Number((event.target as HTMLInputElement).value) }); fit(fitOptions); }; @@ -94,9 +94,9 @@ function configureZoomButtons(): void { } function configureThemeSelect(): void { - const themeSelectedElt = document.getElementById('theme-selected'); + const themeSelectedElt = document.getElementById('theme-selected') as HTMLSelectElement; themeSelectedElt.onchange = event => { - switchTheme((event.target).value); + switchTheme((event.target as HTMLSelectElement).value); }; const currentTheme = getCurrentTheme(); diff --git a/dev/ts/pages/overlays.ts b/dev/ts/pages/overlays.ts index b97314e925..8afef83c88 100644 --- a/dev/ts/pages/overlays.ts +++ b/dev/ts/pages/overlays.ts @@ -17,7 +17,7 @@ limitations under the License. import type { Overlay, OverlayPosition } from '../dev-bundle-index'; import { addOverlays, configureControlsPanel, configureMousePointer, documentReady, getElementsByIds, removeAllOverlays, startBpmnVisualization } from '../dev-bundle-index'; -const bpmnIdInputElt = document.getElementById('bpmn-id-input'); +const bpmnIdInputElt = document.getElementById('bpmn-id-input') as HTMLInputElement; function addOverlay(overlay: Overlay): void { const bpmnId = bpmnIdInputElt.value; diff --git a/dev/ts/shared/main.ts b/dev/ts/shared/main.ts index a6e31e262c..c7b4b9bae3 100644 --- a/dev/ts/shared/main.ts +++ b/dev/ts/shared/main.ts @@ -221,7 +221,7 @@ function getFitOptionsFromParameters(config: BpmnVisualizationDemoConfiguration, 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 - fitOptions.type = parameterFitType; + fitOptions.type = parameterFitType as FitType; } const parameterFitMargin = parameters.get('fitMargin'); if (parameterFitMargin) { diff --git a/src/component/helpers/array-utils.ts b/src/component/helpers/array-utils.ts index ab6a50ece0..cbcb64ec20 100644 --- a/src/component/helpers/array-utils.ts +++ b/src/component/helpers/array-utils.ts @@ -35,7 +35,7 @@ function convertEmptyStringAndObject(element: string | T, acceptEmptyString: /** * @internal */ -export function ensureIsArray(elements: (T | string)[] | T | string, acceptEmptyString = false): Array { +export function ensureIsArray(elements: (T | string)[] | T | string, acceptEmptyString = false): T[] { if (elements === undefined || elements === null) { return []; } @@ -52,7 +52,7 @@ export function ensureIsArray(elements: (T | string)[] | T | string, acceptEm /** * @internal */ -export function filter(arrayToFilter: Array, suffix: string, options?: FilterParameter): Array { +export function filter(arrayToFilter: T[], suffix: string, options?: FilterParameter): T[] { let pattern = ''; if (options?.startingWith) { pattern = pattern.concat(`^(${options.startingWith}).*`); diff --git a/src/component/mxgraph/BpmnCellRenderer.ts b/src/component/mxgraph/BpmnCellRenderer.ts index 63a8d7af87..8154c07794 100644 --- a/src/component/mxgraph/BpmnCellRenderer.ts +++ b/src/component/mxgraph/BpmnCellRenderer.ts @@ -42,7 +42,7 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer { overlayShape = new OverlayBadgeShape(currentOverlay.label, new mxRectangle(0, 0, 0, 0), currentOverlay.style); } else { overlayShape = new mxgraph.mxImageShape(new mxRectangle(0, 0, 0, 0), currentOverlay.image.src); - (overlayShape).preserveImageAspect = false; + (overlayShape as mxImageShape).preserveImageAspect = false; } // END bpmn-visualization CUSTOMIZATION @@ -50,7 +50,7 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer { overlayShape.overlay = currentOverlay; // The 'initializeOverlay' signature forces us to hardly cast the overlayShape - this.initializeOverlay(state, overlayShape); + this.initializeOverlay(state, overlayShape as mxImageShape); this.installCellOverlayListeners(state, currentOverlay, overlayShape); if (currentOverlay.cursor != null) { diff --git a/src/component/mxgraph/initializer.ts b/src/component/mxgraph/initializer.ts index 4441dd0c3a..bbecd222da 100644 --- a/src/component/mxgraph/initializer.ts +++ b/src/component/mxgraph/initializer.ts @@ -56,6 +56,7 @@ export const mxUtils = mxgraph.mxUtils; /** @internal */ declare global { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Since we are overriding an existing interface in the global scope, it is not possible to convert it to a type. interface Window { mxForceIncludes: boolean; mxLoadResources: boolean; diff --git a/src/component/mxgraph/overlay/converter.ts b/src/component/mxgraph/overlay/converter.ts index 35e08ce0cc..557d3ecf03 100644 --- a/src/component/mxgraph/overlay/converter.ts +++ b/src/component/mxgraph/overlay/converter.ts @@ -19,7 +19,7 @@ import { StyleDefault } from '../style'; import type { MxGraphCustomOverlayOptions, MxGraphCustomOverlayPosition, MxGraphCustomOverlayStyle } from './custom-overlay'; export class OverlayConverter { - private overlayPositions: Map = new Map([ + private overlayPositions = new Map([ // Edge ['start', { horizontalAlign: 'left', verticalAlign: 'top' }], ['middle', { horizontalAlign: 'center', verticalAlign: 'top' }], @@ -54,7 +54,7 @@ export class OverlayConverter { }; const style = overlay.style; - const convertedStyle = { ...defaultStyle }; + const convertedStyle = { ...defaultStyle } as MxGraphCustomOverlayStyle; if (!style) { return convertedStyle; } diff --git a/src/component/mxgraph/renderer/StyleComputer.ts b/src/component/mxgraph/renderer/StyleComputer.ts index 7909d30d39..0fcff0d6a7 100644 --- a/src/component/mxgraph/renderer/StyleComputer.ts +++ b/src/component/mxgraph/renderer/StyleComputer.ts @@ -196,7 +196,7 @@ export default class StyleComputer { } computeMessageFlowIconStyle(edge: Edge): string { - const styleValues: Array<[string, string]> = []; + const styleValues: [string, string][] = []; styleValues.push(['shape', BpmnStyleIdentifier.MESSAGE_FLOW_ICON]); styleValues.push([BpmnStyleIdentifier.IS_INITIATING, String(edge.messageVisibleKind === MessageVisibleKind.INITIATING)]); if (!this.ignoreBpmnColors) { @@ -228,6 +228,6 @@ export function getFontStyleValue(font: Font): number { return value; } -function toArrayOfMxGraphStyleEntries(styleValues: Array<[string, string | number]>): string[] { +function toArrayOfMxGraphStyleEntries(styleValues: [string, string | number][]): string[] { return styleValues.filter(([, v]) => v && v != 'undefined').map(([key, value]) => `${key}=${value}`); } diff --git a/src/component/mxgraph/shape/event-shapes.ts b/src/component/mxgraph/shape/event-shapes.ts index e854b48f02..b9af0ebead 100644 --- a/src/component/mxgraph/shape/event-shapes.ts +++ b/src/component/mxgraph/shape/event-shapes.ts @@ -29,7 +29,7 @@ export class EventShape extends mxgraph.mxEllipse { protected iconPainter = IconPainterProvider.get(); // refactor: when all/more event types will be supported, we could move to a Record/MappedType - private iconPainters: Map void> = new Map([ + private iconPainters = new Map void>([ [ShapeBpmnEventDefinitionKind.MESSAGE, (paintParameter: PaintParameter) => this.iconPainter.paintEnvelopeIcon({ ...paintParameter, ratioFromParent: 0.5 })], [ShapeBpmnEventDefinitionKind.TERMINATE, (paintParameter: PaintParameter) => this.iconPainter.paintCircleIcon({ ...paintParameter, ratioFromParent: 0.6 })], [ diff --git a/src/component/mxgraph/style/style-updater.ts b/src/component/mxgraph/style/style-updater.ts index 31ad4d51db..472953991e 100644 --- a/src/component/mxgraph/style/style-updater.ts +++ b/src/component/mxgraph/style/style-updater.ts @@ -93,7 +93,7 @@ export class StyleUpdater { const cssClassesStyleIdentifier = BpmnStyleIdentifier.EXTRA_CSS_CLASSES; class StyleManager { - private stylesCache: Map = new Map(); + private stylesCache = new Map(); constructor(private readonly model: mxGraphModel) {} diff --git a/src/component/mxgraph/style/utils.ts b/src/component/mxgraph/style/utils.ts index fc955485b7..69e5115487 100644 --- a/src/component/mxgraph/style/utils.ts +++ b/src/component/mxgraph/style/utils.ts @@ -74,7 +74,7 @@ export const StyleDefault = { * @internal * @private */ -export const getBpmnIsInstantiating = (style: { [p: string]: unknown }): boolean => mxUtils.getValue(style, BpmnStyleIdentifier.IS_INSTANTIATING, 'false') == 'true'; +export const getBpmnIsInstantiating = (style: Record): boolean => mxUtils.getValue(style, BpmnStyleIdentifier.IS_INSTANTIATING, 'false') == 'true'; const convertDefaultValue = (value: string): string | undefined => (value == 'default' ? undefined : value); diff --git a/src/component/parser/json/converter/CollaborationConverter.ts b/src/component/parser/json/converter/CollaborationConverter.ts index d7e92234dc..d69da7cb01 100644 --- a/src/component/parser/json/converter/CollaborationConverter.ts +++ b/src/component/parser/json/converter/CollaborationConverter.ts @@ -45,19 +45,19 @@ export default class CollaborationConverter { this.buildGroups(collaboration.group); } - private buildParticipant(bpmnElements: Array | TParticipant): void { + private buildParticipant(bpmnElements: TParticipant[] | TParticipant): void { ensureIsArray(bpmnElements).forEach(participant => this.convertedElements.registerPool(new ShapeBpmnElement(participant.id, participant.name, ShapeBpmnElementKind.POOL), participant.processRef), ); } - private buildMessageFlows(bpmnElements: Array | TMessageFlow): void { + private buildMessageFlows(bpmnElements: TMessageFlow[] | TMessageFlow): void { ensureIsArray(bpmnElements).forEach(messageFlow => this.convertedElements.registerMessageFlow(new MessageFlow(messageFlow.id, messageFlow.name, messageFlow.sourceRef, messageFlow.targetRef)), ); } - private buildGroups(bpmnElements: Array | TGroup): void { + private buildGroups(bpmnElements: TGroup[] | TGroup): void { ensureIsArray(bpmnElements).forEach(groupBpmnElement => { const shapeBpmnElement = buildShapeBpmnGroup(this.convertedElements, this.parsingMessageCollector, groupBpmnElement); shapeBpmnElement && this.convertedElements.registerFlowNode(shapeBpmnElement); diff --git a/src/component/parser/json/converter/DiagramConverter.ts b/src/component/parser/json/converter/DiagramConverter.ts index 8d5b001f99..e365bda0d8 100644 --- a/src/component/parser/json/converter/DiagramConverter.ts +++ b/src/component/parser/json/converter/DiagramConverter.ts @@ -39,9 +39,9 @@ export default class DiagramConverter { private parsingMessageCollector: ParsingMessageCollector, ) {} - private convertedFonts: Map = new Map(); + private convertedFonts = new Map(); - deserialize(bpmnDiagrams: Array | BPMNDiagram): BpmnModel { + deserialize(bpmnDiagrams: BPMNDiagram[] | BPMNDiagram): BpmnModel { const flowNodes: Shape[] = []; const lanes: Shape[] = []; const pools: Shape[] = []; @@ -64,7 +64,7 @@ export default class DiagramConverter { return { flowNodes, lanes, pools, edges }; } - private deserializeFonts(bpmnLabelStyle: Array | BPMNLabelStyle): void { + private deserializeFonts(bpmnLabelStyle: BPMNLabelStyle[] | BPMNLabelStyle): void { this.convertedFonts = new Map(); ensureIsArray(bpmnLabelStyle).forEach(labelStyle => @@ -74,7 +74,7 @@ export default class DiagramConverter { ); } - private deserializeShapes(shapes: Array | BPMNShape): Shapes { + private deserializeShapes(shapes: BPMNShape[] | BPMNShape): Shapes { const convertedShapes: Shapes = { flowNodes: [], lanes: [], pools: [] }; ensureIsArray(shapes).forEach(shape => { @@ -97,7 +97,7 @@ export default class DiagramConverter { return convertedShapes; } - private deserializeShapeAndStoreIfFound(shape: BPMNShape, storage: Array, findShapeElement: (bpmnElement: string) => ShapeBpmnElement): boolean { + private deserializeShapeAndStoreIfFound(shape: BPMNShape, storage: Shape[], findShapeElement: (bpmnElement: string) => ShapeBpmnElement): boolean { const element = this.deserializeShape(shape, findShapeElement); if (element) { storage.push(element); @@ -136,14 +136,14 @@ export default class DiagramConverter { // 'BPMN in Color' extensions with fallback to bpmn.io colors private static setColorExtensionsOnShape(shape: Shape, bpmnShape: BPMNShape): void { if ('background-color' in bpmnShape) { - shape.extensions.fillColor = bpmnShape['background-color']; + shape.extensions.fillColor = bpmnShape['background-color'] as string; } else if ('fill' in bpmnShape) { - shape.extensions.fillColor = bpmnShape['fill']; + shape.extensions.fillColor = bpmnShape['fill'] as string; } if ('border-color' in bpmnShape) { - shape.extensions.strokeColor = bpmnShape['border-color']; + shape.extensions.strokeColor = bpmnShape['border-color'] as string; } else if ('stroke' in bpmnShape) { - shape.extensions.strokeColor = bpmnShape['stroke']; + shape.extensions.strokeColor = bpmnShape['stroke'] as string; } } @@ -181,9 +181,9 @@ export default class DiagramConverter { // 'BPMN in Color' extensions with fallback to bpmn.io colors private static setColorExtensionsOnEdge(edge: Edge, bpmnEdge: BPMNEdge): void { if ('border-color' in bpmnEdge) { - edge.extensions.strokeColor = bpmnEdge['border-color']; + edge.extensions.strokeColor = bpmnEdge['border-color'] as string; } else if ('stroke' in bpmnEdge) { - edge.extensions.strokeColor = bpmnEdge['stroke']; + edge.extensions.strokeColor = bpmnEdge['stroke'] as string; } } @@ -197,7 +197,7 @@ export default class DiagramConverter { const bounds = DiagramConverter.deserializeBounds(bpmnLabel); const label = new Label(font, bounds); if ('color' in bpmnLabel) { - label.extensions.color = bpmnLabel.color; + label.extensions.color = bpmnLabel.color as string; return label; } if (font || bounds) { diff --git a/src/component/parser/json/converter/ProcessConverter.ts b/src/component/parser/json/converter/ProcessConverter.ts index ff9b71f21c..b76e399576 100644 --- a/src/component/parser/json/converter/ProcessConverter.ts +++ b/src/component/parser/json/converter/ProcessConverter.ts @@ -76,7 +76,7 @@ const orderedFlowNodeBpmnTypes: BpmnSemanticType[] = (['adHocSubProcess', 'trans .concat([ShapeBpmnElementKind.EVENT_BOUNDARY]); function getShapeBpmnElementKind(bpmnSemanticType: BpmnSemanticType): ShapeBpmnElementKind { - return ['adHocSubProcess', 'transaction'].includes(bpmnSemanticType) ? ShapeBpmnElementKind.SUB_PROCESS : bpmnSemanticType; + return ['adHocSubProcess', 'transaction'].includes(bpmnSemanticType as string) ? ShapeBpmnElementKind.SUB_PROCESS : (bpmnSemanticType as ShapeBpmnElementKind); } /** @@ -84,8 +84,8 @@ function getShapeBpmnElementKind(bpmnSemanticType: BpmnSemanticType): ShapeBpmnE */ export default class ProcessConverter { private defaultSequenceFlowIds: string[] = []; - private elementsWithoutParentByProcessId: Map = new Map(); - private callActivitiesCallingProcess: Map = new Map(); + private elementsWithoutParentByProcessId = new Map(); + private callActivitiesCallingProcess = new Map(); constructor( private convertedElements: ConvertedElements, @@ -160,7 +160,7 @@ export default class ProcessConverter { } private buildFlowNodeBpmnElements( - bpmnElements: Array | FlowNode, + bpmnElements: FlowNode[] | FlowNode, kind: ShapeBpmnElementKind, parentId: string, processId: string, @@ -299,11 +299,11 @@ export default class ProcessConverter { return convertedSubProcess; } - private buildLaneSetBpmnElements(laneSets: Array | TLaneSet, parentId: string, processId: string): void { + private buildLaneSetBpmnElements(laneSets: TLaneSet[] | TLaneSet, parentId: string, processId: string): void { ensureIsArray(laneSets).forEach(laneSet => this.buildLaneBpmnElements(laneSet.lane, parentId, processId)); } - private buildLaneBpmnElements(lanes: Array | TLane, parentId: string, processId: string): void { + private buildLaneBpmnElements(lanes: TLane[] | TLane, parentId: string, processId: string): void { ensureIsArray(lanes).forEach(lane => { const shapeBpmnElement = new ShapeBpmnElement(lane.id, lane.name, ShapeBpmnElementKind.LANE, parentId); this.convertedElements.registerLane(shapeBpmnElement); @@ -332,14 +332,14 @@ export default class ProcessConverter { }); } - private buildSequenceFlows(bpmnElements: Array | TSequenceFlow): void { + private buildSequenceFlows(bpmnElements: TSequenceFlow[] | TSequenceFlow): void { ensureIsArray(bpmnElements).forEach(sequenceFlow => { const kind = this.getSequenceFlowKind(sequenceFlow); this.convertedElements.registerSequenceFlow(new SequenceFlow(sequenceFlow.id, sequenceFlow.name, sequenceFlow.sourceRef, sequenceFlow.targetRef, kind)); }); } - private buildAssociationFlows(bpmnElements: Array | TAssociation): void { + private buildAssociationFlows(bpmnElements: TAssociation[] | TAssociation): void { ensureIsArray(bpmnElements).forEach(association => { const direction = association.associationDirection as unknown as AssociationDirectionKind; this.convertedElements.registerAssociationFlow(new AssociationFlow(association.id, undefined, association.sourceRef, association.targetRef, direction)); diff --git a/src/component/parser/json/converter/utils.ts b/src/component/parser/json/converter/utils.ts index 24f655ba8d..f9a89b03e2 100644 --- a/src/component/parser/json/converter/utils.ts +++ b/src/component/parser/json/converter/utils.ts @@ -30,11 +30,11 @@ export class ConvertedElements { return [...this.messageFlows.values(), ...this.sequenceFlows.values(), ...this.associationFlows.values()]; } - private poolsById: Map = new Map(); + private poolsById = new Map(); findPoolById(id: string): ShapeBpmnElement { return this.poolsById.get(id); } - private poolsByProcessRef: Map = new Map(); + private poolsByProcessRef = new Map(); findPoolByProcessRef(processRef: string): ShapeBpmnElement { return this.poolsByProcessRef.get(processRef); } @@ -45,7 +45,7 @@ export class ConvertedElements { } } - private messageFlows: Map = new Map(); + private messageFlows = new Map(); findMessageFlow(id: string): MessageFlow { return this.messageFlows.get(id); } @@ -53,7 +53,7 @@ export class ConvertedElements { this.messageFlows.set(messageFlow.id, messageFlow); } - private flowNodes: Map = new Map(); + private flowNodes = new Map(); findFlowNode(id: string): ShapeBpmnElement { return this.flowNodes.get(id); } @@ -61,7 +61,7 @@ export class ConvertedElements { this.flowNodes.set(flowNode.id, flowNode); } - private lanes: Map = new Map(); + private lanes = new Map(); findLane(id: string): ShapeBpmnElement { return this.lanes.get(id); } @@ -69,7 +69,7 @@ export class ConvertedElements { this.lanes.set(lane.id, lane); } - private sequenceFlows: Map = new Map(); + private sequenceFlows = new Map(); findSequenceFlow(id: string): SequenceFlow { return this.sequenceFlows.get(id); } @@ -77,7 +77,7 @@ export class ConvertedElements { this.sequenceFlows.set(sequenceFlow.id, sequenceFlow); } - private associationFlows: Map = new Map(); + private associationFlows = new Map(); findAssociationFlow(id: string): AssociationFlow { return this.associationFlows.get(id); } @@ -85,7 +85,7 @@ export class ConvertedElements { this.associationFlows.set(associationFlow.id, associationFlow); } - private eventDefinitionsOfDefinitions: Map = new Map(); + private eventDefinitionsOfDefinitions = new Map(); findEventDefinitionOfDefinition(id: string): ShapeBpmnEventDefinitionKind { return this.eventDefinitionsOfDefinitions.get(id); } @@ -93,7 +93,7 @@ export class ConvertedElements { this.eventDefinitionsOfDefinitions.set(id, eventDefinition); } - private globalTasks: Map = new Map(); + private globalTasks = new Map(); findGlobalTask(id: string): GlobalTaskKind { return this.globalTasks.get(id); } @@ -101,7 +101,7 @@ export class ConvertedElements { this.globalTasks.set(id, kind); } - private categoryValues: Map = new Map(); + private categoryValues = new Map(); findCategoryValue(categoryValue: string): CategoryValueData { return this.categoryValues.get(categoryValue); } diff --git a/src/component/parser/json/warnings.ts b/src/component/parser/json/warnings.ts index 5d41d3fca9..6a874f684b 100644 --- a/src/component/parser/json/warnings.ts +++ b/src/component/parser/json/warnings.ts @@ -26,7 +26,7 @@ export class GroupUnknownCategoryValueWarning extends JsonParsingWarning { super(); } - override getMessage(): { template: string; arguments: Array } { + override getMessage(): { template: string; arguments: string[] } { return { arguments: [this.categoryValueRef, this.groupBpmnElementId], template: 'Group json deserialization: unable to find category value ref %s for bpmn element %s', @@ -39,7 +39,7 @@ export class ShapeUnknownBpmnElementWarning extends JsonParsingWarning { super(); } - override getMessage(): { template: string; arguments: Array } { + override getMessage(): { template: string; arguments: string[] } { return { arguments: [this.bpmnElementId], template: 'Shape json deserialization: unable to find bpmn element with id %s', @@ -52,7 +52,7 @@ export class EdgeUnknownBpmnElementWarning extends JsonParsingWarning { super(); } - override getMessage(): { template: string; arguments: Array } { + override getMessage(): { template: string; arguments: string[] } { return { arguments: [this.bpmnElementId], template: 'Edge json deserialization: unable to find bpmn element with id %s', @@ -68,7 +68,7 @@ export class LabelStyleMissingFontWarning extends JsonParsingWarning { super(); } - override getMessage(): { template: string; arguments: Array } { + override getMessage(): { template: string; arguments: string[] } { return { arguments: [this.labelStyleId, this.shapeOrEdgeId], template: 'Unable to assign font from style %s to shape/edge %s', diff --git a/src/component/parser/parsing-messages.ts b/src/component/parser/parsing-messages.ts index 07a4e882d8..ae220089ec 100644 --- a/src/component/parser/parsing-messages.ts +++ b/src/component/parser/parsing-messages.ts @@ -16,7 +16,7 @@ limitations under the License. export interface MessageDetails { template: string; - arguments: Array; + arguments: string[]; } export abstract class JsonParsingWarning { diff --git a/src/component/registry/bpmn-model-registry.ts b/src/component/registry/bpmn-model-registry.ts index 361072a69a..3fea669fc1 100644 --- a/src/component/registry/bpmn-model-registry.ts +++ b/src/component/registry/bpmn-model-registry.ts @@ -53,13 +53,13 @@ export class BpmnModelRegistry { const isShape = bpmnElement instanceof ShapeBpmnElement; const semantic: BaseBpmnSemantic = { id: bpmnElementId, name: bpmnElement.name, isShape: isShape, kind: bpmnElement.kind }; if (bpmnElement instanceof Flow) { - (semantic).sourceRefId = bpmnElement.sourceRefId; - (semantic).targetRefId = bpmnElement.targetRefId; + (semantic as EdgeBpmnSemantic).sourceRefId = bpmnElement.sourceRefId; + (semantic as EdgeBpmnSemantic).targetRefId = bpmnElement.targetRefId; } else { - (semantic).incomingIds = bpmnElement.incomingIds; - (semantic).outgoingIds = bpmnElement.outgoingIds; + (semantic as ShapeBpmnSemantic).incomingIds = bpmnElement.incomingIds; + (semantic as ShapeBpmnSemantic).outgoingIds = bpmnElement.outgoingIds; } - return semantic; + return semantic as BpmnSemantic; } } @@ -101,10 +101,10 @@ export interface RenderedModel { } class SearchableModel { - private elements: Map = new Map(); + private elements = new Map(); constructor(bpmnModel: BpmnModel) { - ([] as Array) + ([] as (Edge | Shape)[]) .concat(bpmnModel.pools, bpmnModel.lanes, bpmnModel.flowNodes, bpmnModel.edges) // use the bpmn element id and not the bpmn shape id .forEach(e => this.elements.set(e.bpmnElement.id, e)); diff --git a/src/model/bpmn/internal/shape/ShapeBpmnElement.ts b/src/model/bpmn/internal/shape/ShapeBpmnElement.ts index ea6b63cbf1..efd35c33bc 100644 --- a/src/model/bpmn/internal/shape/ShapeBpmnElement.ts +++ b/src/model/bpmn/internal/shape/ShapeBpmnElement.ts @@ -29,7 +29,7 @@ export default class ShapeBpmnElement { readonly name: string, readonly kind: ShapeBpmnElementKind, public parentId?: string, - readonly instantiate: boolean = false, + readonly instantiate = false, ) {} } @@ -120,7 +120,7 @@ export class ShapeBpmnBoundaryEvent extends ShapeBpmnEvent { name: string, eventDefinitionKind: ShapeBpmnEventDefinitionKind, parentId: string, - readonly isInterrupting: boolean = true, + readonly isInterrupting = true, ) { super(id, name, ShapeBpmnElementKind.EVENT_BOUNDARY, eventDefinitionKind, parentId); } diff --git a/test/config/jest.image.ts b/test/config/jest.image.ts index 74d53a0cf1..b78d428550 100644 --- a/test/config/jest.image.ts +++ b/test/config/jest.image.ts @@ -57,7 +57,7 @@ class RetriesCounter { const retriesCounter = new RetriesCounter(); function saveAndRegisterImages(matcherContext: MatcherContext, received: Buffer, options: MatchImageSnapshotOptions): void { - const snapshotIdentifier = options.customSnapshotIdentifier; + const snapshotIdentifier = options.customSnapshotIdentifier as string; // Manage expected and received images const baseImagePathWithName = `${options.customDiffDir}/${snapshotIdentifier}`; const expectedImagePath = `${baseImagePathWithName}-expected.png`; @@ -70,7 +70,7 @@ function saveAndRegisterImages(matcherContext: MatcherContext, received: Buffer, // Create a custom context as the async call can be done whereas the global jest context has changed (another test is currently running). // So the test name and path changed, and the images would be attached to the wrong test. // For the context object structure, see https://github.com/Hazyzh/jest-html-reporters/blob/v3.0.5/helper.ts#L95 - const context: { [key: symbol]: unknown } = {}; + const context: Record = {}; context[Symbol('bpmn-visualization')] = { state: { currentTestName: matcherContext.currentTestName, diff --git a/test/e2e/bpmn.elements.collapsed.test.ts b/test/e2e/bpmn.elements.collapsed.test.ts index 23bc6f4791..0e7beb37f4 100644 --- a/test/e2e/bpmn.elements.collapsed.test.ts +++ b/test/e2e/bpmn.elements.collapsed.test.ts @@ -21,7 +21,7 @@ import { getBpmnDiagramNames } from '@test/shared/visu/test-utils'; // key: diagram name // values: the ids of the elements to collapse. The elements are collapsed one by one, in dedicated tests -const elementsToCollapsePerDiagram = new Map>([ +const elementsToCollapsePerDiagram = new Map([ ['pools', ['Participant_1', 'Participant_2', 'Participant_3', 'Participant_4']], ['subprocess', ['SubProcess_1']], ]); @@ -34,7 +34,7 @@ class CollapsedElementImageSnapshotConfigurator extends ImageSnapshotConfigurato } } -const getElementsToCollapse = (bpmnDiagramName: string): Array => { +const getElementsToCollapse = (bpmnDiagramName: string): string[] => { const elementsToCollapse = elementsToCollapsePerDiagram.get(bpmnDiagramName); // add 'none' to test the diagram rendering without collapsing any element. There is no element in diagrams with the 'none' id (in this case, the value is ignored and there is no collapsing). return ['none', ...elementsToCollapse]; diff --git a/test/integration/BpmnVisualization.test.ts b/test/integration/BpmnVisualization.test.ts index 3ebd379338..b9f8bed811 100644 --- a/test/integration/BpmnVisualization.test.ts +++ b/test/integration/BpmnVisualization.test.ts @@ -41,7 +41,7 @@ describe('BpmnVisualization API', () => { describe('Load', () => { it.each(allTestedFitTypes)('Fit type: %s', (fitType: string) => { - bpmnVisualization.load(readFileSync('../fixtures/bpmn/simple-start-task-end.bpmn'), { fit: { type: fitType } }); + bpmnVisualization.load(readFileSync('../fixtures/bpmn/simple-start-task-end.bpmn'), { fit: { type: fitType as FitType } }); }); it('Load invalid diagram (text file)', () => { diff --git a/test/integration/cross.css.and.style.api.test.ts b/test/integration/cross.css.and.style.api.test.ts index 2d0e1d081c..4928f061f1 100644 --- a/test/integration/cross.css.and.style.api.test.ts +++ b/test/integration/cross.css.and.style.api.test.ts @@ -19,7 +19,7 @@ import { ShapeBpmnElementKind, ShapeBpmnEventDefinitionKind } from '@lib/model/b import { readFileSync } from '@test/shared/file-helper'; import { initializeBpmnVisualizationWithContainerId } from './helpers/bpmn-visualization-initialization'; import { HtmlElementLookup } from './helpers/html-utils'; -import type { ExpectedEdgeModelElement, ExpectedShapeModelElement, VerticalAlign } from './helpers/model-expect'; +import type { ExpectedEdgeModelElement, ExpectedShapeModelElement } from './helpers/model-expect'; import { buildReceivedResolvedModelCellStyle, buildReceivedViewStateStyle } from './matchers/matcher-utils'; import { buildExpectedShapeCellStyle } from './matchers/toBeShape'; import { buildExpectedEdgeCellStyle } from './matchers/toBeEdge'; @@ -93,7 +93,7 @@ describe('Verify interaction between the CSS and style APIs', () => { kind: ShapeBpmnElementKind.EVENT_END, label: 'message end 2', stroke: { color: strokeColor }, - verticalAlign: 'top', // the element has a label + verticalAlign: 'top', // the element has a label } as ExpectedShapeModelElement); }); }); @@ -118,7 +118,7 @@ describe('Verify interaction between the CSS and style APIs', () => { extraCssClasses: ['class-1', 'class-2'], kind: ShapeBpmnElementKind.EVENT_END, label: 'message end 2', - verticalAlign: 'top', // the element has a label + verticalAlign: 'top', // the element has a label } as ExpectedShapeModelElement); }); }); @@ -175,7 +175,7 @@ describe('Verify interaction between the CSS and style APIs', () => { extraCssClasses: ['class-1', 'class-2', 'class-11'], kind: ShapeBpmnElementKind.EVENT_END, label: 'message end 2', - verticalAlign: 'top', // the element has a label + verticalAlign: 'top', // the element has a label } as ExpectedShapeModelElement); // Check elements whose style were not updated prior calling 'reset all' diff --git a/test/integration/diagram.navigation.test.ts b/test/integration/diagram.navigation.test.ts index b4da701cf2..c87ba50e87 100644 --- a/test/integration/diagram.navigation.test.ts +++ b/test/integration/diagram.navigation.test.ts @@ -33,7 +33,7 @@ describe('diagram navigation', () => { }); it.each(allTestedFitTypes)('Fit with %s', (fitType: string) => { - bpmnVisualization.navigation.fit({ type: fitType }); + bpmnVisualization.navigation.fit({ type: fitType as FitType }); }); }); diff --git a/test/integration/helpers/model-expect.ts b/test/integration/helpers/model-expect.ts index 59c64fb3cc..5a600583b9 100644 --- a/test/integration/helpers/model-expect.ts +++ b/test/integration/helpers/model-expect.ts @@ -64,6 +64,7 @@ import { getCell } from '../matchers/matcher-utils'; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace jest { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Since we are overriding an existing interface in Jest, it is not possible to convert it to a type. interface Matchers { toBeCell(): R; toBeCellWithParentAndGeometry(modelElement: ExpectedCellWithGeometry): R; @@ -134,12 +135,12 @@ expect.extend({ toBeTextAnnotation, }); -export interface ExpectedCellWithGeometry { +export type ExpectedCellWithGeometry = { parentId?: string; geometry: mxGeometry; -} +}; -export interface ExpectedFont { +export type ExpectedFont = { color?: string; family?: string; size?: number; @@ -148,7 +149,7 @@ export interface ExpectedFont { isUnderline?: boolean; isStrikeThrough?: boolean; opacity?: Opacity; -} +}; export type HorizontalAlign = 'center' | 'left' | 'right'; export type VerticalAlign = 'bottom' | 'middle' | 'top'; @@ -166,19 +167,19 @@ type ExpectedModelElement = { extraCssClasses?: string[]; }; -export interface ExpectedFill { +export type ExpectedFill = { color?: string; opacity?: Opacity; -} +}; export type ExpectedDirection = 'west' | 'east' | 'north' | 'south'; -export interface ExpectedGradient { +export type ExpectedGradient = { color: string; direction?: ExpectedDirection; -} +}; -export interface ExpectedShapeModelElement extends ExpectedModelElement { +export type ExpectedShapeModelElement = { kind?: ShapeBpmnElementKind; /** Generally needed when the BPMN shape doesn't exist yet (use an arbitrary shape until the final render is implemented) */ styleShape?: string; @@ -192,41 +193,41 @@ export interface ExpectedShapeModelElement extends ExpectedModelElement { isSwimLaneLabelHorizontal?: boolean; fill?: ExpectedFill; gradient?: ExpectedGradient; -} +} & ExpectedModelElement; -export interface ExpectedEventModelElement extends ExpectedShapeModelElement { +export type ExpectedEventModelElement = { eventDefinitionKind: ShapeBpmnEventDefinitionKind; -} +} & ExpectedShapeModelElement; -export interface ExpectedSubProcessModelElement extends ExpectedShapeModelElement { +export type ExpectedSubProcessModelElement = { subProcessKind: ShapeBpmnSubProcessKind; -} +} & ExpectedShapeModelElement; -export interface ExpectedCallActivityModelElement extends ExpectedShapeModelElement { +export type ExpectedCallActivityModelElement = { globalTaskKind?: GlobalTaskKind; -} +} & ExpectedShapeModelElement; -export interface ExpectedEdgeModelElement extends ExpectedModelElement { +export type ExpectedEdgeModelElement = { kind?: FlowKind; startArrow?: string; endArrow?: string; messageVisibleKind?: MessageVisibleKind; -} +} & ExpectedModelElement; -export interface ExpectedSequenceFlowModelElement extends ExpectedEdgeModelElement { +export type ExpectedSequenceFlowModelElement = { sequenceFlowKind?: SequenceFlowKind; -} +} & ExpectedEdgeModelElement; -export interface ExpectedBoundaryEventModelElement extends ExpectedEventModelElement { +export type ExpectedBoundaryEventModelElement = { isInterrupting?: boolean; -} -export interface ExpectedStartEventModelElement extends ExpectedEventModelElement { +} & ExpectedEventModelElement; +export type ExpectedStartEventModelElement = { isInterrupting?: boolean; -} +} & ExpectedEventModelElement; -export interface ExpectedEventBasedGatewayModelElement extends ExpectedShapeModelElement { +export type ExpectedEventBasedGatewayModelElement = { gatewayKind?: ShapeBpmnEventBasedGatewayKind; -} +} & ExpectedShapeModelElement; export const bpmnVisualization = new BpmnVisualization(null); const defaultParent = bpmnVisualization.graph.getDefaultParent(); diff --git a/test/integration/helpers/semantic-with-svg-utils.ts b/test/integration/helpers/semantic-with-svg-utils.ts index 296126c4a4..1d822f600b 100644 --- a/test/integration/helpers/semantic-with-svg-utils.ts +++ b/test/integration/helpers/semantic-with-svg-utils.ts @@ -20,7 +20,7 @@ import { expectEndEvent, expectPool, expectSequenceFlow, expectServiceTask, expe import { expectSvgEvent, expectSvgPool, expectSvgSequenceFlow, expectSvgTask } from './html-utils'; export function expectStartEventBpmnElement(bpmnElement: BpmnElement, expected: ExpectedFlowNodeElement): void { - expectStartEvent(bpmnElement.bpmnSemantic, expected); + expectStartEvent(bpmnElement.bpmnSemantic as ShapeBpmnSemantic, expected); expectSvgEvent(bpmnElement.htmlElement); } @@ -30,12 +30,12 @@ export function expectEndEventBpmnElement(bpmnElement: BpmnElement, expected: Ex } export function expectSequenceFlowBpmnElement(bpmnElement: BpmnElement, expected: ExpectedFlowElement): void { - expectSequenceFlow(bpmnElement.bpmnSemantic, expected); + expectSequenceFlow(bpmnElement.bpmnSemantic as EdgeBpmnSemantic, expected); expectSvgSequenceFlow(bpmnElement.htmlElement); } export function expectTaskBpmnElement(bpmnElement: BpmnElement, expected: ExpectedFlowNodeElement): void { - expectTask(bpmnElement.bpmnSemantic, expected); + expectTask(bpmnElement.bpmnSemantic as ShapeBpmnSemantic, expected); expectSvgTask(bpmnElement.htmlElement); } diff --git a/test/integration/mxGraph.model.style.api.test.ts b/test/integration/mxGraph.model.style.api.test.ts index 1196893398..92f17717e5 100644 --- a/test/integration/mxGraph.model.style.api.test.ts +++ b/test/integration/mxGraph.model.style.api.test.ts @@ -169,11 +169,11 @@ describe('mxGraph model - update style', () => { }); it.each([ - ['top-to-bottom', 'south'], - ['bottom-to-top', 'north'], - ['left-to-right', 'east'], - ['right-to-left', 'west'], - ])('Update the fill color as gradient with direction %s', (direction: GradientDirection, expectedDirection: ExpectedDirection) => { + ['top-to-bottom', 'south'], + ['bottom-to-top', 'north'], + ['left-to-right', 'east'], + ['right-to-left', 'west'], + ] as [GradientDirection, ExpectedDirection][])('Update the fill color as gradient with direction %s', (direction: GradientDirection, expectedDirection: ExpectedDirection) => { const fill = { color: { startColor: 'gold', endColor: 'pink', direction } }; bpmnVisualization.bpmnElementsRegistry.updateStyle('userTask_2_2', { fill }); @@ -559,7 +559,7 @@ describe('mxGraph model - update style', () => { }); // Reset the style by passing special values - bpmnVisualization.bpmnElementsRegistry.updateStyle('sequenceFlow_lane_3_elt_3', { + bpmnVisualization.bpmnElementsRegistry.updateStyle('sequenceFlow_lane_3_elt_3', { font: { color: 'default', opacity: 'default', @@ -570,7 +570,7 @@ describe('mxGraph model - update style', () => { opacity: 'default', width: 'default', }, - }); + } as EdgeStyleUpdate); // The properties should have been reset to use the default values expect('sequenceFlow_lane_3_elt_3').toBeSequenceFlow({ @@ -641,7 +641,7 @@ describe('mxGraph model - update style', () => { }); // Reset the style by passing special values - bpmnVisualization.bpmnElementsRegistry.updateStyle('MessageFlow_3_msgVisibilityKind_non_initiating', { + bpmnVisualization.bpmnElementsRegistry.updateStyle('MessageFlow_3_msgVisibilityKind_non_initiating', { font: { color: 'default', opacity: 'default', @@ -652,7 +652,7 @@ describe('mxGraph model - update style', () => { opacity: 'default', width: 'default', }, - }); + } as EdgeStyleUpdate); // The properties should have been reset to use the default values expect('MessageFlow_3_msgVisibilityKind_non_initiating').toBeMessageFlow({ diff --git a/test/performance/bpmn.load.performance.test.ts b/test/performance/bpmn.load.performance.test.ts index b407983029..c37227bee4 100644 --- a/test/performance/bpmn.load.performance.test.ts +++ b/test/performance/bpmn.load.performance.test.ts @@ -21,7 +21,7 @@ import type { ChartData, PerformanceMetric } from './helpers/perf-utils'; import { calculateMetrics } from './helpers/perf-utils'; import { performanceDataFilePath } from './helpers/file-utils'; -const metricsArray: Array = []; +const metricsArray: PerformanceMetric[] = []; let metricsCollector: ChromiumMetricsCollector; beforeAll(async () => { diff --git a/test/performance/bpmn.navigation.performance.test.ts b/test/performance/bpmn.navigation.performance.test.ts index d8700e11bf..139c35df2d 100644 --- a/test/performance/bpmn.navigation.performance.test.ts +++ b/test/performance/bpmn.navigation.performance.test.ts @@ -24,7 +24,7 @@ import { calculateMetrics } from './helpers/perf-utils'; import { ZoomType } from '@lib/component/options'; import { performanceDataFilePath } from './helpers/file-utils'; -const metricsArray: Array = []; +const metricsArray: PerformanceMetric[] = []; let metricsCollector: ChromiumMetricsCollector; beforeAll(async () => { diff --git a/test/performance/helpers/metrics-chromium.ts b/test/performance/helpers/metrics-chromium.ts index f10ac666e8..886abd112e 100644 --- a/test/performance/helpers/metrics-chromium.ts +++ b/test/performance/helpers/metrics-chromium.ts @@ -92,7 +92,7 @@ const supportedMetrics = new Set([ 'JSHeapTotalSize', ]); -function buildMetricsObject(metrics?: Array): Metrics { +function buildMetricsObject(metrics?: Metric[]): Metrics { const result: Metrics = {}; for (const metric of metrics ?? []) { if (supportedMetrics.has(metric.name)) { diff --git a/test/performance/helpers/perf-utils.ts b/test/performance/helpers/perf-utils.ts index 7b56fad6b5..daf87a1a7c 100644 --- a/test/performance/helpers/perf-utils.ts +++ b/test/performance/helpers/perf-utils.ts @@ -25,8 +25,8 @@ export interface PerformanceMetric { } export interface ChartData { - load: Array; - zoom: Array; + load: PerformanceMetric[]; + zoom: PerformanceMetric[]; } export function calculateMetrics(metricsStart: Metrics, metricsEnd: Metrics): PerformanceMetric { diff --git a/test/shared/overlays.ts b/test/shared/overlays.ts index 19410dfda6..9c2e775668 100644 --- a/test/shared/overlays.ts +++ b/test/shared/overlays.ts @@ -16,9 +16,9 @@ limitations under the License. import type { OverlayEdgePosition, OverlayShapePosition } from '@lib/component/registry'; -export const overlayEdgePositionValues = >['start', 'middle', 'end']; +export const overlayEdgePositionValues = ['start', 'middle', 'end'] as OverlayEdgePosition[]; -export const overlayShapePositionValues = >[ +export const overlayShapePositionValues = [ 'top-left', 'top-center', 'top-right', @@ -27,4 +27,4 @@ export const overlayShapePositionValues = >[ 'bottom-right', 'middle-left', 'middle-right', -]; +] as OverlayShapePosition[]; diff --git a/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts index b26b61d243..52a90a6bb3 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts @@ -296,14 +296,14 @@ describe('parse bpmn as json for sub-process', () => { const model = parseJsonAndExpectOnlySubProcess(json, expectedShapeBpmnSubProcessKind, 1); - verifyShape(model.flowNodes[0], { + verifyShape(model.flowNodes[0], { shapeId: 'shape_sub_process_id_1', bpmnElementId: 'sub_process_id_1', bpmnElementName: undefined, bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, bpmnElementMarkers: getExpectedMarkers([ShapeBpmnMarkerKind.EXPAND], expectedShapeBpmnSubProcessKind), bounds: expectedBounds, - }); + } as ExpectedActivityShape); }); } @@ -422,14 +422,14 @@ describe('parse bpmn as json for sub-process', () => { expectNoPoolLane(model); verifySubProcess(model, expectedShapeBpmnSubProcessKind, 1); - verifyShape(model.flowNodes[0], { + verifyShape(model.flowNodes[0], { shapeId: 'shape_sub-process_id_1', bpmnElementId: 'sub-process_id_1', bpmnElementName: undefined, bpmnElementKind: ShapeBpmnElementKind.SUB_PROCESS, bpmnElementMarkers: getExpectedMarkers([], expectedShapeBpmnSubProcessKind), bounds: { x: 365, y: 235, width: 300, height: 200 }, - }); + } as ExpectedActivityShape); const eventShapes = getEventShapes(model); expect(eventShapes).toHaveLength(2); diff --git a/test/unit/component/registry/bpmn-model-registry.test.ts b/test/unit/component/registry/bpmn-model-registry.test.ts index 1fd3f414c8..8ca73cd155 100644 --- a/test/unit/component/registry/bpmn-model-registry.test.ts +++ b/test/unit/component/registry/bpmn-model-registry.test.ts @@ -32,23 +32,23 @@ describe('Bpmn Model registry', () => { it('search sequence flow', () => { bpmnModelRegistry.load(sequenceFlowInModel('seq_flow_id', 'seq flow name', 'sourceRefId', 'targetRefId')); - const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('seq_flow_id'); + const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('seq_flow_id') as EdgeBpmnSemantic; expectSequenceFlow(bpmnSemantic, { id: 'seq_flow_id', name: 'seq flow name', source: 'sourceRefId', target: 'targetRefId' }); }); it('search message flow', () => { bpmnModelRegistry.load(messageFlowInModel('msg_flow_id', 'msg flow name', 'sourceRefId', 'targetRefId')); - const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('msg_flow_id'); + const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('msg_flow_id') as EdgeBpmnSemantic; expectMessageFlow(bpmnSemantic, { id: 'msg_flow_id', name: 'msg flow name', source: 'sourceRefId', target: 'targetRefId' }); }); it('search association flow', () => { bpmnModelRegistry.load(associationFlowInModel('association_flow_id', 'association flow name', 'sourceRefId', 'targetRefId')); - const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('association_flow_id'); + const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('association_flow_id') as EdgeBpmnSemantic; expectAssociationFlow(bpmnSemantic, { id: 'association_flow_id', name: 'association flow name', source: 'sourceRefId', target: 'targetRefId' }); }); it('search flowNode', () => { bpmnModelRegistry.load(startEventInModel('start event id', 'start event name', { incomingIds: ['incoming_1'], outgoingIds: ['outgoing_1', 'outgoing_2'] })); - const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('start event id'); + const bpmnSemantic = bpmnModelRegistry.getBpmnSemantic('start event id') as ShapeBpmnSemantic; expectStartEvent(bpmnSemantic, { id: 'start event id', name: 'start event name', incoming: ['incoming_1'], outgoing: ['outgoing_1', 'outgoing_2'] }); }); diff --git a/test/unit/helpers/JsonBuilder.ts b/test/unit/helpers/JsonBuilder.ts index 4b7e9651d1..be7b49547f 100644 --- a/test/unit/helpers/JsonBuilder.ts +++ b/test/unit/helpers/JsonBuilder.ts @@ -48,58 +48,58 @@ export enum EventDefinitionOn { * If the id field is set, the default id is override. * Otherwise, the id has the format: `event_id_${processIndex}_${index}` */ -interface BuildEventParameter extends TFlowNode { +type BuildEventParameter = { eventDefinitionParameter: BuildEventDefinitionParameter; -} +} & TFlowNode; -interface BuildInterruptingEventParameter extends BuildEventParameter { +type BuildInterruptingEventParameter = { isInterrupting?: boolean; -} +} & BuildEventParameter; export type BuildEventsParameter = BuildOtherEventParameter | BuildStartEventParameter | BuildBoundaryEventParameter; export type OtherBuildEventKind = 'endEvent' | 'intermediateCatchEvent' | 'intermediateThrowEvent'; -interface BuildOtherEventParameter extends BuildEventParameter { +type BuildOtherEventParameter = { bpmnKind: OtherBuildEventKind; -} +} & BuildEventParameter; -interface BuildStartEventParameter extends BuildInterruptingEventParameter { +type BuildStartEventParameter = { bpmnKind: 'startEvent'; -} +} & BuildInterruptingEventParameter; -interface BuildBoundaryEventParameter extends BuildInterruptingEventParameter { +type BuildBoundaryEventParameter = { bpmnKind: 'boundaryEvent'; attachedToRef: string; -} +} & BuildInterruptingEventParameter; -export interface BuildEventDefinitionParameter { +export type BuildEventDefinitionParameter = { eventDefinitionKind?: string; eventDefinitionOn: EventDefinitionOn; eventDefinition?: BPMNEventDefinition; withDifferentDefinition?: boolean; withMultipleDefinitions?: boolean; -} +}; export type BuildTaskKind = 'task' | 'businessRuleTask' | 'manualTask' | 'receiveTask' | 'sendTask' | 'serviceTask' | 'scriptTask' | 'userTask'; /** * If the id field is set, the default id is override. * Otherwise, the id has the format: `task_id_${processIndex}_${index}` */ -export interface BuildTaskParameter extends TFlowNode { +export type BuildTaskParameter = { /** @default 'task' */ bpmnKind?: BuildTaskKind; -} +} & TFlowNode; /** * If the id field is set, the default id is override. * Otherwise, the id has the format: `callActivity_id_${processIndex}_${index}` */ -export interface BuildCallActivityParameter extends TFlowNode { +export type BuildCallActivityParameter = { calledElement: string; /** @default false */ isExpanded?: boolean; -} +} & TFlowNode; /** * If the id field is set, the default id is override. @@ -117,9 +117,9 @@ export type BuildGatewayKind = 'complexGateway' | 'eventBasedGateway' | 'exclusi * If the id field is set, the default id is override. * Otherwise, the id has the format: `exclusiveGateway_id_${processIndex}_${index}` */ -export interface BuildGatewayParameter extends TFlowNode { +export type BuildGatewayParameter = { bpmnKind: BuildGatewayKind; -} +} & TFlowNode; /** * If the id field is set, the default id is override. @@ -131,10 +131,10 @@ export type BuildLaneParameter = TFlowElement; * If the id field is set, the default id is override. * Otherwise, the id has the format: `sequence_flow_id_${processIndex}_${index}` */ -export interface BuildSequenceFlowParameter extends TFlowElement { +export type BuildSequenceFlowParameter = { sourceRef: string; targetRef: string; -} +} & TFlowElement; /** * If the id field is set, the default id is override. @@ -148,7 +148,7 @@ export type BuildAssociationParameter = Pick; -export interface BuildProcessParameter { +export type BuildProcessParameter = { lane?: BuildLaneParameter | BuildLaneParameter[]; task?: BuildTaskParameter | BuildTaskParameter[]; event?: BuildEventsParameter | BuildEventsParameter[]; @@ -226,14 +226,14 @@ export interface BuildProcessParameter { /** @default false */ withParticipant?: boolean; -} +}; -export interface BuildMessageFlowParameter { +export type BuildMessageFlowParameter = { id: string; name?: string; sourceRef: string; targetRef: string; -} +}; export type BpmnGlobalTaskKind = keyof Pick; export type BuildGlobalTaskParameter = { @@ -243,16 +243,11 @@ export type BuildGlobalTaskParameter = { bpmnKind?: BpmnGlobalTaskKind; }; -export interface BuildTaskParameter extends TFlowNode { - /** @default 'task' */ - bpmnKind?: BuildTaskKind; -} - -export interface BuildDefinitionParameter { +export type BuildDefinitionParameter = { process: BuildProcessParameter | BuildProcessParameter[]; messageFlows?: BuildMessageFlowParameter | BuildMessageFlowParameter[]; globalTask?: BuildGlobalTaskParameter | BuildGlobalTaskParameter[]; -} +}; export function buildDefinitions({ process, messageFlows, globalTask }: BuildDefinitionParameter): BpmnJsonModel { const json: BpmnJsonModel = { diff --git a/test/unit/helpers/JsonTestUtils.ts b/test/unit/helpers/JsonTestUtils.ts index ca88bb33ec..ae1f70307b 100644 --- a/test/unit/helpers/JsonTestUtils.ts +++ b/test/unit/helpers/JsonTestUtils.ts @@ -25,7 +25,7 @@ import { ParsingMessageCollector } from '@lib/component/parser/parsing-messages' import type { ExpectedBounds, ExpectedFont, ExpectedLabel } from './bpmn-model-expect'; class ParsingMessageCollectorTester extends ParsingMessageCollector { - private warnings: Array = []; + private warnings: JsonParsingWarning[] = []; override warning(warning: JsonParsingWarning): void { this.warnings.push(warning); @@ -35,7 +35,7 @@ class ParsingMessageCollectorTester extends ParsingMessageCollector { this.warnings = []; } - getWarnings(): Array { + getWarnings(): JsonParsingWarning[] { return this.warnings; } }