From f122d5e6d75839d1282c21e45d0d89f1d6a30391 Mon Sep 17 00:00:00 2001 From: Murilo Geraldini Date: Wed, 5 Feb 2025 15:59:24 -0300 Subject: [PATCH] refactor: add curly eslint rule --- dashboard/.eslintrc.cjs | 1 + dashboard/src/api/commonRequest.ts | 8 +++- dashboard/src/api/hardwareDetails.ts | 9 +++-- .../src/components/BootsTable/BootsTable.tsx | 6 ++- .../components/BuildsTable/BuildsTable.tsx | 9 +++-- .../src/components/Checkbox/Checkbox.tsx | 7 +++- .../src/components/Filter/CheckboxSection.tsx | 4 +- .../src/components/Section/LogspecSection.tsx | 3 +- .../src/components/Table/PaginationInfo.tsx | 4 +- .../src/components/Table/TableHeader.tsx | 3 +- .../src/components/Table/TooltipHardware.tsx | 4 +- .../src/components/Tabs/Builds/StatusCard.tsx | 4 +- dashboard/src/components/Tabs/FilterList.tsx | 4 +- dashboard/src/components/Tabs/Filters.tsx | 8 +++- dashboard/src/components/Tabs/tabsUtils.ts | 4 +- .../TestsTable/IndividualTestsTable.tsx | 10 +++-- .../src/components/TestsTable/TestsTable.tsx | 8 +++- .../TooltipDateTime/TooltipDateTime.tsx | 4 +- dashboard/src/components/TopBar/TopBar.tsx | 3 +- .../components/TreeListingPage/InputTime.tsx | 4 +- .../TreeListingPage/TreeListingPage.tsx | 12 ++++-- dashboard/src/hooks/usePaginationState.tsx | 4 +- dashboard/src/hooks/useToast.tsx | 4 +- .../pages/Hardware/HardwareListingPage.tsx | 4 +- dashboard/src/pages/Hardware/InputTime.tsx | 4 +- .../pages/TreeDetails/Tabs/Boots/BootsTab.tsx | 7 +++- .../pages/TreeDetails/Tabs/Tests/TestsTab.tsx | 7 +++- .../src/pages/TreeDetails/TreeDetails.tsx | 4 +- .../pages/hardwareDetails/HardwareDetails.tsx | 4 +- .../hardwareDetails/HardwareDetailsFilter.tsx | 9 +++-- .../HardwareDetailsHeaderTable.tsx | 8 +++- .../Tabs/HardwareCommitNavigationGraph.tsx | 8 +++- dashboard/src/types/general.ts | 4 +- dashboard/src/utils/misc.tsx | 10 +++-- dashboard/src/utils/status.ts | 8 +++- dashboard/src/utils/utils.ts | 38 ++++++++++++++----- 36 files changed, 176 insertions(+), 66 deletions(-) diff --git a/dashboard/.eslintrc.cjs b/dashboard/.eslintrc.cjs index fceba9bdf..b06775915 100644 --- a/dashboard/.eslintrc.cjs +++ b/dashboard/.eslintrc.cjs @@ -136,5 +136,6 @@ module.exports = { "react/prop-types": "off", "react/react-in-jsx-scope": "off", "react/require-default-props": "off", + "curly": "error", }, }; diff --git a/dashboard/src/api/commonRequest.ts b/dashboard/src/api/commonRequest.ts index 0a2856b6f..9d3d1b83c 100644 --- a/dashboard/src/api/commonRequest.ts +++ b/dashboard/src/api/commonRequest.ts @@ -8,7 +8,9 @@ export class RequestData { static async get(url: string, config?: AxiosRequestConfig): Promise { const res = await http.get>(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; } @@ -20,7 +22,9 @@ export class RequestData { ): Promise { const res = await http.post>(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; } diff --git a/dashboard/src/api/hardwareDetails.ts b/dashboard/src/api/hardwareDetails.ts index 1577b6639..ba9389c74 100644 --- a/dashboard/src/api/hardwareDetails.ts +++ b/dashboard/src/api/hardwareDetails.ts @@ -31,8 +31,9 @@ const mapIndexesToSelectedTrees = ( ): Record => { const selectedTrees: Record = {}; - if (selectedIndexes.length === 0 && isEmptyObject(treeCommits)) + if (selectedIndexes.length === 0 && isEmptyObject(treeCommits)) { return selectedTrees; + } const selectedArray = treeIndexesLength && selectedIndexes.length === 0 @@ -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()); + } }); }); diff --git a/dashboard/src/components/BootsTable/BootsTable.tsx b/dashboard/src/components/BootsTable/BootsTable.tsx index a2027186c..af9936db0 100644 --- a/dashboard/src/components/BootsTable/BootsTable.tsx +++ b/dashboard/src/components/BootsTable/BootsTable.tsx @@ -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; }); @@ -342,8 +343,9 @@ export function BootsTable({ if ( typeof previousLog === 'number' && previousLog < sortedItems.length - 1 - ) + ) { return previousLog + 1; + } return previousLog; }); diff --git a/dashboard/src/components/BuildsTable/BuildsTable.tsx b/dashboard/src/components/BuildsTable/BuildsTable.tsx index ece8d62fd..aac605c7e 100644 --- a/dashboard/src/components/BuildsTable/BuildsTable.tsx +++ b/dashboard/src/components/BuildsTable/BuildsTable.tsx @@ -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>, @@ -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; }); @@ -239,8 +241,9 @@ export function BuildsTable({ if ( typeof previousLog === 'number' && previousLog < sortedItems.length - 1 - ) + ) { return previousLog + 1; + } return previousLog; }); diff --git a/dashboard/src/components/Checkbox/Checkbox.tsx b/dashboard/src/components/Checkbox/Checkbox.tsx index c13619cbd..bb8f98de2 100644 --- a/dashboard/src/components/Checkbox/Checkbox.tsx +++ b/dashboard/src/components/Checkbox/Checkbox.tsx @@ -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 (