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: eslint curly rule #885

Open
wants to merge 1 commit into
base: fix/tests-table-path-filter
Choose a base branch
from
Open
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
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 @@ -327,8 +327,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 @@ -339,8 +340,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
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/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 @@ -180,7 +180,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) {
statusCounter(localGroup, t.status);
statusCounter(globalGroup, t.status);
Expand Down Expand Up @@ -374,7 +376,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 @@ -63,7 +63,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/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
4 changes: 3 additions & 1 deletion dashboard/src/pages/Hardware/InputTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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
7 changes: 5 additions & 2 deletions dashboard/src/pages/TreeDetails/Tabs/Boots/BootsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ const BootsTab = ({ treeDetailsLazyLoaded }: BootsTabProps): JSX.Element => {
);
}

if (isLoading)
if (isLoading) {
return (
<Skeleton>
<FormattedMessage id="global.loading" />
</Skeleton>
);
}

if (!data) return <div />;
if (!data) {
return <div />;
}

if (bootsData?.length === 0) {
return (
Expand Down
Loading