Skip to content

Commit

Permalink
chore(eslint): add unicorn/prefer-ternary rule (#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet authored Sep 21, 2023
1 parent 01e730f commit f150db6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 44 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
'unicorn/prefer-add-event-listener': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-ternary': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/first': 'error',
'import/order': [
Expand Down
6 changes: 1 addition & 5 deletions scripts/utils/parseBpmn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ const json = xmlParser.parse(readFileSync(bpmnFilePath, 'utf-8', __dirname));
const prettyString = (object: BpmnJsonModel | BpmnModel): string => JSON.stringify(object, null, 2);

let result = '';
if (outputType === 'json') {
result = prettyString(json);
} else {
result = prettyString(newBpmnJsonParser(new ParsingMessageCollector()).parse(json));
}
result = outputType === 'json' ? prettyString(json) : prettyString(newBpmnJsonParser(new ParsingMessageCollector()).parse(json));

// copy to clipboard
// disabling the copy is not officially supported, it currently fails on GitHub actions when running on Ubuntu 20.04. So disabling it only in this case.
Expand Down
24 changes: 10 additions & 14 deletions src/component/mxgraph/shape/activity-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,16 @@ export abstract class BaseActivityShape extends mxRectangleShape {
}

private getMarkerIconOriginFunction(allMarkers: number, markerOrder: number): (canvas: BpmnCanvas) => void {
let setIconOriginFunction: (canvas: BpmnCanvas) => void;
if (allMarkers === 1) {
setIconOriginFunction = (canvas: BpmnCanvas) => canvas.setIconOriginForIconBottomCentered();
}
// Here we suppose that we have 'allMarkers === 2'
// More markers will be supported when implementing adhoc subprocess or compensation marker
else {
setIconOriginFunction = (canvas: BpmnCanvas) => {
canvas.setIconOriginForIconBottomCentered();
const xTranslation = Math.pow(-1, markerOrder) * (StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_SIZE / 2 + StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_MARGIN);
canvas.translateIconOrigin(xTranslation, 0);
};
}
return setIconOriginFunction;
return allMarkers === 1
? (canvas: BpmnCanvas) => canvas.setIconOriginForIconBottomCentered()
: (canvas: BpmnCanvas) => {
// Here we suppose that we have 'allMarkers === 2'
// More markers will be supported when implementing adhoc subprocess or compensation marker

canvas.setIconOriginForIconBottomCentered();
const xTranslation = Math.pow(-1, markerOrder) * (StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_SIZE / 2 + StyleDefault.SHAPE_ACTIVITY_MARKER_ICON_MARGIN);
canvas.translateIconOrigin(xTranslation, 0);
};
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,7 @@ export default class ProcessConverter {
} else {
const sourceShapeBpmnElement = this.convertedElements.findFlowNode(sequenceFlow.sourceRef);
if (sourceShapeBpmnElement && ShapeUtil.isWithDefaultSequenceFlow(sourceShapeBpmnElement.kind) && sequenceFlow.conditionExpression) {
if (ShapeUtil.isActivity(sourceShapeBpmnElement.kind)) {
return SequenceFlowKind.CONDITIONAL_FROM_ACTIVITY;
} else {
return SequenceFlowKind.CONDITIONAL_FROM_GATEWAY;
}
return ShapeUtil.isActivity(sourceShapeBpmnElement.kind) ? SequenceFlowKind.CONDITIONAL_FROM_ACTIVITY : SequenceFlowKind.CONDITIONAL_FROM_GATEWAY;
}
}
return SequenceFlowKind.NORMAL;
Expand Down
7 changes: 2 additions & 5 deletions test/config/jest-playwright.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ const computeConfigurationForDevelopmentServerUsage = defaultBrowsers => {

const computeConfiguration = options => {
let configuration;
if (options.startWebServer ?? true) {
configuration = computeConfigurationForDevelopmentServerUsage(options.defaultBrowsers);
} else {
configuration = computeConfigurationForStaticUsage(options.defaultBrowsers);
}
configuration =
options.startWebServer ?? true ? computeConfigurationForDevelopmentServerUsage(options.defaultBrowsers) : computeConfigurationForStaticUsage(options.defaultBrowsers);
log('Computed configuration', configuration);
return configuration;
};
Expand Down
16 changes: 6 additions & 10 deletions test/integration/matchers/matcher-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,12 @@ export function buildReceivedCellWithCommonAttributes(cell: mxCell): ExpectedCel
const receivedCell = buildBaseReceivedExpectedCell(cell);

const cellOverlays = bpmnVisualization.graph.getCellOverlays(cell) as MxGraphCustomOverlay[];
if (cellOverlays) {
receivedCell.overlays = cellOverlays.map(cellOverlay => ({
label: cellOverlay.label,
horizontalAlign: cellOverlay.align,
verticalAlign: cellOverlay.verticalAlign,
style: cellOverlay.style,
}));
} else {
receivedCell.overlays = undefined;
}
receivedCell.overlays = cellOverlays?.map(cellOverlay => ({
label: cellOverlay.label,
horizontalAlign: cellOverlay.align,
verticalAlign: cellOverlay.verticalAlign,
style: cellOverlay.style,
}));

// The cell of the "message flow icon" is defined as a child of the "message flow" cell
if (cell.edge) {
Expand Down
6 changes: 1 addition & 5 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,7 @@ function addElementsOnProcess(processParameter: BuildProcessParameter, json: Bpm
}

function getElementOfArray<T>(object: T | T[], index = 0): T {
if (Array.isArray(object)) {
return object[index];
} else {
return object;
}
return Array.isArray(object) ? object[index] : object;
}

function enrichBpmnElement<T extends TBaseElement | DiagramElement>(currentElement: T | T[], elementToAdd: T): T | T[] {
Expand Down

0 comments on commit f150db6

Please sign in to comment.