diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 293d9e0d54..97bd59d88d 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -68,6 +68,9 @@ module.exports = { 'unicorn/require-array-join-separator': 'error', 'unicorn/numeric-separators-style': 'error', 'unicorn/no-zero-fractions': 'error', + 'unicorn/no-useless-switch-case': 'error', + 'unicorn/prefer-switch': 'error', + 'unicorn/switch-case-braces': 'error', 'import/newline-after-import': ['error', { count: 1 }], 'import/first': 'error', 'import/order': [ diff --git a/dev/ts/component/ThemedBpmnVisualization.ts b/dev/ts/component/ThemedBpmnVisualization.ts index 8322e39858..c7a8e36567 100644 --- a/dev/ts/component/ThemedBpmnVisualization.ts +++ b/dev/ts/component/ThemedBpmnVisualization.ts @@ -120,24 +120,28 @@ export class ThemedBpmnVisualization extends BpmnVisualization { let fillColor; let strokeColor; switch (kind) { - case 'endEvent': + case 'endEvent': { fillColor = theme.endEventFillColor; strokeColor = theme.endEventStrokeColor; break; - case 'startEvent': + } + case 'startEvent': { fillColor = theme.startEventFillColor; strokeColor = theme.startEventStrokeColor; break; + } case 'intermediateCatchEvent': case 'intermediateThrowEvent': - case 'boundaryEvent': + case 'boundaryEvent': { fillColor = theme.defaultFillColor; strokeColor = theme.catchAndThrowEventStrokeColor ?? theme.defaultStrokeColor; break; - default: + } + default: { fillColor = theme.defaultFillColor; strokeColor = theme.defaultStrokeColor; break; + } } const style = styleSheet.styles[kind]; style['fillColor'] = fillColor; diff --git a/dev/ts/pages/elements-identification.ts b/dev/ts/pages/elements-identification.ts index a210a94470..d43c9a1c6e 100644 --- a/dev/ts/pages/elements-identification.ts +++ b/dev/ts/pages/elements-identification.ts @@ -53,11 +53,12 @@ function computeStyleUpdateByKind(bpmnKind: BpmnElementKind): StyleUpdate { switch (bpmnKind) { case 'messageFlow': case 'sequenceFlow': - case 'association': + case 'association': { style.font.color = 'Chocolate'; style.stroke.color = 'Chocolate'; style.stroke.width = 4; break; + } } return style; } @@ -106,7 +107,7 @@ function computeStyleUpdateByKind(bpmnKind: BpmnElementKind): StyleUpdate { } else { switch (bpmnKind) { case 'group': - case 'textAnnotation': + case 'textAnnotation': { style.font.color = 'Crimson'; style.font.size = 18; style.font.family = 'Verdana'; @@ -116,6 +117,7 @@ function computeStyleUpdateByKind(bpmnKind: BpmnElementKind): StyleUpdate { style.stroke.color = 'Chartreuse'; style.stroke.width = 6; break; + } } } return style; diff --git a/src/component/mxgraph/BpmnGraph.ts b/src/component/mxgraph/BpmnGraph.ts index 9580e24632..536587191e 100644 --- a/src/component/mxgraph/BpmnGraph.ts +++ b/src/component/mxgraph/BpmnGraph.ts @@ -149,12 +149,14 @@ export class BpmnGraph extends mxgraph.mxGraph { let ignoreWidth = false; let ignoreHeight = false; switch (type) { - case FitType.Horizontal: + case FitType.Horizontal: { ignoreHeight = true; break; - case FitType.Vertical: + } + case FitType.Vertical: { ignoreWidth = true; break; + } } this.fit(this.border, false, margin, true, ignoreWidth, ignoreHeight); diff --git a/src/component/mxgraph/renderer/style-utils.ts b/src/component/mxgraph/renderer/style-utils.ts index e3bea732a6..e013403f90 100644 --- a/src/component/mxgraph/renderer/style-utils.ts +++ b/src/component/mxgraph/renderer/style-utils.ts @@ -62,21 +62,27 @@ export function computeAllBpmnClassNames(style: string, isLabel: boolean): strin return [elements[0], elements[1]]; })) { switch (key) { - case BpmnStyleIdentifier.EVENT_DEFINITION_KIND: + case BpmnStyleIdentifier.EVENT_DEFINITION_KIND: { classes.push(`bpmn-event-def-${value}`); break; - case BpmnStyleIdentifier.EVENT_BASED_GATEWAY_KIND: + } + case BpmnStyleIdentifier.EVENT_BASED_GATEWAY_KIND: { classes.push(`bpmn-gateway-kind-${value.toLowerCase()}`); break; - case BpmnStyleIdentifier.IS_INITIATING: // message flow icon + } + case BpmnStyleIdentifier.IS_INITIATING: { + // message flow icon classes.push(value == 'true' ? 'bpmn-icon-initiating' : 'bpmn-icon-non-initiating'); break; - case BpmnStyleIdentifier.SUB_PROCESS_KIND: + } + case BpmnStyleIdentifier.SUB_PROCESS_KIND: { classes.push(`bpmn-sub-process-${value.toLowerCase()}`); break; - case BpmnStyleIdentifier.GLOBAL_TASK_KIND: + } + case BpmnStyleIdentifier.GLOBAL_TASK_KIND: { classes.push(computeBpmnBaseClassName(value)); break; + } } } diff --git a/src/component/mxgraph/shape/activity-shapes.ts b/src/component/mxgraph/shape/activity-shapes.ts index 022ca6cc74..d535d9a6e2 100644 --- a/src/component/mxgraph/shape/activity-shapes.ts +++ b/src/component/mxgraph/shape/activity-shapes.ts @@ -62,18 +62,22 @@ export abstract class BaseActivityShape extends mxRectangleShape { }; paintParameter.canvas.save(); // ensure we can later restore the configuration switch (marker) { - case ShapeBpmnMarkerKind.LOOP: + case ShapeBpmnMarkerKind.LOOP: { this.iconPainter.paintLoopIcon(paintParameter); break; - case ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL: + } + case ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL: { this.iconPainter.paintSequentialMultiInstanceIcon(paintParameter); break; - case ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL: + } + case ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL: { this.iconPainter.paintParallelMultiInstanceIcon(paintParameter); break; - case ShapeBpmnMarkerKind.EXPAND: + } + case ShapeBpmnMarkerKind.EXPAND: { this.iconPainter.paintExpandIcon(paintParameter); break; + } } // Restore original configuration to avoid side effects if the iconPainter changed the canvas configuration (colors, ....) paintParameter.canvas.restore(); @@ -211,7 +215,7 @@ export class CallActivityShape extends BaseActivityShape { const paintParameter = buildPaintParameter({ canvas: c, x, y, width: w, height: h, shape: this }); switch (mxUtils.getValue(this.style, BpmnStyleIdentifier.GLOBAL_TASK_KIND, undefined)) { - case ShapeBpmnElementKind.GLOBAL_TASK_MANUAL: + case ShapeBpmnElementKind.GLOBAL_TASK_MANUAL: { this.iconPainter.paintHandIcon({ ...paintParameter, ratioFromParent: 0.18, @@ -219,7 +223,8 @@ export class CallActivityShape extends BaseActivityShape { }); break; - case ShapeBpmnElementKind.GLOBAL_TASK_SCRIPT: + } + case ShapeBpmnElementKind.GLOBAL_TASK_SCRIPT: { this.iconPainter.paintScriptIcon({ ...paintParameter, ratioFromParent: 0.22, @@ -227,20 +232,23 @@ export class CallActivityShape extends BaseActivityShape { }); break; - case ShapeBpmnElementKind.GLOBAL_TASK_USER: + } + case ShapeBpmnElementKind.GLOBAL_TASK_USER: { this.iconPainter.paintPersonIcon({ ...paintParameter, setIconOriginFunct: (canvas: BpmnCanvas) => canvas.setIconOriginToShapeTopLeftProportionally(20) }); break; - case ShapeBpmnElementKind.GLOBAL_TASK_BUSINESS_RULE: + } + case ShapeBpmnElementKind.GLOBAL_TASK_BUSINESS_RULE: { this.iconPainter.paintTableIcon({ ...paintParameter, ratioFromParent: 0.6, setIconOriginFunct: (canvas: BpmnCanvas) => canvas.setIconOriginToShapeTopLeftProportionally(15), }); break; - case ShapeBpmnElementKind.GLOBAL_TASK: - default: + } + default: { // No symbol for the Call Activity calling a Global Task or calling a Process this.iconPainter.paintEmptyIcon(); + } } } } diff --git a/src/component/mxgraph/style/utils.ts b/src/component/mxgraph/style/utils.ts index 04242b2a0e..ee6a6ad322 100644 --- a/src/component/mxgraph/style/utils.ts +++ b/src/component/mxgraph/style/utils.ts @@ -121,14 +121,18 @@ export const getStyleValue = (cellStyle: string, key: string, defaultValue: stri const convertDirection = (direction: GradientDirection): string => { switch (direction) { - case 'right-to-left': + case 'right-to-left': { return mxConstants.DIRECTION_WEST; - case 'bottom-to-top': + } + case 'bottom-to-top': { return mxConstants.DIRECTION_NORTH; - case 'top-to-bottom': + } + case 'top-to-bottom': { return mxConstants.DIRECTION_SOUTH; - default: + } + default: { return mxConstants.DIRECTION_EAST; + } } }; diff --git a/src/component/parser/json/converter/ProcessConverter.ts b/src/component/parser/json/converter/ProcessConverter.ts index 85d347484d..001b49358d 100644 --- a/src/component/parser/json/converter/ProcessConverter.ts +++ b/src/component/parser/json/converter/ProcessConverter.ts @@ -63,12 +63,15 @@ type BpmnSemanticType = keyof TProcess; const computeSubProcessKind = (processedSemanticType: BpmnSemanticType, bpmnElement: TSubProcess): ShapeBpmnSubProcessKind => { switch (processedSemanticType) { - case 'adHocSubProcess': + case 'adHocSubProcess': { return ShapeBpmnSubProcessKind.AD_HOC; - case 'transaction': + } + case 'transaction': { return ShapeBpmnSubProcessKind.TRANSACTION; - default: + } + default: { return bpmnElement.triggeredByEvent ? ShapeBpmnSubProcessKind.EVENT : ShapeBpmnSubProcessKind.EMBEDDED; + } } }; diff --git a/test/e2e/helpers/visu/image-snapshot-config.ts b/test/e2e/helpers/visu/image-snapshot-config.ts index e8655f81f0..9b72627882 100644 --- a/test/e2e/helpers/visu/image-snapshot-config.ts +++ b/test/e2e/helpers/visu/image-snapshot-config.ts @@ -134,27 +134,35 @@ export class MultiBrowserImageSnapshotThresholds { const testedBrowserFamily = getTestedBrowserFamily(); configLog(`The browser family used for test is ${testedBrowserFamily}`); switch (testedBrowserFamily) { - case 'chromium': + case 'chromium': { return this.getChromiumThresholds(); - case 'firefox': + } + case 'firefox': { return this.getFirefoxThresholds(); - case 'webkit': + } + case 'webkit': { return this.getWebkitThresholds(); - default: + } + default: { return new Map(); + } } } getDefault(): number { switch (getTestedBrowserFamily()) { - case 'chromium': + case 'chromium': { return this.chromiumDefault; - case 'firefox': + } + case 'firefox': { return this.firefoxDefault; - case 'webkit': + } + case 'webkit': { return this.webkitDefault; - default: + } + default: { return 0; + } } } } diff --git a/test/unit/helpers/JsonBuilder.ts b/test/unit/helpers/JsonBuilder.ts index f07d244697..ab4bb2a98e 100644 --- a/test/unit/helpers/JsonBuilder.ts +++ b/test/unit/helpers/JsonBuilder.ts @@ -565,18 +565,22 @@ function addEvent( ): void { const event = buildEvent({ id, name, index, processIndex, ...rest }); switch (eventDefinitionParameter.eventDefinitionOn) { - case EventDefinitionOn.BOTH: + case EventDefinitionOn.BOTH: { addEventDefinitionsOnEvent(event, eventDefinitionParameter); addEventDefinitionsOnDefinition(jsonModel, eventDefinitionParameter, event); break; - case EventDefinitionOn.DEFINITIONS: + } + case EventDefinitionOn.DEFINITIONS: { addEventDefinitionsOnDefinition(jsonModel, eventDefinitionParameter, event); break; - case EventDefinitionOn.EVENT: + } + case EventDefinitionOn.EVENT: { addEventDefinitionsOnEvent(event, eventDefinitionParameter); break; - case EventDefinitionOn.NONE: + } + case EventDefinitionOn.NONE: { break; + } } addProcessElementWithShape(jsonModel, bpmnKind, { ...event, index, processIndex }, { Bounds: { x: 362, y: 232, width: 36, height: 45 } });