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 some unicorn rules #2925

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ module.exports = {
'unicorn/prefer-logical-operator-over-ternary': 'error',
'unicorn/consistent-function-scoping': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/no-array-callback-reference': 'error',
Expand Down
2 changes: 1 addition & 1 deletion dev/ts/component/SvgExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CanvasForExport extends mxSvgCanvas2D {
let index = 0;

while ((exp == 0 || length < exp) && index < content.length) {
const char = content.charCodeAt(index);
const char = content.codePointAt(index);
if (char == 10 || char == 13) {
if (length > 0) {
break;
Expand Down
15 changes: 9 additions & 6 deletions dev/ts/shared/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ function collapseBpmnElement(bpmnElementId: string): void {
}

// callback function for opening | dropping the file to be loaded
function readAndLoadFile(f: File): void {
const reader = new FileReader();
reader.addEventListener('load', () => {
loadBpmn(reader.result as string);
});
reader.readAsText(f);
function readAndLoadFile(file: File): void {
file
.text()
.then(content => {
loadBpmn(content);
})
.catch(error => {
throw error;
});
}

// TODO: make File Open Button a self contained component
Expand Down
1 change: 1 addition & 0 deletions src/component/mxgraph/config/ShapeConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default class ShapeConfigurator {
if (!this.antiAlias) {
// Rounds all numbers in the SVG output to integers
canvas.format = function (value: string) {
// eslint-disable-next-line unicorn/prefer-number-properties -- mxGraph code
return Math.round(parseFloat(value));
};
}
Expand Down
16 changes: 9 additions & 7 deletions src/component/registry/bpmn-model-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ export class BpmnModelRegistry {
}

function toRenderedModel(bpmnModel: BpmnModel): RenderedModel {
const collapsedSubProcessIds: string[] = bpmnModel.flowNodes
.filter(shape => {
const bpmnElement = shape.bpmnElement;
return ShapeUtil.isSubProcess(bpmnElement.kind) && (bpmnElement as ShapeBpmnSubProcess).markers.includes(ShapeBpmnMarkerKind.EXPAND);
})
.map(shape => shape.bpmnElement.id);
const collapsedSubProcessIds = new Set(
bpmnModel.flowNodes
.filter(shape => {
const bpmnElement = shape.bpmnElement;
return ShapeUtil.isSubProcess(bpmnElement.kind) && (bpmnElement as ShapeBpmnSubProcess).markers.includes(ShapeBpmnMarkerKind.EXPAND);
})
.map(shape => shape.bpmnElement.id),
);

const subprocesses: Shape[] = [];
const boundaryEvents: Shape[] = [];
Expand All @@ -103,7 +105,7 @@ function toRenderedModel(bpmnModel: BpmnModel): RenderedModel {
subprocesses.push(shape);
} else if (ShapeUtil.isBoundaryEvent(kind)) {
boundaryEvents.push(shape);
} else if (!collapsedSubProcessIds.includes(shape.bpmnElement.parentId)) {
} else if (!collapsedSubProcessIds.has(shape.bpmnElement.parentId)) {
otherFlowNodes.push(shape);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/model/bpmn/internal/shape/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class ShapeUtil {
}

static isWithDefaultSequenceFlow(kind: ShapeBpmnElementKind): boolean {
return FLOW_NODE_WITH_DEFAULT_SEQUENCE_FLOW_KINDS.includes(kind);
return FLOW_NODE_WITH_DEFAULT_SEQUENCE_FLOW_KINDS.has(kind);
}

/**
Expand Down Expand Up @@ -127,12 +127,12 @@ const GATEWAY_KINDS = filterKind('Gateway');
const TASK_KINDS = filterKind('Task', { ignoreCase: true, notStartingWith: 'global' });

const ACTIVITY_KINDS = [...TASK_KINDS, ShapeBpmnElementKind.CALL_ACTIVITY, ShapeBpmnElementKind.SUB_PROCESS];
const FLOW_NODE_WITH_DEFAULT_SEQUENCE_FLOW_KINDS = [
const FLOW_NODE_WITH_DEFAULT_SEQUENCE_FLOW_KINDS = new Set([
...ACTIVITY_KINDS,
ShapeBpmnElementKind.GATEWAY_EXCLUSIVE,
ShapeBpmnElementKind.GATEWAY_INCLUSIVE,
ShapeBpmnElementKind.GATEWAY_COMPLEX,
];
]);

/**
* Elements that are effectively used in BPMN diagram as base for eventDefinition i.e all {@link ShapeBpmnEventDefinitionKind} elements except {@link ShapeBpmnEventDefinitionKind.NONE}
Expand Down
2 changes: 1 addition & 1 deletion test/config/jest.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RetriesCounter {
// https://github.com/facebook/jest/blob/v27.4.7/packages/jest-circus/src/run.ts#L46
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- code adapted from jest-circus
// @ts-ignore
private readonly retryTimes = parseInt(global[Symbol.for('RETRY_TIMES')], 10) || 0;
private readonly retryTimes = Number.parseInt(global[Symbol.for('RETRY_TIMES')], 10) || 0;

hasReachMaxRetries(testId: unknown): boolean {
return !this.retryTimes || this.getExecutionCount(testId) > this.retryTimes;
Expand Down
5 changes: 1 addition & 4 deletions test/shared/visu/bpmn-page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ import type { ElementHandle, Page } from 'playwright';
import debugLogger from 'debug';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-ignore js file with commonjs export
import environmentUtils = require('../environment-utils.cjs');

import { delay } from './test-utils';

import { FitType, type LoadOptions, ZoomType } from '@lib/component/options';
import { BpmnQuerySelectorsForTests } from '@test/shared/query-selectors';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore js file with commonjs export

const pageCheckLog = debugLogger('bv:test:page-check');

class BpmnPage {
Expand Down