Skip to content

Commit

Permalink
refactor: add curly eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
murilx committed Feb 6, 2025
1 parent 8e9baac commit b867845
Show file tree
Hide file tree
Showing 36 changed files with 176 additions and 66 deletions.
1 change: 1 addition & 0 deletions dashboard/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ module.exports = {
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"curly": "error",
},
};
8 changes: 6 additions & 2 deletions dashboard/src/api/commonRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export class RequestData {
static async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
const res = await http.get<ResponseData<T>>(url, config);

if (res.data.error) throw new Error(res.data.error);
if (res.data.error) {
throw new Error(res.data.error);
}

return res.data;
}
Expand All @@ -20,7 +22,9 @@ export class RequestData {
): Promise<T> {
const res = await http.post<ResponseData<T>>(url, data, config);

if (res.data.error) throw new Error(res.data.error);
if (res.data.error) {
throw new Error(res.data.error);
}

return res.data;
}
Expand Down
9 changes: 6 additions & 3 deletions dashboard/src/api/hardwareDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const mapIndexesToSelectedTrees = (
): Record<string, string> => {
const selectedTrees: Record<string, string> = {};

if (selectedIndexes.length === 0 && isEmptyObject(treeCommits))
if (selectedIndexes.length === 0 && isEmptyObject(treeCommits)) {
return selectedTrees;
}

const selectedArray =
treeIndexesLength && selectedIndexes.length === 0
Expand All @@ -57,9 +58,11 @@ const mapFiltersKeysToBackendCompatible = (
Object.keys(filter).forEach(key => {
const filterList = filter[key as keyof THardwareDetailsFilter];
filterList?.forEach(value => {
if (!filterParam[`filter_${key}`])
if (!filterParam[`filter_${key}`]) {
filterParam[`filter_${key}`] = [value.toString()];
else filterParam[`filter_${key}`].push(value.toString());
} else {
filterParam[`filter_${key}`].push(value.toString());
}
});
});

Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/components/BootsTable/BootsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ export function BootsTable({

const handlePreviousItem = useCallback(() => {
setLog(previousLog => {
if (typeof previousLog === 'number' && previousLog > 0)
if (typeof previousLog === 'number' && previousLog > 0) {
return previousLog - 1;
}

return previousLog;
});
Expand All @@ -342,8 +343,9 @@ export function BootsTable({
if (
typeof previousLog === 'number' &&
previousLog < sortedItems.length - 1
)
) {
return previousLog + 1;
}

return previousLog;
});
Expand Down
9 changes: 6 additions & 3 deletions dashboard/src/components/BuildsTable/BuildsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ export function BuildsTable({

const count = possibleBuildsTableFilter.reduce(
(acc, currentFilter) => {
if (dataFilter)
if (dataFilter) {
acc[currentFilter] = dataFilter?.reduce(
(total, row) => (row.status === currentFilter ? total + 1 : total),
0,
);
}
return acc;
},
{} as Record<(typeof possibleBuildsTableFilter)[number], number>,
Expand Down Expand Up @@ -227,8 +228,9 @@ export function BuildsTable({

const handlePreviousItem = useCallback(() => {
setLog(previousLog => {
if (typeof previousLog === 'number' && previousLog > 0)
if (typeof previousLog === 'number' && previousLog > 0) {
return previousLog - 1;
}

return previousLog;
});
Expand All @@ -239,8 +241,9 @@ export function BuildsTable({
if (
typeof previousLog === 'number' &&
previousLog < sortedItems.length - 1
)
) {
return previousLog + 1;
}

return previousLog;
});
Expand Down
7 changes: 5 additions & 2 deletions dashboard/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const Checkbox = ({
isChecked = false,
}: ICheckbox): JSX.Element => {
let truncatedText = text;
if (isUrl(text)) truncatedText = truncateUrl(text);
else truncatedText = truncateBigText(text, maxCheckboxLength);
if (isUrl(text)) {
truncatedText = truncateUrl(text);
} else {
truncatedText = truncateBigText(text, maxCheckboxLength);
}

return (
<label
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Filter/CheckboxSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export interface ISectionItem {
type SplitFilterString = `${string}__${string}`;

const extractCheckboxValue = (value: SplitFilterString | undefined): string => {
if (!value) return '';
if (!value) {
return '';
}

const valueSplit = value.split('__');
return valueSplit[0];
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/Section/LogspecSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export const getLogspecSection = ({
setSheetType: setSheetType,
setJsonContent: setJsonContent,
});
if (content !== undefined)
if (content !== undefined) {
logspecSection.subsections?.[0].infos.push(content);
}
}
});

Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Table/PaginationInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export function PaginationInfo({

const onValueChange = useCallback(
(value: number) => {
if (onPaginationChange) onPaginationChange(value);
if (onPaginationChange) {
onPaginationChange(value);
}

table.setPageSize(value);
},
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/Table/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ export const TableHeader = <T,>({
tooltipId,
}: ITableHeader<T>): JSX.Element => {
const headerSort = useCallback(() => {
if (sortable)
if (sortable) {
if (column.getIsSorted() === 'asc') {
column.toggleSorting(true);
} else if (column.getIsSorted() === 'desc') {
column.clearSorting();
} else {
column.toggleSorting(false);
}
}
}, [column, sortable]);

return (
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Table/TooltipHardware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const TooltipHardware = ({

const hardwareTrigger = sanitizeTableValue(hardwares?.[0], false);

if (!shouldHaveTooltip) return <span>{hardwareTrigger}</span>;
if (!shouldHaveTooltip) {
return <span>{hardwareTrigger}</span>;
}

return (
<Tooltip>
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Tabs/Builds/StatusCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const StatusCard = ({
return invalid + valid + nullables;
}, [buildsSummary]);

if (!buildsSummary) return <></>;
if (!buildsSummary) {
return <></>;
}

return (
<BaseCard
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Tabs/FilterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const createFlatFilter = (filter: TFilter): string[] => {
Object.entries(filter).forEach(([field, fieldValue]) => {
if (typeof fieldValue === 'object') {
Object.entries(fieldValue).forEach(([value, isSelected]) => {
if (isSelected) flatFilter.push(`${field}:${value}`);
if (isSelected) {
flatFilter.push(`${field}:${value}`);
}
});
} else {
flatFilter.push(`${field}:${fieldValue}`);
Expand Down
8 changes: 6 additions & 2 deletions dashboard/src/components/Tabs/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const mapFilterToReq = (filter: TFilter): TFilter => {

Object.entries(filterFieldMap).forEach(([reqField, field]) => {
const values = filter[field as TFilterKeys];
if (!values) return;
if (!values) {
return;
}

if (typeof values === 'object') {
Object.entries(values).forEach(([value, isSelected]) => {
Expand Down Expand Up @@ -261,7 +263,9 @@ const TreeSelectSection = ({
const intl = useIntl();

const filterItems = useMemo(() => {
if (!items) return {};
if (!items) {
return {};
}

const filteredItems: Record<string, boolean> = {};

Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/Tabs/tabsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const useDiffFilterParams = (
[currentDiffFilter],
);

if (!currentDiffFilter) return {};
if (!currentDiffFilter) {
return {};
}

// This seems redundant but we do this to keep the pointer to newFilter[filterSection]
newFilter[filterSection] = newFilter[filterSection] ?? {};
Expand Down
10 changes: 7 additions & 3 deletions dashboard/src/components/TestsTable/IndividualTestsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export function IndividualTestsTable({
// https://tanstack.com/virtual/latest/docs/framework/react/examples/table
const [firstRowStyle, lastRowStyle]: [CSSProperties, CSSProperties] =
useMemo(() => {
if (virtualItems.length === 0) return [{}, {}];
if (virtualItems.length === 0) {
return [{}, {}];
}
return [
{ paddingTop: virtualItems[0].start },
{
Expand All @@ -122,8 +124,9 @@ export function IndividualTestsTable({

const handlePreviousItem = useCallback(() => {
setLog(previousLog => {
if (typeof previousLog === 'number' && previousLog > 0)
if (typeof previousLog === 'number' && previousLog > 0) {
return previousLog - 1;
}

return previousLog;
});
Expand All @@ -134,8 +137,9 @@ export function IndividualTestsTable({
if (
typeof previousLog === 'number' &&
previousLog < originalItems.length - 1
)
) {
return previousLog + 1;
}

return previousLog;
});
Expand Down
8 changes: 6 additions & 2 deletions dashboard/src/components/TestsTable/TestsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export function TestsTable({
};
const individualTest = test.individual_tests.filter(t => {
let dataIncludesPath = true;
if (isValidPath) dataIncludesPath = t.path.includes(path);
if (isValidPath) {
dataIncludesPath = t.path.includes(path);
}
if (dataIncludesPath) {
countStatus(localGroup, t.status);
countStatus(globalGroup, t.status);
Expand Down Expand Up @@ -377,7 +379,9 @@ export function TestsTable({
<TableRow
className="group cursor-pointer hover:bg-lightBlue"
onClick={() => {
if (row.getCanExpand()) row.toggleExpanded();
if (row.getCanExpand()) {
row.toggleExpanded();
}
}}
data-state={row.getIsExpanded() ? 'open' : 'closed'}
>
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/TooltipDateTime/TooltipDateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const TooltipDateTime = ({
showTooltip = true,
}: TooltipDateTimeProps): JSX.Element => {
const dateObj = new Date(dateTime);
if (!isValid(dateObj)) return <div>-</div>;
if (!isValid(dateObj)) {
return <div>-</div>;
}

const date = dateFormat
? format(dateObj, dateFormat)
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ const OriginSelect = ({ basePath }: { basePath: string }): JSX.Element => {
);

useEffect(() => {
if (unsafeOrigin === undefined)
if (unsafeOrigin === undefined) {
navigate({
search: previousSearch => ({ ...previousSearch, origin: origin }),
});
}
});

return (
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/TreeListingPage/InputTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export function InputTime(): JSX.Element {

const onInputTimeTextChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
if (!e.target.value) return;
if (!e.target.value) {
return;
}
onSubmit();
},
[onSubmit],
Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/components/TreeListingPage/TreeListingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const TreeListingPage = ({ inputFilter }: ITreeListingPage): JSX.Element => {
});

const listItems: TreeTableBody[] = useMemo(() => {
if (!fastData || fastStatus === 'error') return [];
if (!fastData || fastStatus === 'error') {
return [];
}

const hasCompleteData = !isLoading && !!data;
const currentData = hasCompleteData ? data : fastData;
Expand Down Expand Up @@ -112,10 +114,14 @@ const TreeListingPage = ({ inputFilter }: ITreeListingPage): JSX.Element => {
const treeNameComparison =
currentATreeName.localeCompare(currentBTreeName);

if (treeNameComparison !== 0) return treeNameComparison;
if (treeNameComparison !== 0) {
return treeNameComparison;
}

const branchComparison = a.branch.localeCompare(b.branch);
if (branchComparison !== 0) return branchComparison;
if (branchComparison !== 0) {
return branchComparison;
}

return new Date(b.date).getTime() - new Date(a.date).getTime();
});
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/hooks/usePaginationState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const DEFAULT_LISTING_SIZE = 10;

const findClosestGreaterNumber = (sortedList: number[], x: number): number => {
for (let i = 0; i < sortedList.length; i++) {
if (sortedList[i] >= x) return sortedList[i];
if (sortedList[i] >= x) {
return sortedList[i];
}
}

return sortedList.slice(-1)[0] ?? DEFAULT_LISTING_SIZE;
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/hooks/useToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ function toast({ ...props }: Toast): ToastStateProps {
id,
open: true,
onOpenChange: open => {
if (!open) dismiss();
if (!open) {
dismiss();
}
},
},
});
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/pages/Hardware/HardwareListingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const HardwareListingPage = ({
);

const listItems: HardwareTableItem[] = useMemo(() => {
if (!data || error) return [];
if (!data || error) {
return [];
}

const currentData = data.hardware;

Expand Down
Loading

0 comments on commit b867845

Please sign in to comment.