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

refactor: improving code safety with nullish coalescing operator #2823

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
2 changes: 1 addition & 1 deletion dev/ts/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function configureFitOnLoadCheckBox(): void {
function updateFitConfig(config: FitOptions): void {
log('Updating fit config', config);

fitOptions.margin = config.margin || fitOptions.margin;
fitOptions.margin = config.margin ?? fitOptions.margin;
if (config.type) {
fitOptions.type = config.type;
}
Expand Down
4 changes: 2 additions & 2 deletions dev/ts/shared/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function logOnlyStatusKoNotifier(errorMsg: string): void {
}

function getFitOptionsFromParameters(config: BpmnVisualizationDemoConfiguration, parameters: URLSearchParams): FitOptions {
const fitOptions: FitOptions = config.loadOptions?.fit || {};
const fitOptions: FitOptions = config.loadOptions?.fit ?? {};
const parameterFitType: string = parameters.get('fitTypeOnLoad');
if (parameterFitType) {
// As the parameter is a string, and the load/fit APIs accept only enum to avoid error, we need to convert it
Expand Down Expand Up @@ -320,7 +320,7 @@ export function startBpmnVisualization(config: BpmnVisualizationDemoConfiguratio
statusKoNotifier = config.statusKoNotifier ?? logOnlyStatusKoNotifier;

log('Configuring Load Options');
loadOptions = config.loadOptions || {};
loadOptions = config.loadOptions ?? {};
loadOptions.fit = getFitOptionsFromParameters(config, parameters);
loadOptions.modelFilter = configurePoolsFilteringFromParameters(parameters);

Expand Down
2 changes: 1 addition & 1 deletion src/component/helpers/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function ensureInRange(value: number, min: number, max: number, defaultVa
* @internal
*/
export function ensurePositiveValue(input: number | undefined | null): number {
return Math.max(input || 0, 0);
return Math.max(input ?? 0, 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 @@ -365,13 +365,9 @@ export default class ProcessConverter {

const buildMarkers = (bpmnElement: TActivity): ShapeBpmnMarkerKind[] => {
const markers: ShapeBpmnMarkerKind[] = [];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the standardLoopCharacteristics field is not on all types, but it's already tested
// @ts-ignore
const standardLoopCharacteristics = bpmnElement.standardLoopCharacteristics;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- We know that the multiInstanceLoopCharacteristics field is not on all types, but it's already tested
// @ts-ignore
const multiInstanceLoopCharacteristics = ensureIsArray(bpmnElement.multiInstanceLoopCharacteristics, true)[0];
if (standardLoopCharacteristics || standardLoopCharacteristics === '') {
if (standardLoopCharacteristics !== undefined) {
markers.push(ShapeBpmnMarkerKind.LOOP);
} else if (multiInstanceLoopCharacteristics) {
markers.push(multiInstanceLoopCharacteristics.isSequential ? ShapeBpmnMarkerKind.MULTI_INSTANCE_SEQUENTIAL : ShapeBpmnMarkerKind.MULTI_INSTANCE_PARALLEL);
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/visu/image-snapshot-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ImageSnapshotConfigurator {
configLog(`Using dedicated image snapshot threshold for '${fileName}'`);
const simplePlatformName = getSimplePlatformName();
configLog(`Simple platform name: ${simplePlatformName}`);
failureThreshold = config[simplePlatformName] || failureThreshold;
failureThreshold = config[simplePlatformName] ?? failureThreshold;
} else {
configLog(`Using default image snapshot threshold for '${fileName}'`);
}
Expand Down
2 changes: 1 addition & 1 deletion test/performance/helpers/metrics-chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const supportedMetrics = new Set<string>([

function buildMetricsObject(metrics?: Array<Metric>): Metrics {
const result: Metrics = {};
for (const metric of metrics || []) {
for (const metric of metrics ?? []) {
if (supportedMetrics.has(metric.name)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions test/unit/helpers/bpmn-model-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ExpectedActivityShape extends ExpectedShape {

export interface ExpectedCallActivityShape extends ExpectedActivityShape {
bpmnElementGlobalTaskKind?: GlobalTaskKind;
bpmnElementCallActivityKind?: ShapeBpmnCallActivityKind;
bpmnElementCallActivityKind: ShapeBpmnCallActivityKind;
}

export interface ExpectedEventShape extends ExpectedShape {
Expand Down Expand Up @@ -114,7 +114,7 @@ export const verifyShape = (
expect(bpmnElement.markers).toHaveLength(0);
}

if (('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) || 'bpmnElementGlobalTaskKind' in expectedShape) {
if ('bpmnElementCallActivityKind' in expectedShape && expectedShape.bpmnElementCallActivityKind) {
expect(bpmnElement instanceof ShapeBpmnCallActivity).toBeTruthy();
expect((bpmnElement as ShapeBpmnCallActivity).callActivityKind).toEqual(expectedShape.bpmnElementCallActivityKind);
expect((bpmnElement as ShapeBpmnCallActivity).globalTaskKind).toEqual(expectedShape.bpmnElementGlobalTaskKind);
Expand Down