Skip to content

Commit

Permalink
refactor: Upgrade ESlint to v9 & create shared config
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 committed Jul 3, 2024
1 parent 74180e1 commit 524161b
Show file tree
Hide file tree
Showing 139 changed files with 889 additions and 2,380 deletions.
18 changes: 0 additions & 18 deletions apps/landing-page/.eslintrc.cjs

This file was deleted.

11 changes: 3 additions & 8 deletions apps/landing-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"lint:check": "eslint .",
"lint": "eslint --fix ."
},
"dependencies": {
"@mantine/core": "^7.6.2",
Expand All @@ -23,16 +24,10 @@
"devDependencies": {
"@types/react": "^18.2.69",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"postcss": "^8.4.38",
"postcss-preset-mantine": "^1.13.0",
"postcss-simple-vars": "^7.0.1",
"typescript": "^5.2.2",
"vite": "^5.2.4",
"vite-plugin-node-polyfills": "^0.19.0"
}
Expand Down
18 changes: 0 additions & 18 deletions apps/playground/.eslintrc.cjs

This file was deleted.

11 changes: 3 additions & 8 deletions apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"lint:check": "eslint .",
"lint": "eslint --fix ."
},
"dependencies": {
"@mantine/core": "^7.10.1",
Expand All @@ -33,16 +34,10 @@
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"@vitejs/plugin-react": "^4.3.0",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"postcss": "^8.4.38",
"postcss-preset-mantine": "^1.15.0",
"postcss-simple-vars": "^7.0.1",
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-wasm": "^3.3.0"
Expand Down
3 changes: 3 additions & 0 deletions apps/playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const App = () => {

const [accounts, setAccounts] = useState<InjectedAccountWithMeta[]>([]);

// eslint-disable-next-line @typescript-eslint/unbound-method
const { selectedAccount, setSelectedAccount } = useWallet();

const initAccounts = async () => {
Expand Down Expand Up @@ -114,10 +115,12 @@ const App = () => {
<Image src="logo.png" h="100%" p={8} />
{selectedAccount ? (
<Button
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClick={onChangeAccountClick}
variant="outline"
>{`${selectedAccount.meta.name} (${selectedAccount.meta.source})`}</Button>
) : (
// eslint-disable-next-line @typescript-eslint/no-misused-promises
<Button onClick={onConnectWalletClick}>Connect wallet</Button>
)}
</Group>
Expand Down
3 changes: 2 additions & 1 deletion apps/playground/src/components/RouterTransferForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { useForm } from "@mantine/form";
import {
EXCHANGE_NODES,
Expand Down Expand Up @@ -58,7 +59,7 @@ const RouterTransferForm: FC<Props> = ({ onSubmit, loading }) => {
};

useEffect(() => {
(async () => {
void (async () => {
if (selectedAccount) {
const injector = await web3FromAddress(selectedAccount.address);
form.setFieldValue("evmSigner", injector.signer);
Expand Down
3 changes: 3 additions & 0 deletions apps/playground/src/components/TransferInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box } from "@mantine/core";
import ErrorAlert from "./ErrorAlert";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
Expand Down Expand Up @@ -38,6 +39,7 @@ const TransferInfo = () => {
const { useApi } = formValues;
const originAddress = selectedAccount?.address ?? "";
if (useApi) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await fetchFromApi(
{
origin: formValues.from,
Expand Down Expand Up @@ -70,6 +72,7 @@ const TransferInfo = () => {
setLoading(true);

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const output = await getQueryResult(formValues);
setOutput(JSON.stringify(output, null, 2));
openOutputAlert();
Expand Down
7 changes: 2 additions & 5 deletions apps/playground/src/components/XcmTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box } from "@mantine/core";
import ErrorAlert from "./ErrorAlert";
import TransferForm, { FormValues } from "./TransferForm";
Expand Down Expand Up @@ -42,11 +43,7 @@ const XcmTransfer = () => {
.address(address)
.build();
} else if (to === "Polkadot" || to === "Kusama") {
return Builder(api)
.from(from as TNode)
.amount(amount)
.address(address)
.build();
return Builder(api).from(from).amount(amount).address(address).build();
} else {
return Builder(api)
.from(from)
Expand Down
1 change: 1 addition & 0 deletions apps/playground/src/components/asset-claim/AssetClaim.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box } from "@mantine/core";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
import { Builder, createApiInstanceForNode } from "@paraspell/sdk";
Expand Down
3 changes: 3 additions & 0 deletions apps/playground/src/components/assets/AssetsQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box, Alert, Text } from "@mantine/core";
import ErrorAlert from "../ErrorAlert";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
Expand Down Expand Up @@ -101,6 +102,7 @@ const AssetsQueries = () => {
const getQueryResult = async (formValues: FormValues) => {
const { useApi } = formValues;
if (useApi) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await fetchFromApi(
formValues,
`/assets/${getEndpoint(formValues)}`
Expand All @@ -114,6 +116,7 @@ const AssetsQueries = () => {
setLoading(true);

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const output = await getQueryResult(formValues);
if (typeof output === "bigint") {
setOutput(output.toString());
Expand Down
8 changes: 6 additions & 2 deletions apps/playground/src/components/channels/ChannelsQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box } from "@mantine/core";
import ErrorAlert from "../ErrorAlert";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
Expand Down Expand Up @@ -40,7 +41,7 @@ const ChannelsQueries = () => {
}
}, [error, scrollIntoView]);

const submitUsingSdk = async (
const submitUsingSdk = (
{ func, from, to, maxSize, maxMessageSize, inbound, outbound }: FormValues,
api: ApiPromise
) => {
Expand All @@ -66,13 +67,14 @@ const ChannelsQueries = () => {
const getQueryResult = async (formValues: FormValues, api: ApiPromise) => {
const { func, useApi } = formValues;
if (useApi) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await fetchFromApi(
formValues,
`/hrmp/channels`,
func === "OPEN_CHANNEL" ? "POST" : "DELETE"
);
} else {
return await submitUsingSdk(formValues, api);
return submitUsingSdk(formValues, api);
}
};

Expand All @@ -90,12 +92,14 @@ const ChannelsQueries = () => {

try {
const api = await createApiInstanceForNode(from);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const output = await getQueryResult(formValues, api);
setOutput(JSON.stringify(output, null, 2));
openOutputAlert();
closeErrorAlert();
await submitTransaction(
api,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
buildTx(api, output),
injector.signer,
selectedAccount.address
Expand Down
51 changes: 32 additions & 19 deletions apps/playground/src/components/pallets/PalletsQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Stack, Title, Box } from '@mantine/core';
import ErrorAlert from '../ErrorAlert';
import { useDisclosure, useScrollIntoView } from '@mantine/hooks';
import { useState, useEffect } from 'react';
import { fetchFromApi } from '../../utils/submitUsingApi';
import { getDefaultPallet, getSupportedPallets } from '@paraspell/sdk';
import PalletsForm, { FormValues } from './PalletsForm';
import OutputAlert from '../OutputAlert';
/* eslint-disable @typescript-eslint/no-misused-promises */
import { Stack, Title, Box } from "@mantine/core";
import ErrorAlert from "../ErrorAlert";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
import { useState, useEffect } from "react";
import { fetchFromApi } from "../../utils/submitUsingApi";
import { getDefaultPallet, getSupportedPallets } from "@paraspell/sdk";
import PalletsForm, { FormValues } from "./PalletsForm";
import OutputAlert from "../OutputAlert";

const PalletsQueries = () => {
const [errorAlertOpened, { open: openErrorAlert, close: closeErrorAlert }] = useDisclosure(false);
const [outputAlertOpened, { open: openOutputAlert, close: closeOutputAlert }] =
const [errorAlertOpened, { open: openErrorAlert, close: closeErrorAlert }] =
useDisclosure(false);
const [
outputAlertOpened,
{ open: openOutputAlert, close: closeOutputAlert },
] = useDisclosure(false);

const [error, setError] = useState<Error>();
const [output, setOutput] = useState<string>();
Expand All @@ -27,37 +31,42 @@ const PalletsQueries = () => {
}
}, [error, scrollIntoView]);

const submitUsingSdk = async ({ func, node }: FormValues) => {
const submitUsingSdk = ({ func, node }: FormValues) => {
switch (func) {
case 'ALL_PALLETS':
case "ALL_PALLETS":
return getSupportedPallets(node);
case 'DEFAULT_PALLET':
case "DEFAULT_PALLET":
return getDefaultPallet(node);
}
};

const getEndpoint = ({ func, node }: FormValues) => {
switch (func) {
case 'ALL_PALLETS':
case "ALL_PALLETS":
return `${node}`;
case 'DEFAULT_PALLET':
case "DEFAULT_PALLET":
return `${node}/default`;
}
};

const getQueryResult = async (formValues: FormValues) => {
const { useApi } = formValues;
if (useApi) {
return await fetchFromApi(formValues, `/pallets/${getEndpoint(formValues)}`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return await fetchFromApi(
formValues,
`/pallets/${getEndpoint(formValues)}`
);
} else {
return await submitUsingSdk(formValues);
return submitUsingSdk(formValues);
}
};

const onSubmit = async (formValues: FormValues) => {
setLoading(true);

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const output = await getQueryResult(formValues);
setOutput(JSON.stringify(output, null, 2));
openOutputAlert();
Expand Down Expand Up @@ -90,11 +99,15 @@ const PalletsQueries = () => {
</Stack>
<Box ref={targetRef}>
{errorAlertOpened && (
<ErrorAlert onAlertCloseClick={onErrorAlertCloseClick}>{error?.message}</ErrorAlert>
<ErrorAlert onAlertCloseClick={onErrorAlertCloseClick}>
{error?.message}
</ErrorAlert>
)}
</Box>
<Box>
{outputAlertOpened && <OutputAlert onClose={onOutputAlertCloseClick}>{output}</OutputAlert>}
{outputAlertOpened && (
<OutputAlert onClose={onOutputAlertCloseClick}>{output}</OutputAlert>
)}
</Box>
</Stack>
);
Expand Down
3 changes: 2 additions & 1 deletion apps/playground/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import ReactDOM from "react-dom/client";
import App from "./App";
import WalletProvider from "./providers/WalletProvider";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(BigInt.prototype as any)["toJSON"] = function () {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
return this.toString();
};

Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/providers/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getWalletStateFromLocalStorage = ():
return undefined;
}

return JSON.parse(walletState);
return JSON.parse(walletState) as InjectedAccountWithMeta;
};

const WalletProvider: React.FC<PropsWithChildren<unknown>> = ({ children }) => {
Expand All @@ -28,7 +28,7 @@ const WalletProvider: React.FC<PropsWithChildren<unknown>> = ({ children }) => {
}, [selectedAccount]);

useEffect(() => {
web3Enable("SpellRouter");
void web3Enable("SpellRouter");
}, []);

return (
Expand Down
Loading

0 comments on commit 524161b

Please sign in to comment.