Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Sep 19, 2023
1 parent ea25e3d commit 28bd2fd
Show file tree
Hide file tree
Showing 25 changed files with 154 additions and 170 deletions.
2 changes: 1 addition & 1 deletion dev/ts/component/DropFileUserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DropFileUserInterface {
}

private preventDefaultsOnEvents(events: string[], container: Element | Window): void {
events.forEach(eventName => container.addEventListener(eventName, this.preventDefaults.bind(this), false));
for (const eventName of events) container.addEventListener(eventName, this.preventDefaults.bind(this), false);
}

private addDomElements(containerToBeFaded: HTMLElement): void {
Expand Down
8 changes: 4 additions & 4 deletions dev/ts/component/ThemedBpmnVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ThemedBpmnVisualization extends BpmnVisualization {
const styleSheet = this.graph.getStylesheet();

// EVENT
ShapeUtil.eventKinds().forEach(kind => {
for (const kind of ShapeUtil.eventKinds()) {
let fillColor;
let strokeColor;
switch (kind) {
Expand All @@ -142,13 +142,13 @@ export class ThemedBpmnVisualization extends BpmnVisualization {
const style = styleSheet.styles[kind];
style['fillColor'] = fillColor;
style['strokeColor'] = strokeColor;
});
}

// TASK
ShapeUtil.taskKinds().forEach(kind => {
for (const kind of ShapeUtil.taskKinds()) {
const style = styleSheet.styles[kind];
style['fillColor'] = theme.taskAndCallActivityFillColor;
});
}

// CALL ACTIVITY
const callActivityStyle = styleSheet.styles[ShapeBpmnElementKind.CALL_ACTIVITY];
Expand Down
8 changes: 4 additions & 4 deletions dev/ts/pages/diagram-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
import { configureControlsPanel, configureMousePointer, documentReady, fit, FitType, startBpmnVisualization, zoom, ZoomType } from '../development-bundle-index';

function configureFitAndZoomButtons(): void {
Object.values(FitType).forEach(fitType => {
for (const fitType of Object.values(FitType)) {
document.querySelector(`#${fitType}`).addEventListener('click', () => fit({ type: fitType }));
});
Object.values(ZoomType).forEach(zoomType => {
}
for (const zoomType of Object.values(ZoomType)) {
document.querySelector(`#zoom-${zoomType}`).addEventListener('click', () => zoom(zoomType));
});
}
}

function configureZoomThrottleInput(parameters: URLSearchParams): HTMLInputElement {
Expand Down
6 changes: 3 additions & 3 deletions dev/ts/pages/elements-identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ function resetStyleByAPI(): void {
}

function manageOverlays(idsToAddOverlay: string[], bpmnKind: ShapeBpmnElementKind): void {
lastIdentifiedBpmnIds.forEach(id => removeAllOverlays(id));
for (const id of lastIdentifiedBpmnIds) removeAllOverlays(id);
if (isOverlaysDisplayed) {
idsToAddOverlay.forEach(id => addOverlays(id, getOverlay(bpmnKind)));
for (const id of idsToAddOverlay) addOverlays(id, getOverlay(bpmnKind));
} else {
log('Do not display overlays');
}
Expand Down Expand Up @@ -207,7 +207,7 @@ function configureControls(): void {
resetTextArea();

useCSS ? removeCssClasses(lastIdentifiedBpmnIds, cssClassName) : resetStyleByAPI();
lastIdentifiedBpmnIds.forEach(id => removeAllOverlays(id));
for (const id of lastIdentifiedBpmnIds) removeAllOverlays(id);

// reset identified elements and values
lastIdentifiedBpmnIds = [];
Expand Down
4 changes: 2 additions & 2 deletions dev/ts/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function configureFitMarginInput(): void {
}

function configureZoomButtons(): void {
Object.values(ZoomType).forEach(zoomType => {
for (const zoomType of Object.values(ZoomType)) {
document.querySelector(`#zoom-${zoomType}`).addEventListener('click', () => zoom(zoomType));
});
}
document.querySelector(`#zoom-reset`).addEventListener('click', () => fit(fitOptions));
}

Expand Down
16 changes: 7 additions & 9 deletions scripts/prepare-demo-for-publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ const updateAssetsLoadingFile = path => {
const demoRootDirectory = './build/demo';
const htmlPagesPath = join(demoRootDirectory, 'dev/public');
const pages = readdirSync(htmlPagesPath);
pages
.filter(file => extname(file).toLowerCase() === '.html')
.forEach(page => {
// eslint-disable-next-line no-console
console.info('Managing', page);

// change the path of the assets in the current html page
updateAssetsLoadingFile(join(htmlPagesPath, page));
});
for (const page of pages.filter(file => extname(file).toLowerCase() === '.html')) {
// eslint-disable-next-line no-console
console.info('Managing', page);

// change the path of the assets in the current html page
updateAssetsLoadingFile(join(htmlPagesPath, page));
}

// copy ./index.html in build/demo directory, to reproduce the hierarchy on the examples' repo, on the demo preview in GitHub
copyFileSync('./index.html', join(demoRootDirectory, 'index.html'));
6 changes: 3 additions & 3 deletions src/component/mxgraph/BpmnRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class BpmnRenderer {
}

private insertShapes(shapes: Shape[]): void {
shapes.forEach(shape => this.insertShape(shape));
for (const shape of shapes) this.insertShape(shape);
}

private getParent(bpmnElement: ShapeBpmnElement): mxCell {
Expand All @@ -81,7 +81,7 @@ export class BpmnRenderer {
}

private insertEdges(edges: Edge[]): void {
edges.forEach(internalEdge => {
for (const internalEdge of edges) {
const bpmnElement = internalEdge.bpmnElement;
const parent = this.graph.getDefaultParent();
const source = this.getCell(bpmnElement.sourceReferenceId);
Expand All @@ -107,7 +107,7 @@ export class BpmnRenderer {
}

this.insertMessageFlowIconIfNeeded(internalEdge, edge);
});
}
}

private insertMessageFlowIconIfNeeded(internalEdge: Edge, edge: mxCell): void {
Expand Down
16 changes: 8 additions & 8 deletions src/component/mxgraph/config/StyleConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ export class StyleConfigurator {
}

private configureEventStyles(): void {
ShapeUtil.eventKinds().forEach(kind => {
for (const kind of ShapeUtil.eventKinds()) {
const style: StyleMap = {};
style[mxConstants.STYLE_SHAPE] = kind;
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.EllipsePerimeter;
style[mxConstants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.EVENT_END ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_BOTTOM;
this.putCellStyle(kind, style);
});
}
}

private configureTextAnnotationStyle(): void {
Expand Down Expand Up @@ -202,18 +202,18 @@ export class StyleConfigurator {
}

private configureActivityStyles(): void {
ShapeUtil.activityKinds().forEach(kind => {
for (const kind of ShapeUtil.activityKinds()) {
const style: StyleMap = {};
style[mxConstants.STYLE_SHAPE] = kind;
style[mxConstants.STYLE_ROUNDED] = true; // required by the BPMN specification
style[mxConstants.STYLE_VERTICAL_ALIGN] = mxConstants.ALIGN_MIDDLE;
style[mxConstants.STYLE_STROKEWIDTH] = kind == ShapeBpmnElementKind.CALL_ACTIVITY ? StyleDefault.STROKE_WIDTH_THICK : StyleDefault.STROKE_WIDTH_THIN;
this.putCellStyle(kind, style);
});
}
}

private configureGatewayStyles(): void {
ShapeUtil.gatewayKinds().forEach(kind => {
for (const kind of ShapeUtil.gatewayKinds()) {
const style: StyleMap = {};
style[mxConstants.STYLE_SHAPE] = kind;
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RhombusPerimeter;
Expand All @@ -225,7 +225,7 @@ export class StyleConfigurator {
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_TOP;

this.putCellStyle(kind, style);
});
}
}

private configureDefaultEdgeStyle(): void {
Expand All @@ -244,11 +244,11 @@ export class StyleConfigurator {
}

private configureEdgeStyles<T>(styleKinds: T[], specificStyles: Map<T, (style: StyleMap) => void>): void {
styleKinds.forEach(kind => {
for (const kind of styleKinds) {
const style: StyleMap = {};
specificStyles.get(kind)(style);
this.graph.getStylesheet().putCellStyle(kind.toString(), style);
});
}
}

private configureFlowStyles(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/overlay/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export class OverlaysUpdater {
if (!cell) {
return;
}
ensureIsArray(overlays).forEach(overlay => {
for (const overlay of ensureIsArray(overlays)) {
const bpmnOverlay = new MxGraphCustomOverlay(overlay.label, this.overlayConverter.convert(overlay));
this.graph.addCellOverlay(cell, bpmnOverlay);
});
}
}

removeAllOverlays(bpmnElementId: string): void {
Expand Down
48 changes: 23 additions & 25 deletions src/component/mxgraph/renderer/style-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,32 @@ export function computeAllBpmnClassNames(style: string, isLabel: boolean): strin
typeClasses.set('bpmn-type-flow', isFlowKind(bpmnElementKind));
typeClasses.set('bpmn-type-gateway', ShapeUtil.isGateway(bpmnElementKind));
typeClasses.set('bpmn-type-task', ShapeUtil.isTask(bpmnElementKind));
[...typeClasses].filter(([, isType]) => isType).forEach(([className]) => classes.push(className));
for (const [className] of [...typeClasses].filter(([, isType]) => isType)) classes.push(className);

classes.push(computeBpmnBaseClassName(bpmnElementKind));

styleElements
.map(entry => {
const elements = entry.split('=');
return [elements[0], elements[1]];
})
.forEach(([key, value]) => {
switch (key) {
case BpmnStyleIdentifier.EVENT_DEFINITION_KIND:
classes.push(`bpmn-event-def-${value}`);
break;
case BpmnStyleIdentifier.EVENT_BASED_GATEWAY_KIND:
classes.push(`bpmn-gateway-kind-${value.toLowerCase()}`);
break;
case BpmnStyleIdentifier.IS_INITIATING: // message flow icon
classes.push(value == 'true' ? 'bpmn-icon-initiating' : 'bpmn-icon-non-initiating');
break;
case BpmnStyleIdentifier.SUB_PROCESS_KIND:
classes.push(`bpmn-sub-process-${value.toLowerCase()}`);
break;
case BpmnStyleIdentifier.GLOBAL_TASK_KIND:
classes.push(computeBpmnBaseClassName(value));
break;
}
});
for (const [key, value] of styleElements.map(entry => {
const elements = entry.split('=');
return [elements[0], elements[1]];
})) {
switch (key) {
case BpmnStyleIdentifier.EVENT_DEFINITION_KIND:
classes.push(`bpmn-event-def-${value}`);
break;
case BpmnStyleIdentifier.EVENT_BASED_GATEWAY_KIND:
classes.push(`bpmn-gateway-kind-${value.toLowerCase()}`);
break;
case BpmnStyleIdentifier.IS_INITIATING: // message flow icon
classes.push(value == 'true' ? 'bpmn-icon-initiating' : 'bpmn-icon-non-initiating');
break;
case BpmnStyleIdentifier.SUB_PROCESS_KIND:
classes.push(`bpmn-sub-process-${value.toLowerCase()}`);
break;
case BpmnStyleIdentifier.GLOBAL_TASK_KIND:
classes.push(computeBpmnBaseClassName(value));
break;
}
}

if (isLabel) {
classes.push('bpmn-label');
Expand Down
7 changes: 4 additions & 3 deletions src/component/mxgraph/shape/activity-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export abstract class BaseActivityShape extends mxRectangleShape {
protected paintMarkerIcons(paintParameter: PaintParameter): void {
const markers = mxUtils.getValue(this.style, BpmnStyleIdentifier.MARKERS, undefined);
if (markers) {
orderActivityMarkers(markers.split(',')).forEach((marker, index, allMarkers) => {
const orderedMarkers = orderActivityMarkers(markers.split(','));
for (const [index, marker] of orderedMarkers.entries()) {
paintParameter = {
...paintParameter,
setIconOriginFunct: this.getMarkerIconOriginFunction(allMarkers.length, index + 1),
setIconOriginFunct: this.getMarkerIconOriginFunction(orderedMarkers.length, index + 1),
};
paintParameter.canvas.save(); // ensure we can later restore the configuration
switch (marker) {
Expand All @@ -76,7 +77,7 @@ export abstract class BaseActivityShape extends mxRectangleShape {
}
// Restore original configuration to avoid side effects if the iconPainter changed the canvas configuration (colors, ....)
paintParameter.canvas.restore();
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/component/mxgraph/shape/render/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ const referenceOrderedMarkers = [
export function orderActivityMarkers(markers: string[]): string[] {
const orderedMarkers: string[] = referenceOrderedMarkers.filter(marker => markers.includes(marker));
// Put extra remaining at the end of the ordered markers, in the order they appear in the original array
markers.filter(marker => !orderedMarkers.includes(marker)).forEach(marker => orderedMarkers.push(marker));
for (const marker of markers.filter(marker => !orderedMarkers.includes(marker))) orderedMarkers.push(marker);
return orderedMarkers;
}
5 changes: 2 additions & 3 deletions src/component/parser/json/converter/CategoryConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default class CategoryConverter {
constructor(private convertedElements: ConvertedElements) {}

deserialize(definitions: TDefinitions): void {
ensureIsArray<TCategory>(definitions.category).forEach(category =>
ensureIsArray(category.categoryValue).forEach(categoryValue => this.convertedElements.registerCategoryValue(categoryValue.id, categoryValue.value)),
);
for (const category of ensureIsArray<TCategory>(definitions.category))
for (const categoryValue of ensureIsArray(category.categoryValue)) this.convertedElements.registerCategoryValue(categoryValue.id, categoryValue.value);
}
}
16 changes: 7 additions & 9 deletions src/component/parser/json/converter/CollaborationConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class CollaborationConverter {
) {}

deserialize(collaborations: string | TCollaboration | (string | TCollaboration)[]): void {
ensureIsArray(collaborations).forEach(collaboration => this.parseCollaboration(collaboration));
for (const collaboration of ensureIsArray(collaborations)) this.parseCollaboration(collaboration);
}

private parseCollaboration(collaboration: TCollaboration): void {
Expand All @@ -48,21 +48,19 @@ export default class CollaborationConverter {
}

private buildParticipant(bpmnElements: TParticipant[] | TParticipant): void {
ensureIsArray(bpmnElements).forEach(participant =>
this.convertedElements.registerPool(new ShapeBpmnElement(participant.id, participant.name, ShapeBpmnElementKind.POOL), participant.processRef),
);
for (const participant of ensureIsArray(bpmnElements))
this.convertedElements.registerPool(new ShapeBpmnElement(participant.id, participant.name, ShapeBpmnElementKind.POOL), participant.processRef);
}

private buildMessageFlows(bpmnElements: TMessageFlow[] | TMessageFlow): void {
ensureIsArray(bpmnElements).forEach(messageFlow =>
this.convertedElements.registerMessageFlow(new MessageFlow(messageFlow.id, messageFlow.name, messageFlow.sourceRef, messageFlow.targetRef)),
);
for (const messageFlow of ensureIsArray(bpmnElements))
this.convertedElements.registerMessageFlow(new MessageFlow(messageFlow.id, messageFlow.name, messageFlow.sourceRef, messageFlow.targetRef));
}

private buildGroups(bpmnElements: TGroup[] | TGroup): void {
ensureIsArray(bpmnElements).forEach(groupBpmnElement => {
for (const groupBpmnElement of ensureIsArray(bpmnElements)) {
const shapeBpmnElement = buildShapeBpmnGroup(this.convertedElements, this.parsingMessageCollector, groupBpmnElement);
shapeBpmnElement && this.convertedElements.registerFlowNode(shapeBpmnElement);
});
}
}
}
18 changes: 8 additions & 10 deletions src/component/parser/json/converter/DiagramConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,30 @@ export default class DiagramConverter {
private deserializeFonts(bpmnLabelStyle: BPMNLabelStyle[] | BPMNLabelStyle): void {
this.convertedFonts = new Map();

ensureIsArray(bpmnLabelStyle).forEach(labelStyle =>
ensureIsArray(labelStyle.Font).forEach(font =>
this.convertedFonts.set(labelStyle.id, new Font(font.name, font.size, font.isBold, font.isItalic, font.isUnderline, font.isStrikeThrough)),
),
);
for (const labelStyle of ensureIsArray(bpmnLabelStyle))
for (const font of ensureIsArray(labelStyle.Font))
this.convertedFonts.set(labelStyle.id, new Font(font.name, font.size, font.isBold, font.isItalic, font.isUnderline, font.isStrikeThrough));
}

private deserializeShapes(shapes: BPMNShape[] | BPMNShape): Shapes {
const convertedShapes: Shapes = { flowNodes: [], lanes: [], pools: [] };

ensureIsArray(shapes).forEach(shape => {
for (const shape of ensureIsArray(shapes)) {
// flow nodes
if (this.deserializeShapeAndStoreIfFound(shape, convertedShapes.flowNodes, (bpmnElementId: string) => this.convertedElements.findFlowNode(bpmnElementId))) {
return;
continue;
}
// lane
if (this.deserializeShapeAndStoreIfFound(shape, convertedShapes.lanes, (bpmnElementId: string) => this.convertedElements.findLane(bpmnElementId))) {
return;
continue;
}
// pool
if (this.deserializeShapeAndStoreIfFound(shape, convertedShapes.pools, (bpmnElementId: string) => this.convertedElements.findPoolById(bpmnElementId))) {
return;
continue;
}
// not found
this.parsingMessageCollector.warning(new ShapeUnknownBpmnElementWarning(shape.bpmnElement));
});
}

return convertedShapes;
}
Expand Down
Loading

0 comments on commit 28bd2fd

Please sign in to comment.