Skip to content

Commit

Permalink
lint(curly): consistent use of curly brackets in codebase (#3584)
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi authored Aug 9, 2023
1 parent 9ae3d9f commit 5d43542
Show file tree
Hide file tree
Showing 113 changed files with 1,508 additions and 1,063 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"version": "detect"
}
},
"rules": {
// Enforce consistent brace style for all control statements for readability
"curly": "error"
},
"globals": {
"cy": true,
"before": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Icon, Tooltip } from '@ohif/ui';


export default function _getStatusComponent({ isHydrated, onStatusClick }) {
let ToolTipMessage = null;
let StatusIcon = null;

const {t} = useTranslation("Common");
const loadStr = t("LOAD");
const { t } = useTranslation('Common');
const loadStr = t('LOAD');

switch (isHydrated) {
case true:
Expand All @@ -18,7 +17,7 @@ export default function _getStatusComponent({ isHydrated, onStatusClick }) {
<div>This Segmentation is loaded in the segmentation panel</div>
);
break;
case false:
case false:
StatusIcon = () => <Icon name="status-untracked" />;

ToolTipMessage = () => <div>Click LOAD to load segmentation.</div>;
Expand All @@ -42,7 +41,6 @@ export default function _getStatusComponent({ isHydrated, onStatusClick }) {
</div>
);


return (
<>
{ToolTipMessage && (
Expand Down
11 changes: 8 additions & 3 deletions extensions/cornerstone-dicom-sr/src/getSopClassHandlerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ function _measurementReferencesSOPInstanceUID(
measurement.coords[0].ReferencedSOPSequence[0]?.ReferencedFrameNumber) ||
1;

if (frameNumber && Number(frameNumber) !== Number(ReferencedFrameNumber))
if (frameNumber && Number(frameNumber) !== Number(ReferencedFrameNumber)) {
return false;
}

for (let j = 0; j < coords.length; j++) {
const coord = coords[j];
Expand Down Expand Up @@ -670,7 +671,9 @@ function _getReferencedImagesList(ImagingMeasurementReportContentSequence) {

_getSequenceAsArray(ImageLibraryGroup.ContentSequence).forEach(item => {
const { ReferencedSOPSequence } = item;
if (!ReferencedSOPSequence) return;
if (!ReferencedSOPSequence) {
return;
}
for (const ref of _getSequenceAsArray(ReferencedSOPSequence)) {
if (ref.ReferencedSOPClassUID) {
const { ReferencedSOPClassUID, ReferencedSOPInstanceUID } = ref;
Expand All @@ -687,7 +690,9 @@ function _getReferencedImagesList(ImagingMeasurementReportContentSequence) {
}

function _getSequenceAsArray(sequence) {
if (!sequence) return [];
if (!sequence) {
return [];
}
return Array.isArray(sequence) ? sequence : [sequence];
}

Expand Down
20 changes: 9 additions & 11 deletions extensions/cornerstone-dicom-sr/src/tools/DICOMSRDisplayTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,16 @@ export default class DICOMSRDisplayTool extends AnnotationTool {
);
let canvasCorners;
if (rotation == 90 || rotation == 270) {
canvasCorners = <Array<Types.Point2>>(
utilities.math.ellipse.getCanvasEllipseCorners([
canvasCoordinates[2],
canvasCoordinates[3],
canvasCoordinates[0],
canvasCoordinates[1],
])
);
canvasCorners = utilities.math.ellipse.getCanvasEllipseCorners([
canvasCoordinates[2],
canvasCoordinates[3],
canvasCoordinates[0],
canvasCoordinates[1],
]) as Array<Types.Point2>;
} else {
canvasCorners = <Array<Types.Point2>>(
utilities.math.ellipse.getCanvasEllipseCorners(canvasCoordinates)
);
canvasCorners = utilities.math.ellipse.getCanvasEllipseCorners(
canvasCoordinates
) as Array<Types.Point2>;
}

const lineUID = `${index}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { DisplaySetService, classes } from '@ohif/core';
const ImageSet = classes.ImageSet;

const findInstance = (measurement, displaySetService: DisplaySetService) => {
const { displaySetInstanceUID, ReferencedSOPInstanceUID: sopUid } =
measurement;
const {
displaySetInstanceUID,
ReferencedSOPInstanceUID: sopUid,
} = measurement;
const referencedDisplaySet = displaySetService.getDisplaySetByUID(
displaySetInstanceUID
);
if (!referencedDisplaySet.images) return;
if (!referencedDisplaySet.images) {
return;
}
return referencedDisplaySet.images.find(it => it.SOPInstanceUID === sopUid);
};

Expand All @@ -24,8 +28,12 @@ const findReferencedInstances = (
const instanceById = {};
for (const measurement of displaySet.measurements) {
const { imageId } = measurement;
if (!imageId) continue;
if (instanceById[imageId]) continue;
if (!imageId) {
continue;
}
if (instanceById[imageId]) {
continue;
}

const instance = findInstance(measurement, displaySetService);
if (!instance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const findInstanceMetadataBySopInstanceUID = (displaySets, SOPInstanceUID) => {
let instanceFound;

displaySets.find(displaySet => {
if (!displaySet.images) return false;
if (!displaySet.images) {
return false;
}

instanceFound = displaySet.images.find(
instanceMetadata =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ const CORNERSTONE_3D_TOOLS_SOURCE_VERSION = '0.1';
const supportedLegacyCornerstoneTags = ['cornerstoneTools@^4.0.0'];

const convertCode = (codingValues, code) => {
if (!code || code.CodingSchemeDesignator === 'CORNERSTONEJS') return;
if (!code || code.CodingSchemeDesignator === 'CORNERSTONEJS') {
return;
}
const ref = `${code.CodingSchemeDesignator}:${code.CodeValue}`;
const ret = { ...codingValues[ref], ref, ...code, text: code.CodeMeaning };
return ret;
};

const convertSites = (codingValues, sites) => {
if (!sites || !sites.length) return;
if (!sites || !sites.length) {
return;
}
const ret = [];
// Do as a loop to convert away from Proxy instances
for (let i = 0; i < sites.length; i++) {
// Deal with irregular conversion from dcmjs
const site = convertCode(codingValues, sites[i][0] || sites[i]);
if (site) ret.push(site);
if (site) {
ret.push(site);
}
}
return (ret.length && ret) || undefined;
};
Expand Down Expand Up @@ -287,7 +293,7 @@ function _mapLegacyDataSet(dataset) {
return dataset;
}

const toArray = function (x) {
const toArray = function(x) {
return Array.isArray(x) ? x : [x];
};

Expand Down
12 changes: 9 additions & 3 deletions extensions/cornerstone/src/Viewport/OHIFCornerstoneViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ function _subscribeToJumpToMeasurementEvents(
props => {
cacheJumpToMeasurementEvent = props;
const { viewportIndex: jumpIndex, measurement, isConsumed } = props;
if (!measurement || isConsumed) return;
if (!measurement || isConsumed) {
return;
}
if (cacheJumpToMeasurementEvent.cornerstoneViewport === undefined) {
// Decide on which viewport should handle this
cacheJumpToMeasurementEvent.cornerstoneViewport = cornerstoneViewportService.getViewportIndexToJump(
Expand Down Expand Up @@ -482,15 +484,19 @@ function _checkForCachedJumpToMeasurementEvents(
viewportGridService,
cornerstoneViewportService
) {
if (!cacheJumpToMeasurementEvent) return;
if (!cacheJumpToMeasurementEvent) {
return;
}
if (cacheJumpToMeasurementEvent.isConsumed) {
cacheJumpToMeasurementEvent = null;
return;
}
const displaysUIDs = displaySets.map(
displaySet => displaySet.displaySetInstanceUID
);
if (!displaysUIDs?.length) return;
if (!displaysUIDs?.length) {
return;
}

// Jump to measurement if the measurement exists
const { measurement } = cacheJumpToMeasurementEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ function CornerstoneOverlays(props) {
}

if (viewportData) {
const viewportInfo =
cornerstoneViewportService.getViewportInfoByIndex(viewportIndex);
const viewportInfo = cornerstoneViewportService.getViewportInfoByIndex(
viewportIndex
);

if (viewportInfo?.viewportOptions?.customViewportProps?.hideOverlays) {
return null;
Expand Down
16 changes: 12 additions & 4 deletions extensions/cornerstone/src/initContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ const DEFAULT_CONTEXT_MENU_CLICKS = {
function getEventName(evt) {
const button = evt.detail.event.which;
const nameArr = [];
if (evt.detail.event.altKey) nameArr.push('alt');
if (evt.detail.event.ctrlKey) nameArr.push('ctrl');
if (evt.detail.event.shiftKey) nameArr.push('shift');
if (evt.detail.event.altKey) {
nameArr.push('alt');
}
if (evt.detail.event.ctrlKey) {
nameArr.push('ctrl');
}
if (evt.detail.event.shiftKey) {
nameArr.push('shift');
}
nameArr.push('button');
nameArr.push(button);
return nameArr.join('');
Expand Down Expand Up @@ -73,7 +79,9 @@ function initContextMenu({
function elementEnabledHandler(evt) {
const { viewportId, element } = evt.detail;
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
if (!viewportInfo) return;
if (!viewportInfo) {
return;
}
const viewportIndex = viewportInfo.getViewportIndex();
// TODO check update upstream
setEnabledElement(viewportIndex, element);
Expand Down
12 changes: 9 additions & 3 deletions extensions/cornerstone/src/initDoubleClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ const DEFAULT_DOUBLE_CLICK = {
*/
function getDoubleClickEventName(evt: CustomEvent) {
const nameArr = [];
if (evt.detail.event.altKey) nameArr.push('alt');
if (evt.detail.event.ctrlKey) nameArr.push('ctrl');
if (evt.detail.event.shiftKey) nameArr.push('shift');
if (evt.detail.event.altKey) {
nameArr.push('alt');
}
if (evt.detail.event.ctrlKey) {
nameArr.push('ctrl');
}
if (evt.detail.event.shiftKey) {
nameArr.push('shift');
}
nameArr.push('doubleClick');
return nameArr.join('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,26 @@ class CornerstoneViewportService extends PubSubService

public setPresentations(viewport, presentations?: Presentations): void {
const properties = presentations?.lutPresentation?.properties;
if (properties) viewport.setProperties(properties);
if (properties) {
viewport.setProperties(properties);
}
const camera = presentations?.positionPresentation?.camera;
if (camera) viewport.setCamera(camera);
if (camera) {
viewport.setCamera(camera);
}
}

public getPresentation(viewportIndex: number): Presentation {
const viewportInfo = this.viewportsInfo.get(viewportIndex);
if (!viewportInfo) return;
if (!viewportInfo) {
return;
}
const { viewportType, presentationIds } = viewportInfo.getViewportOptions();

const csViewport = this.getCornerstoneViewportByIndex(viewportIndex);
if (!csViewport) return;
if (!csViewport) {
return;
}

const properties = csViewport.getProperties();
if (properties.isComputedVOI) {
Expand Down Expand Up @@ -408,7 +416,9 @@ class CornerstoneViewportService extends PubSubService
viewport.setStack(imageIds, initialImageIndexToUse).then(() => {
viewport.setProperties(properties);
const camera = presentations.positionPresentation?.camera;
if (camera) viewport.setCamera(camera);
if (camera) {
viewport.setCamera(camera);
}
});
}

Expand Down Expand Up @@ -745,7 +755,10 @@ class CornerstoneViewportService extends PubSubService
const viewport = this.getCornerstoneViewport(viewportId);
const viewportCamera = viewport.getCamera();

if (viewport instanceof VolumeViewport || viewport instanceof VolumeViewport3D) {
if (
viewport instanceof VolumeViewport ||
viewport instanceof VolumeViewport3D
) {
this._setVolumeViewport(viewport, viewportData, viewportInfo).then(() => {
if (keepCamera) {
viewport.setCamera(viewportCamera);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ const dataContains = (
displaySetUID: string,
imageId?: string
): boolean => {
if (data.displaySetInstanceUID === displaySetUID) return true;
if (data.displaySetInstanceUID === displaySetUID) {
return true;
}
if (imageId && data.isCompositeStack && data.imageIds) {
return !!data.imageIds.find(dataId => dataId === imageId);
}
Expand Down Expand Up @@ -123,7 +125,9 @@ class ViewportInfo {
* OR if it is a composite stack and contains the given imageId
*/
public contains(displaySetUID: string, imageId: string): boolean {
if (!this.viewportData?.data) return false;
if (!this.viewportData?.data) {
return false;
}

if (this.viewportData.data.length) {
return !!this.viewportData.data.find(data =>
Expand Down
4 changes: 3 additions & 1 deletion extensions/cornerstone/src/utils/DicomFileUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export default class DicomFileUploader extends PubSubService {
}

private _checkDicomFile(arrayBuffer: ArrayBuffer) {
if (arrayBuffer.length <= 132) return false;
if (arrayBuffer.length <= 132) {
return false;
}
const arr = new Uint8Array(arrayBuffer.slice(128, 132));
// bytes from 128 to 132 must be "DICM"
return Array.from('DICM').every((char, i) => char.charCodeAt(0) === arr[i]);
Expand Down
3 changes: 2 additions & 1 deletion extensions/cornerstone/src/utils/callInputDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ function callInputDialog(
const onSubmitHandler = ({ action, value }) => {
switch (action.id) {
case 'save':
if (typeof validateFunc === 'function' && !validateFunc(value.label))
if (typeof validateFunc === 'function' && !validateFunc(value.label)) {
return;
}

callback(value.label, action.id);
break;
Expand Down
8 changes: 6 additions & 2 deletions extensions/cornerstone/src/utils/interleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
* @returns [] reordered to be breadth first traversal of lists
*/
export default function interleave(lists) {
if (!lists || !lists.length) return [];
if (lists.length === 1) return lists[0];
if (!lists || !lists.length) {
return [];
}
if (lists.length === 1) {
return lists[0];
}
console.time('interleave');
const useLists = [...lists];
const ret = [];
Expand Down
Loading

0 comments on commit 5d43542

Please sign in to comment.