Skip to content

Commit

Permalink
added Disable .sort for .toSorted lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pnaik1 committed May 27, 2024
1 parent 23428a2 commit 770d616
Show file tree
Hide file tree
Showing 36 changed files with 60 additions and 46 deletions.
4 changes: 4 additions & 0 deletions frontend/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
"object": "Promise",
"property": "allSettled",
"message": "Avoid using Promise.allSettled, use allSettledPromises utility function instead."
},
{
"property": "sort",
"message": "Avoid using .sort, use .toSorted instead."
}
],
"import/newline-after-import": "error",
Expand Down
4 changes: 3 additions & 1 deletion frontend/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module.exports = {
'@babel/preset-env',
{
targets: {
chrome: 100,
chrome: 110,
},
useBuiltIns: 'usage',
corejs: '3',
},
],
'@babel/preset-react',
Expand Down
12 changes: 12 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^5.2.7",
"css-minimizer-webpack-plugin": "^4.2.2",
"core-js": "^3.37.1",
"cypress": "^13.6.0",
"cypress-axe": "^1.5.0",
"dotenv": "^8.2.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/__tests__/unit/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TextEncoder } from 'util';
import { JestAssertionError } from 'expect';
import 'core-js/actual/array/to-sorted';
import {
BooleanValues,
RenderHookResultExt,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/prometheus/distributedWorkloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getTopResourceConsumingWorkloads = (
usage: getWorkloadCurrentUsage(workload)[usageType],
}))
.filter(({ usage }) => usage !== undefined)
.sort((a, b) => (b.usage || 0) - (a.usage || 0));
.toSorted((a, b) => (b.usage || 0) - (a.usage || 0));

const topWorkloads =
workloadsSortedByUsage.length === 6
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/app/AppLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AppLauncher: React.FC = () => {
(link) =>
link.spec.location === 'ApplicationMenu' && link.metadata?.name !== odhConsoleLinkName,
)
.sort((a, b) => a.spec.text.localeCompare(b.spec.text));
.toSorted((a, b) => a.spec.text.localeCompare(b.spec.text));

Check warning on line 74 in frontend/src/app/AppLauncher.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/AppLauncher.tsx#L74

Added line #L74 was not covered by tests

const getODHApplications = (): Section[] => {
const osConsoleAction = getOpenShiftConsoleAction(serverURL);
Expand Down Expand Up @@ -110,9 +110,7 @@ const AppLauncher: React.FC = () => {
return acc;
}, getODHApplications());

sections.sort((a, b) => sectionSortValue(a) - sectionSortValue(b));

return sections;
return sections.toSorted((a, b) => sectionSortValue(a) - sectionSortValue(b));
}, [clusterBranding, clusterID, consoleLinks, disableClusterManager, serverURL]);

const onToggle = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/AppNotificationDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface AppNotificationDrawerProps {

const AppNotificationDrawer: React.FC<AppNotificationDrawerProps> = ({ onClose }) => {
const stateNotifications: AppNotification[] = useAppSelector((state) => state.notifications);
const notifications = [...stateNotifications].sort(
const notifications = stateNotifications.toSorted(

Check warning on line 28 in frontend/src/app/AppNotificationDrawer.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/AppNotificationDrawer.tsx#L28

Added line #L28 was not covered by tests
(a, b) => b.timestamp.getTime() - a.timestamp.getTime(),
);
const dispatch = useAppDispatch();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SimpleDropdownSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const SimpleDropdownSelect: React.FC<SimpleDropdownProps> = ({
>
<DropdownList>
{[...options]
.sort((a, b) => (a.isPlaceholder === b.isPlaceholder ? 0 : a.isPlaceholder ? -1 : 1))
.toSorted((a, b) => (a.isPlaceholder === b.isPlaceholder ? 0 : a.isPlaceholder ? -1 : 1))
.map(({ key, dropdownLabel, label, description, isPlaceholder }) => (
<DropdownItem
data-testid={`dropdown-item ${key}`}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/table/useTableColumnSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const useTableColumnSort = <T>(
return data;
}

return [...data].sort((a, b) => {
return data.toSorted((a, b) => {
const columnField =
activeSortIndex < columns.length
? columns[activeSortIndex]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const generateTableStructure = (scalarMetricsArtifacts: RunArtifact[]): S
];

// Prepare data rows and sort them
const sortedDataList = Object.entries(dataMap).sort((a, b) => b[1].dataCount - a[1].dataCount);
const sortedDataList = Object.entries(dataMap).toSorted(
(a, b) => b[1].dataCount - a[1].dataCount,

Check warning on line 89 in frontend/src/concepts/pipelines/content/compareRuns/metricsSection/scalar/utils.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/pipelines/content/compareRuns/metricsSection/scalar/utils.ts#L89

Added line #L89 was not covered by tests
);

return {
columns,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/concepts/pipelines/topology/parseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const lowestProgress = (details: TaskDetailKF[]): PipelineTaskRunStatus['
}
};

return details.sort(
return details.toSorted(
({ state: stateA }, { state: stateB }) => statusWeight(stateB) - statusWeight(stateA),
)[0].state;
};
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/concepts/projects/ProjectsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ const ProjectsContextProvider: React.FC<ProjectsProviderProps> = ({ children })

const contextValue = React.useMemo(
() => ({
projects: projects.sort(projectSorter),
dataScienceProjects: dataScienceProjects.sort(projectSorter),
modelServingProjects: modelServingProjects.sort(projectSorter),
nonActiveProjects: nonActiveProjects.sort(projectSorter),
projects: projects.toSorted(projectSorter),
dataScienceProjects: dataScienceProjects.toSorted(projectSorter),
modelServingProjects: modelServingProjects.toSorted(projectSorter),
nonActiveProjects: nonActiveProjects.toSorted(projectSorter),
preferredProject,
updatePreferredProject,
loaded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const EnabledApplications: React.FC = () => {
() =>
_.cloneDeep(components)
.filter((component) => !component.spec.hidden)
.sort((a, b) => a.spec.displayName.localeCompare(b.spec.displayName)),
.toSorted((a, b) => a.spec.displayName.localeCompare(b.spec.displayName)),

Check warning on line 53 in frontend/src/pages/enabledApplications/EnabledApplications.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/enabledApplications/EnabledApplications.tsx#L53

Added line #L53 was not covered by tests
[components],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const ExploreApplications: React.FC = () => {
() =>
_.cloneDeep(components)
.filter((component) => !component.spec.hidden)
.sort((a, b) => a.spec.displayName.localeCompare(b.spec.displayName)),
.toSorted((a, b) => a.spec.displayName.localeCompare(b.spec.displayName)),

Check warning on line 124 in frontend/src/pages/exploreApplication/ExploreApplications.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/exploreApplication/ExploreApplications.tsx#L124

Added line #L124 was not covered by tests
[components],
);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/learningCenter/ApplicationFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ApplicationFilters: React.FC<ApplicationFiltersProps> = ({ docApps, catego
showAll={showAll}
>
{Object.keys(applications)
.sort((a, b) => a.localeCompare(b))
.toSorted((a, b) => a.localeCompare(b))

Check warning on line 67 in frontend/src/pages/learningCenter/ApplicationFilters.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/learningCenter/ApplicationFilters.tsx#L67

Added line #L67 was not covered by tests
.map((application) => (
<FilterSidePanelCategoryItem
data-id={application}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/learningCenter/CategoryFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CategoryFilters: React.FC<CategoryFiltersProps> = ({ docApps, favorites })
}
return acc;
}, initCategories)
.sort((a, b) => a.localeCompare(b));
.toSorted((a, b) => a.localeCompare(b));
setCategories([ALL_ITEMS, ...updatedCategories]);
}, [docApps, favorites]);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/learningCenter/LearningCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const LearningCenter: React.FC = () => {
React.useEffect(() => {
const filtered = docFilterer(docs);
setFilteredDocApps(
filtered.sort((a, b) => {
filtered.toSorted((a, b) => {
const aFav = favoriteResources.includes(a.metadata.name);
const bFav = favoriteResources.includes(b.metadata.name);
if (aFav && !bFav) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/learningCenter/ProviderTypeFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const ProviderTypeFilters: React.FC<ProviderTypeFiltersProps> = ({ docApps, cate
showAll={showAll}
>
{Object.keys(providerTypes)
.sort((a, b) => {
.toSorted((a, b) => {

Check warning on line 72 in frontend/src/pages/learningCenter/ProviderTypeFilters.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/learningCenter/ProviderTypeFilters.tsx#L72

Added line #L72 was not covered by tests
if (a.toLowerCase().includes(`${ODH_PRODUCT_NAME}`)) {
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const isTemplateOOTB = (template: TemplateKind): boolean =>
template.metadata.labels?.['opendatahub.io/ootb'] === 'true';

export const getSortedTemplates = (templates: TemplateKind[], order: string[]): TemplateKind[] =>
[...templates].sort(
templates.toSorted(
(a, b) =>
order.indexOf(getServingRuntimeNameFromTemplate(a)) -
order.indexOf(getServingRuntimeNameFromTemplate(b)),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/modelServing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ export const isModelServerEditInfoChanged = (
!_.isEqual(
getServingRuntimeTokens(editInfo.secrets)
.map((token) => token.name)
.sort(),
createData.tokens.map((token) => token.name).sort(),
.toSorted(),
createData.tokens.map((token) => token.name).toSorted(),

Check warning on line 297 in frontend/src/pages/modelServing/utils.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/modelServing/utils.ts#L297

Added line #L297 was not covered by tests
))
: true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const AcceleratorProfileSelectField: React.FC<AcceleratorProfileSelectFieldProps
};

const options: SimpleDropdownOption[] = enabledAcceleratorProfiles
.sort((a, b) => {
.toSorted((a, b) => {

Check warning on line 101 in frontend/src/pages/notebookController/screens/server/AcceleratorProfileSelectField.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/notebookController/screens/server/AcceleratorProfileSelectField.tsx#L101

Added line #L101 was not covered by tests
const aSupported = isAcceleratorProfileSupported(a);
const bSupported = isAcceleratorProfileSupported(b);
if (aSupported && !bSupported) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ImageVersions: React.FC<ImageVersionsProps> = ({ image, tags, selectedTag,
isExpanded={isExpanded}
className="odh-notebook-controller__notebook-image-tags"
>
{[...tags].sort(compareTagVersions).map((tag: ImageTagInfo) => {
{tags.toSorted(compareTagVersions).map((tag: ImageTagInfo) => {
const disabled = !isImageTagBuildValid(buildStatuses, image, tag);
return (
<Radio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const SpawnerPage: React.FC = () => {
<Grid sm={12} md={12} lg={12} xl={6} xl2={6} hasGutter>
{[...images]
.filter((image) => !image.error)
.sort(checkOrder)
.toSorted(checkOrder)
.map((image) => (
<GridItem key={image.name}>
<ImageSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const CompareRunParamsSection: React.FunctionComponent = () => {
<InnerScrollContainer>
<Table
loading={!loaded}
data={Object.entries(runParamsMap).sort()}
data={Object.entries(runParamsMap).toSorted()}
columns={hasParameters ? runNameColumns : []}
hasNestedHeader
emptyTableView={
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/projects/notebook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const filterEvents = (
): [filterEvents: EventKind[], thisInstanceEvents: EventKind[], gracePeriod: boolean] => {
const thisInstanceEvents = allEvents
.filter((event) => new Date(getEventTimestamp(event)) >= lastActivity)
.sort((a, b) => getEventTimestamp(a).localeCompare(getEventTimestamp(b)));
.toSorted((a, b) => getEventTimestamp(a).localeCompare(getEventTimestamp(b)));

Check warning on line 75 in frontend/src/pages/projects/notebook/utils.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/projects/notebook/utils.ts#L75

Added line #L75 was not covered by tests
if (thisInstanceEvents.length === 0) {
// Filtered out all of the events, exit early
return [[], [], false];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NotebooksCardItems: React.FC<NotebooksCardItemsProps> = ({
return [];
}

const listItems = notebooks.sort(notebookSorter).slice(0, 5);
const listItems = notebooks.toSorted(notebookSorter).slice(0, 5);

return (
<Flex direction={{ default: 'column' }} gap={{ default: 'gapSm' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ImageStreamSelector: React.FC<ImageStreamSelectorProps> = ({
buildStatuses,
compatibleAcceleratorIdentifier,
}) => {
const options = [...imageStreams].sort(compareImageStreamOrder).map((imageStream) => {
const options = imageStreams.toSorted(compareImageStreamOrder).map((imageStream) => {
const description = getRelatedVersionDescription(imageStream);
const displayName = getImageStreamDisplayName(imageStream);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ImageVersionSelector: React.FC<ImageVersionSelectorProps> = ({
}

const selectOptionObjects = [...imageVersions]
.sort(compareImageVersionOrder)
.toSorted(compareImageVersionOrder)
.map((imageVersion) => getImageVersionSelectOptionObject(imageStream, imageVersion));

const options = selectOptionObjects.map((optionObject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const getDefaultVersionForImageStream = (
return undefined;
}

const sortedVersions = [...availableVersions].sort(compareTagVersions);
const sortedVersions = availableVersions.toSorted(compareTagVersions);

// Return the most recent version
return sortedVersions[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useBuildStatuses = (namespace?: string): BuildStatus[] => {
imageStreamVersion: buildConfig.spec.output.to.name,
};
}
const mostRecent = builds.sort(compareBuilds).pop() as BuildKind;
const mostRecent = builds.toSorted(compareBuilds).pop() as BuildKind;

Check warning on line 29 in frontend/src/pages/projects/screens/spawner/useBuildStatuses.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/projects/screens/spawner/useBuildStatuses.ts#L29

Added line #L29 was not covered by tests
return {
name: buildNotebookName,
status: mostRecent.status.phase,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utilities/__tests__/imageUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('compareTagVersions', () => {
{ name: 'v3', recommended: false },
] as ImageTagInfo[],
};
expect(recemendedTagVersion.tag.sort(compareTagVersions)).toEqual([
expect(recemendedTagVersion.tag.toSorted(compareTagVersions)).toEqual([
{ name: 'v2', recommended: true },
{ name: 'v3', recommended: false },
{ name: 'v1', recommended: false },
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utilities/imageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const getDefaultTag = (
}

// Return the most recent version
return [...tags].sort(compareTagVersions)[0];
return tags.toSorted(compareTagVersions)[0];
};

export const getTagForImage = (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utilities/notebookControllerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const filterEvents = (
): [filterEvents: K8sEvent[], thisInstanceEvents: K8sEvent[], gracePeroid: boolean] => {
const thisInstanceEvents = allEvents
.filter((event) => new Date(getEventTimestamp(event)) >= lastActivity)
.sort((a, b) => getEventTimestamp(a).localeCompare(getEventTimestamp(b)));
.toSorted((a, b) => getEventTimestamp(a).localeCompare(getEventTimestamp(b)));

Check warning on line 248 in frontend/src/utilities/notebookControllerUtils.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/utilities/notebookControllerUtils.ts#L248

Added line #L248 was not covered by tests
if (thisInstanceEvents.length === 0) {
// Filtered out all of the events, exit early
return [[], [], false];
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/utilities/useWatchBuildStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const useWatchBuildStatus = (): BuildStatus[] => {
const watchBuildStatuses = () => {
fetchBuildStatuses()
.then((buildStatuses: BuildStatus[]) => {
buildStatuses.sort((a, b) => a.name.localeCompare(b.name));
setStatuses(buildStatuses);
setStatuses(buildStatuses.toSorted((a, b) => a.name.localeCompare(b.name)));

Check warning on line 31 in frontend/src/utilities/useWatchBuildStatus.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/utilities/useWatchBuildStatus.tsx#L31

Added line #L31 was not covered by tests
})
// eslint-disable-next-line @typescript-eslint/no-empty-function
.catch(() => {});
Expand Down
9 changes: 2 additions & 7 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"outDir": "public",
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom"],
"lib": ["es6", "dom", "ES2023.Array"],
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
Expand All @@ -25,10 +25,5 @@
"skipLibCheck": true
},
"include": ["**/*.ts", "**/*.tsx", "**/*.jsx", "**/*.js"],
"exclude": [
"node_modules",
"public",
"public-cypress",
"src/__tests__/cypress"
]
"exclude": ["node_modules", "public", "public-cypress", "src/__tests__/cypress"]
}

0 comments on commit 770d616

Please sign in to comment.