From be025362b6c58257a296658501172b739dbc4cce Mon Sep 17 00:00:00 2001 From: Michal Miszczyszyn Date: Wed, 17 Aug 2022 13:44:32 +0200 Subject: [PATCH 01/24] Make eslint rules consistent --- apps/saleor-app-checkout/.eslintrc.js | 10 +---- .../providers/mollie/createPayment.ts | 2 +- .../elements/ErrorAlert/ErrorAlert.tsx | 2 +- .../CustomizationDetails.tsx | 2 +- apps/saleor-app-checkout/package.json | 1 + apps/storefront/.eslintrc.js | 10 +---- apps/storefront/package.json | 2 +- packages/checkout-common/package.json | 3 +- packages/checkout-storefront/.eslintrc.js | 2 - packages/checkout-storefront/package.json | 7 ++-- .../CheckoutForm/useCheckoutFinalize.ts | 2 +- .../src/sections/Contact/Contact.tsx | 2 +- packages/eslint-config-checkout/index.js | 42 ++++++++++++++++++- packages/eslint-config-storefront/index.js | 12 ------ .../eslint-config-storefront/package.json | 21 ---------- packages/ui-kit/package.json | 3 +- .../components/RemoveButton/RemoveButton.tsx | 2 +- turbo.json | 6 +-- 18 files changed, 63 insertions(+), 68 deletions(-) delete mode 100644 packages/eslint-config-storefront/index.js delete mode 100644 packages/eslint-config-storefront/package.json diff --git a/apps/saleor-app-checkout/.eslintrc.js b/apps/saleor-app-checkout/.eslintrc.js index 9de0a3f92..effd35d42 100644 --- a/apps/saleor-app-checkout/.eslintrc.js +++ b/apps/saleor-app-checkout/.eslintrc.js @@ -1,15 +1,7 @@ module.exports = { - extends: ["checkout", "next"], + extends: ["checkout"], parserOptions: { tsconfigRootDir: __dirname, project: ["./tsconfig.json"], }, - settings: { - next: { - rootDir: ["."], - }, - }, - rules: { - "require-await": ["error"], - }, }; diff --git a/apps/saleor-app-checkout/backend/payments/providers/mollie/createPayment.ts b/apps/saleor-app-checkout/backend/payments/providers/mollie/createPayment.ts index 67d6b5cc4..b0a5c5e60 100644 --- a/apps/saleor-app-checkout/backend/payments/providers/mollie/createPayment.ts +++ b/apps/saleor-app-checkout/backend/payments/providers/mollie/createPayment.ts @@ -16,7 +16,7 @@ export const createMolliePayment = async ({ order, redirectUrl, appUrl }: Create const mollieClient = await getMollieClient(); const mollieData = await mollieClient.orders.create({ - orderNumber: order.number!, + orderNumber: order.number, webhookUrl: `${appUrl}/api/webhooks/mollie`, locale: "en_US", redirectUrl: formatRedirectUrl(redirectUrl, order.id), diff --git a/apps/saleor-app-checkout/frontend/components/elements/ErrorAlert/ErrorAlert.tsx b/apps/saleor-app-checkout/frontend/components/elements/ErrorAlert/ErrorAlert.tsx index a50dac34e..e5b96437b 100644 --- a/apps/saleor-app-checkout/frontend/components/elements/ErrorAlert/ErrorAlert.tsx +++ b/apps/saleor-app-checkout/frontend/components/elements/ErrorAlert/ErrorAlert.tsx @@ -14,7 +14,7 @@ interface ErrorAlertProps { getErrorMessage: (error: UnknownError, intl: IntlShape) => string | null | undefined; } -const ErrorAlert = ({ errors, getErrorMessage }: ErrorAlertProps) => { +const ErrorAlert = ({ errors, getErrorMessage }: ErrorAlertProps) => { const intl = useIntl(); const classes = useStyles(); diff --git a/apps/saleor-app-checkout/frontend/components/templates/CustomizationDetails/CustomizationDetails.tsx b/apps/saleor-app-checkout/frontend/components/templates/CustomizationDetails/CustomizationDetails.tsx index 034585d6b..3c472970a 100644 --- a/apps/saleor-app-checkout/frontend/components/templates/CustomizationDetails/CustomizationDetails.tsx +++ b/apps/saleor-app-checkout/frontend/components/templates/CustomizationDetails/CustomizationDetails.tsx @@ -72,7 +72,7 @@ const CustomizationDetails: React.FC = ({ event: React.ChangeEvent ) => { const inputFiles = event.target.files; - if (!!inputFiles?.length) { + if (inputFiles?.length) { setFiles({ ...files, [optionId]: { diff --git a/apps/saleor-app-checkout/package.json b/apps/saleor-app-checkout/package.json index 6d915fe82..70f82956d 100644 --- a/apps/saleor-app-checkout/package.json +++ b/apps/saleor-app-checkout/package.json @@ -9,6 +9,7 @@ "build": "npm run i18n && next build", "start": "next start -p 3001", "lint": "next lint", + "lint:staged": "next lint --fix", "check-types": "tsc --noEmit", "generate": "DOTENV_CONFIG_PATH=.env graphql-codegen -r env-vars --config codegen.yml", "extract:i18n": "formatjs extract '{pages,components,hooks,misc}/**/*.{js,ts,tsx}' --format transifex --id-interpolation-pattern '[folder]/[name]/[sha512:contenthash:base64:6]' --out-file content/locales/en.json", diff --git a/apps/storefront/.eslintrc.js b/apps/storefront/.eslintrc.js index 626e88fa5..1b2bb010f 100644 --- a/apps/storefront/.eslintrc.js +++ b/apps/storefront/.eslintrc.js @@ -1,16 +1,10 @@ module.exports = { root: true, - parser: "@typescript-eslint/parser", - extends: [ - "storefront", - "airbnb", - "plugin:@typescript-eslint/recommended", - "prettier", // prettier *has* to be the last one, to avoid conflicting rules - ], + extends: ["checkout"], // @todo: get rid of most of it ignorePatterns: ["saleor/api.tsx", "pnpm-lock.yaml", "graphql.schema.json", "lib/$path.ts"], - plugins: ["simple-import-sort", "formatjs", "@typescript-eslint"], + plugins: ["simple-import-sort", "formatjs"], rules: { quotes: ["error", "double"], "react/react-in-jsx-scope": "off", // next does not require react imports diff --git a/apps/storefront/package.json b/apps/storefront/package.json index 51000eac2..b1fd9da0a 100644 --- a/apps/storefront/package.json +++ b/apps/storefront/package.json @@ -74,7 +74,7 @@ "eslint-config-airbnb": "^19.0.4", "eslint-config-next": "^12.2.3", "eslint-config-prettier": "^8.5.0", - "eslint-config-storefront": "workspace:*", + "eslint-config-checkout": "workspace:*", "eslint-plugin-formatjs": "^3.1.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsx-a11y": "^6.5.1", diff --git a/packages/checkout-common/package.json b/packages/checkout-common/package.json index 5902d32ef..f925f7299 100644 --- a/packages/checkout-common/package.json +++ b/packages/checkout-common/package.json @@ -12,7 +12,8 @@ "check-types": "tsc --noEmit", "dev": "rollup -w -c", "build": "NODE_ENV=production rollup -c", - "lint": "eslint --max-warnings=0 \"src/**/*.@(tsx|ts|jsx|js)\" --fix" + "lint": "eslint --fix", + "lint:staged": "eslint" }, "dependencies": { "@material-ui/core": "^4.12.3" diff --git a/packages/checkout-storefront/.eslintrc.js b/packages/checkout-storefront/.eslintrc.js index 30a967a6e..9065237f3 100644 --- a/packages/checkout-storefront/.eslintrc.js +++ b/packages/checkout-storefront/.eslintrc.js @@ -4,7 +4,5 @@ module.exports = { tsconfigRootDir: __dirname, project: ["./tsconfig.json"], }, - plugins: ["react", "react-hooks"], extends: ["checkout"], - ignorePatterns: "*.js", }; diff --git a/packages/checkout-storefront/package.json b/packages/checkout-storefront/package.json index 0352bb990..056c084d7 100644 --- a/packages/checkout-storefront/package.json +++ b/packages/checkout-storefront/package.json @@ -10,10 +10,11 @@ "build": "NODE_ENV=production rollup -c", "generate": "DOTENV_CONFIG_PATH=.env graphql-codegen -r env-vars --config codegen.yml", "check-types": "tsc --noEmit", - "lint": "eslint --max-warnings=0 \"src/**/*.@(tsx|ts|jsx|js)\" --fix", - "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", "test": "jest", - "test:dev": "jest --watch" + "test:dev": "jest --watch", + "lint": "eslint", + "lint:staged": "eslint --fix", + "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" }, "peerDependencies": { "graphql": "^15.8.0", diff --git a/packages/checkout-storefront/src/sections/CheckoutForm/useCheckoutFinalize.ts b/packages/checkout-storefront/src/sections/CheckoutForm/useCheckoutFinalize.ts index a3c1a509f..c010c44c4 100644 --- a/packages/checkout-storefront/src/sections/CheckoutForm/useCheckoutFinalize.ts +++ b/packages/checkout-storefront/src/sections/CheckoutForm/useCheckoutFinalize.ts @@ -61,7 +61,7 @@ export const useCheckoutFinalize = () => { provider: formData.paymentProviderId, method: formData.paymentMethodId, checkoutId: checkout?.id, - totalAmount: checkout?.totalPrice?.gross?.amount as number, + totalAmount: checkout?.totalPrice?.gross?.amount, }); if (!result) { diff --git a/packages/checkout-storefront/src/sections/Contact/Contact.tsx b/packages/checkout-storefront/src/sections/Contact/Contact.tsx index 8a3939b0e..191798cf0 100644 --- a/packages/checkout-storefront/src/sections/Contact/Contact.tsx +++ b/packages/checkout-storefront/src/sections/Contact/Contact.tsx @@ -62,7 +62,7 @@ export const Contact: FC = ({ setShowOnlyContact }) => { return; } - await handleEmailUpdate(user?.email as string); + await handleEmailUpdate(user?.email); }; const updateEmailAfterSectionChange = async () => { diff --git a/packages/eslint-config-checkout/index.js b/packages/eslint-config-checkout/index.js index a7fac4c47..11eb1e576 100644 --- a/packages/eslint-config-checkout/index.js +++ b/packages/eslint-config-checkout/index.js @@ -5,13 +5,24 @@ module.exports = { project: ["./tsconfig.json"], }, plugins: ["@typescript-eslint"], - extends: ["prettier"], + extends: [ + "next", + "next/core-web-vitals", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking", + "prettier", + ], settings: { next: { rootDir: ["apps/*/", "packages/*/"], }, + react: { + version: "999.999.999", + }, }, rules: { + "@next/next/no-html-link-for-pages": "off", + "react/jsx-key": "off", "array-callback-return": "error", "no-alert": ["error"], "no-debugger": ["error"], @@ -26,5 +37,34 @@ module.exports = { ], "@typescript-eslint/no-misused-promises": ["error"], "@typescript-eslint/no-floating-promises": ["error"], + + // we allow empty interfaces + "no-empty-pattern": "off", + "@typescript-eslint/no-empty-interface": "off", + + // we allow empty functions + "@typescript-eslint/no-empty-function": "off", + + // @todo + "react/display-name": "off", + "react/no-children-prop": "off", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unsafe-return": "off", + "@typescript-eslint/require-await": "off", + "@typescript-eslint/no-unsafe-argument": "off", + "@typescript-eslint/no-unnecessary-type-assertion": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/restrict-plus-operands": "off", + "@typescript-eslint/no-non-null-asserted-optional-chain": "off", + "@typescript-eslint/no-unsafe-call": "off", + "@typescript-eslint/await-thenable": "off", + "@typescript-eslint/no-floating-promises": "off", + "require-await": "off", + "@typescript-eslint/no-misused-promises": "off", }, }; diff --git a/packages/eslint-config-storefront/index.js b/packages/eslint-config-storefront/index.js deleted file mode 100644 index f28d0ef2a..000000000 --- a/packages/eslint-config-storefront/index.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - extends: ["next", "prettier"], - rules: { - "@next/next/no-html-link-for-pages": "off", - "react/jsx-key": "off", - }, - settings: { - next: { - rootDir: ["apps/*/"], - }, - }, -}; diff --git a/packages/eslint-config-storefront/package.json b/packages/eslint-config-storefront/package.json deleted file mode 100644 index 99714d82d..000000000 --- a/packages/eslint-config-storefront/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "eslint-config-storefront", - "version": "0.0.0", - "main": "index.js", - "license": "MIT", - "resolutions": { - "eslint-plugin-react-hooks": "^4.5.0" - }, - "dependencies": { - "eslint": "8.15.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-react": "^7.29.4", - "eslint-config-next": "^12.2.3" - }, - "devDependencies": { - "typescript": "4.7.4" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/ui-kit/package.json b/packages/ui-kit/package.json index aa9a91564..b4d3df44b 100644 --- a/packages/ui-kit/package.json +++ b/packages/ui-kit/package.json @@ -17,7 +17,8 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "lint": "eslint --max-warnings=0 \"src/**/*.@(tsx|ts|jsx|js)\" --fix", + "lint": "eslint --fix", + "lint:staged": "eslint", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", "storybook": "start-storybook -p 6006", "build-storybook": "build-storybook", diff --git a/packages/ui-kit/src/components/RemoveButton/RemoveButton.tsx b/packages/ui-kit/src/components/RemoveButton/RemoveButton.tsx index f216a4d35..5d2f3b5b0 100644 --- a/packages/ui-kit/src/components/RemoveButton/RemoveButton.tsx +++ b/packages/ui-kit/src/components/RemoveButton/RemoveButton.tsx @@ -5,7 +5,7 @@ import styles from "./RemoveButton.module.css"; import { Button, ButtonProps } from "../Button"; import { RemoveIcon } from "../icons"; -export interface RemoveButtonProps extends Omit {} +export type RemoveButtonProps = Omit; export const RemoveButton: FC = ({ className, ...rest }) => (