chore: replace eslint with biome (#14263)

This commit is contained in:
Kayla Washburn-Love
2024-08-15 13:26:29 -06:00
committed by GitHub
parent 7b09d98238
commit d15f16fa2e
592 changed files with 4160 additions and 6288 deletions
+13 -16
View File
@@ -1,13 +1,13 @@
import "testHelpers/localStorage";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { http, HttpResponse } from "msw";
import type { Region } from "api/typesGenerated";
import { http, HttpResponse } from "msw";
import {
MockPrimaryWorkspaceProxy,
MockWorkspaceProxies,
MockHealthyWildWorkspaceProxy,
MockPrimaryWorkspaceProxy,
MockUnhealthyWildWorkspaceProxy,
MockWorkspaceProxies,
} from "testHelpers/entities";
import {
renderWithAuth,
@@ -15,8 +15,8 @@ import {
} from "testHelpers/renderHelpers";
import { server } from "testHelpers/server";
import {
getPreferredProxy,
ProxyProvider,
getPreferredProxy,
saveUserSelectedProxy,
useProxy,
} from "./ProxyContext";
@@ -99,14 +99,14 @@ describe("ProxyContextGetURLs", () => {
// This should be ignored because it's unhealthy
[MockUnhealthyWildWorkspaceProxy.id]: fakeLatency(25),
// This should be ignored because it is not in the list.
["not a proxy"]: fakeLatency(10),
"not a proxy": fakeLatency(10),
},
undefined,
MockHealthyWildWorkspaceProxy.path_app_url,
MockHealthyWildWorkspaceProxy.wildcard_hostname,
],
])(
`%p`,
"%p",
(
_,
regions,
@@ -130,7 +130,7 @@ const TestingComponent = () => {
<TestingScreen />
</ProxyProvider>,
{
route: `/proxies`,
route: "/proxies",
path: "/proxies",
},
);
@@ -144,11 +144,8 @@ const TestingScreen = () => {
<>
<div data-testid="isFetched" title={isFetched.toString()}></div>
<div data-testid="isLoading" title={isLoading.toString()}></div>
<div
data-testid="preferredProxy"
title={proxy.proxy && proxy.proxy.id}
></div>
<div data-testid="userProxy" title={userProxy && userProxy.id}></div>
<div data-testid="preferredProxy" title={proxy.proxy?.id}></div>
<div data-testid="userProxy" title={userProxy?.id}></div>
<button data-testid="clearProxy" onClick={clearProxy}></button>
<div data-testid="userSelectProxyData"></div>
<button
@@ -323,14 +320,14 @@ describe("ProxyContextSelection", () => {
storageProxy: MockUnhealthyWildWorkspaceProxy,
expUserProxyID: MockUnhealthyWildWorkspaceProxy.id,
latencies: {
["some"]: fakeLatency(500),
["random"]: fakeLatency(100),
["ids"]: fakeLatency(25),
some: fakeLatency(500),
random: fakeLatency(100),
ids: fakeLatency(25),
},
},
],
] as [string, ProxyContextSelectionTest][])(
`%s`,
"%s",
async (
_,
{
+7 -7
View File
@@ -1,18 +1,18 @@
import { API } from "api/api";
import { cachedQuery } from "api/queries/util";
import type { Region, WorkspaceProxy } from "api/typesGenerated";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import {
createContext,
type FC,
type PropsWithChildren,
createContext,
useCallback,
useContext,
useEffect,
useState,
} from "react";
import { useQuery } from "react-query";
import { API } from "api/api";
import { cachedQuery } from "api/queries/util";
import type { Region, WorkspaceProxy } from "api/typesGenerated";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import { type ProxyLatencyReport, useProxyLatency } from "./useProxyLatency";
export interface ProxyContextValue {
@@ -142,9 +142,9 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
// This useEffect ensures the proxy to be used is updated whenever the state changes.
// This includes proxies being loaded, latencies being calculated, and the user selecting a proxy.
// biome-ignore lint/correctness/useExhaustiveDependencies: Only update if the source data changes
useEffect(() => {
updateProxy();
// eslint-disable-next-line react-hooks/exhaustive-deps -- Only update if the source data changes
}, [proxiesResp, proxyLatencies]);
return (
+2 -1
View File
@@ -1,8 +1,9 @@
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
import CssBaseline from "@mui/material/CssBaseline";
import {
StyledEngineProvider,
ThemeProvider as MuiThemeProvider,
StyledEngineProvider,
// biome-ignore lint/nursery/noRestrictedImports: we extend the MUI theme
} from "@mui/material/styles";
import {
type FC,
+9 -9
View File
@@ -1,11 +1,3 @@
import {
type FC,
type PropsWithChildren,
createContext,
useCallback,
useContext,
} from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { isApiError } from "api/errors";
import { checkAuthorization } from "api/queries/authCheck";
import {
@@ -18,7 +10,15 @@ import {
import type { UpdateUserProfileRequest, User } from "api/typesGenerated";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import { permissionsToCheck, type Permissions } from "./permissions";
import {
type FC,
type PropsWithChildren,
createContext,
useCallback,
useContext,
} from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { type Permissions, permissionsToCheck } from "./permissions";
export type AuthContextValue = {
isLoading: boolean;
+2 -2
View File
@@ -1,11 +1,11 @@
import { screen, renderHook } from "@testing-library/react";
import { renderHook, screen } from "@testing-library/react";
import { http, HttpResponse } from "msw";
import type { FC, PropsWithChildren } from "react";
import { QueryClientProvider } from "react-query";
import { MockPermissions, MockUser } from "testHelpers/entities";
import {
renderWithAuth,
createTestQueryClient,
renderWithAuth,
} from "testHelpers/renderHelpers";
import { server } from "testHelpers/server";
import { AuthContext, type AuthContextValue } from "./AuthProvider";
+2 -2
View File
@@ -1,10 +1,10 @@
import { type FC, useEffect } from "react";
import { Outlet, Navigate, useLocation } from "react-router-dom";
import { API } from "api/api";
import { isApiError } from "api/errors";
import { Loader } from "components/Loader/Loader";
import { ProxyProvider } from "contexts/ProxyContext";
import { DashboardProvider } from "modules/dashboard/DashboardProvider";
import { type FC, useEffect } from "react";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { embedRedirect } from "utils/redirect";
import { type AuthContextValue, useAuthContext } from "./AuthProvider";
+2 -2
View File
@@ -15,7 +15,7 @@ export const RequirePermission: FC<RequirePermissionProps> = ({
}) => {
if (!isFeatureVisible) {
return <Navigate to="/workspaces" />;
} else {
return <>{children}</>;
}
return <>{children}</>;
};
+13 -15
View File
@@ -1,7 +1,7 @@
import PerformanceObserver from "@fastly/performance-observer-polyfill";
import { useEffect, useReducer, useState } from "react";
import { API } from "api/api";
import type { Region } from "api/typesGenerated";
import { useEffect, useReducer, useState } from "react";
import { generateRandomString } from "utils/random";
const proxyIntervalSeconds = 30; // seconds
@@ -99,8 +99,7 @@ export const useProxyLatency = (
// 1. Fetch the latest stored latency for the given proxy.
// 2. If the latest latency is after the latestFetchRequest, then skip the latency check.
if (
storedLatencies &&
storedLatencies[proxy.id] &&
storedLatencies?.[proxy.id] &&
storedLatencies[proxy.id].length > 0
) {
const fetchRequestDate = new Date(latestFetchRequest);
@@ -189,9 +188,9 @@ export const useProxyLatency = (
// to the proxies.
const observer = new PerformanceObserver((list) => {
// If we get entries via this callback, then dispatch the events to the latency reducer.
list.getEntries().forEach((entry) => {
for (const entry of list.getEntries()) {
dispatchProxyLatenciesGuarded(entry);
});
}
});
// The resource requests include xmlhttp requests.
@@ -215,9 +214,9 @@ export const useProxyLatency = (
// takeRecords will return any entries that were not called via the callback yet.
// We want to call this before we disconnect the observer to make sure we get all the
// proxy requests recorded.
observer.takeRecords().forEach((entry) => {
for (const entry of observer.takeRecords()) {
dispatchProxyLatenciesGuarded(entry);
});
}
// At this point, we can be confident that all the proxy requests have been recorded
// via the performance observer. So we can disconnect the observer.
observer.disconnect();
@@ -291,19 +290,18 @@ const cleanupLatencies = (
now: Date,
maxStored: number,
): Record<string, ProxyLatencyReport[]> => {
Object.keys(stored).forEach((proxyID) => {
if (!regions.find((region) => region.id === proxyID)) {
delete stored[proxyID];
return;
for (const [proxyId, reports] of Object.entries(stored)) {
if (!regions.find((region) => region.id === proxyId)) {
delete stored[proxyId];
continue;
}
const reports = stored[proxyID];
const nowMS = now.getTime();
stored[proxyID] = reports.filter((report) => {
stored[proxyId] = reports.filter((report) => {
// Only keep the reports that are less then 1 week old.
return new Date(report.at).getTime() > nowMS - 1000 * 60 * 60 * 24 * 7;
});
// Only keep the 5 latest
stored[proxyID] = stored[proxyID].slice(-1 * maxStored);
});
stored[proxyId] = stored[proxyId].slice(-1 * maxStored);
}
return stored;
};