Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eslint): add unicorn Switch rules #2881

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
12 changes: 8 additions & 4 deletions dev/ts/component/ThemedBpmnVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions dev/ts/pages/elements-identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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';
Expand All @@ -116,6 +117,7 @@ function computeStyleUpdateByKind(bpmnKind: BpmnElementKind): StyleUpdate {
style.stroke.color = 'Chartreuse';
style.stroke.width = 6;
break;
}
}
}
return style;
Expand Down
6 changes: 4 additions & 2 deletions src/component/mxgraph/BpmnGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions src/component/mxgraph/renderer/style-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: may be clearer with the comment on the top of the case entry. This is what we generally do in the code.

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;
}
}
}

Expand Down
28 changes: 18 additions & 10 deletions src/component/mxgraph/shape/activity-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -211,36 +215,40 @@ 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,
setIconOriginFunct: (canvas: BpmnCanvas) => canvas.setIconOriginToShapeTopLeftProportionally(20),
});

break;
case ShapeBpmnElementKind.GLOBAL_TASK_SCRIPT:
}
case ShapeBpmnElementKind.GLOBAL_TASK_SCRIPT: {
this.iconPainter.paintScriptIcon({
...paintParameter,
ratioFromParent: 0.22,
setIconOriginFunct: (canvas: BpmnCanvas) => canvas.setIconOriginToShapeTopLeftProportionally(20),
});

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();
}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/component/mxgraph/style/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
};

Expand Down
9 changes: 6 additions & 3 deletions src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
};

Expand Down
24 changes: 16 additions & 8 deletions test/e2e/helpers/visu/image-snapshot-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ImageSnapshotThresholdConfig>();
}
}
}

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;
}
}
}
}
12 changes: 8 additions & 4 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand Down