diff --git a/packages/console/.eslintrc.cjs b/packages/console/.eslintrc.cjs new file mode 100644 index 000000000..f2cffeab3 --- /dev/null +++ b/packages/console/.eslintrc.cjs @@ -0,0 +1,53 @@ +// eslint-disable-next-line import/no-extraneous-dependencies -- a transitive dependency of @silverhand/eslint-config +const xo = require('eslint-config-xo'); + +/** @type {import('eslint').Linter.Config} */ +module.exports = { + extends: '@silverhand/react', + parserOptions: { + project: ['./tsconfig.json', './tsconfig.scripts.gen.json'], + }, + rules: { + 'react/function-component-definition': [ + 'error', + { + namedComponents: 'function-declaration', + unnamedComponents: 'arrow-function', + }, + ], + 'import/no-unused-modules': [ + 'error', + { + unusedExports: true, + }, + ], + }, + overrides: [ + { + files: [ + '*.d.ts', + '**/assets/docs/guides/types.ts', + '**/assets/docs/guides/*/index.ts', + '**/assets/docs/guides/*/components/**/*.tsx', + '**/mdx-components*/*/index.tsx', + ], + rules: { + 'import/no-unused-modules': 'off', + }, + }, + { + files: ['src/pages/**/*.tsx'], + rules: { + 'no-restricted-imports': [ + ...xo.rules['no-restricted-imports'], + { + name: 'react-router-dom', + importNames: ['Route', 'Routes'], + message: + "Don't use `Route` or `Routes` in pages, add routes to `src/hooks/use-console-routes` instead.", + }, + ], + }, + }, + ], +}; diff --git a/packages/console/package.json b/packages/console/package.json index d614198b9..bae2b102e 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -142,44 +142,6 @@ "@cloud/*": "./src/cloud/$1", "@mdx/components/*": "./src/mdx-components/$1" }, - "eslintConfig": { - "extends": "@silverhand/react", - "parserOptions": { - "project": [ - "./tsconfig.json", - "./tsconfig.scripts.gen.json" - ] - }, - "rules": { - "react/function-component-definition": [ - "error", - { - "namedComponents": "function-declaration", - "unnamedComponents": "arrow-function" - } - ], - "import/no-unused-modules": [ - "error", - { - "unusedExports": true - } - ] - }, - "overrides": [ - { - "files": [ - "*.d.ts", - "**/assets/docs/guides/types.ts", - "**/assets/docs/guides/*/index.ts", - "**/assets/docs/guides/*/components/**/*.tsx", - "**/mdx-components*/*/index.tsx" - ], - "rules": { - "import/no-unused-modules": "off" - } - } - ] - }, "stylelint": { "extends": "@silverhand/eslint-config-react/.stylelintrc" }, diff --git a/packages/console/src/pages/ApiResourceDetails/index.tsx b/packages/console/src/pages/ApiResourceDetails/index.tsx index 2c3a48248..f8dddb270 100644 --- a/packages/console/src/pages/ApiResourceDetails/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/index.tsx @@ -6,6 +6,8 @@ import classNames from 'classnames'; import { useEffect, useState } from 'react'; import { toast } from 'react-hot-toast'; import { Trans, useTranslation } from 'react-i18next'; +// FIXME: @yijun +// eslint-disable-next-line no-restricted-imports import { Navigate, Route, Routes, useLocation, useParams } from 'react-router-dom'; import useSWR from 'swr'; diff --git a/packages/console/src/pages/OrganizationDetails/index.tsx b/packages/console/src/pages/OrganizationDetails/index.tsx index 1ac59d6fc..f7fd6db6a 100644 --- a/packages/console/src/pages/OrganizationDetails/index.tsx +++ b/packages/console/src/pages/OrganizationDetails/index.tsx @@ -1,6 +1,8 @@ import { type Organization } from '@logto/schemas'; import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; +// FIXME: @gao +// eslint-disable-next-line no-restricted-imports import { Navigate, Route, Routes, useParams } from 'react-router-dom'; import useSWR from 'swr'; diff --git a/packages/console/src/pages/OrganizationRoleDetails/index.tsx b/packages/console/src/pages/OrganizationRoleDetails/index.tsx index 9abcfcfdd..3f05670c3 100644 --- a/packages/console/src/pages/OrganizationRoleDetails/index.tsx +++ b/packages/console/src/pages/OrganizationRoleDetails/index.tsx @@ -3,6 +3,8 @@ import { type OrganizationRole } from '@logto/schemas'; import { useState } from 'react'; import { toast } from 'react-hot-toast'; import { useTranslation } from 'react-i18next'; +// FIXME: @yijun +// eslint-disable-next-line no-restricted-imports import { Navigate, Route, Routes, useParams } from 'react-router-dom'; import useSWR, { useSWRConfig } from 'swr'; diff --git a/packages/console/src/pages/Organizations/Guide/index.tsx b/packages/console/src/pages/Organizations/Guide/index.tsx index ba92548a3..e59e80ef1 100644 --- a/packages/console/src/pages/Organizations/Guide/index.tsx +++ b/packages/console/src/pages/Organizations/Guide/index.tsx @@ -1,5 +1,7 @@ import { useCallback } from 'react'; import Modal from 'react-modal'; +// FIXME: @charles +// eslint-disable-next-line no-restricted-imports import { Navigate, Route, Routes } from 'react-router-dom'; import DsModalHeader from '@/ds-components/ModalHeader'; diff --git a/packages/console/src/pages/TenantSettings/TenantMembers/index.tsx b/packages/console/src/pages/TenantSettings/TenantMembers/index.tsx index 9af808b80..52655714d 100644 --- a/packages/console/src/pages/TenantSettings/TenantMembers/index.tsx +++ b/packages/console/src/pages/TenantSettings/TenantMembers/index.tsx @@ -1,5 +1,7 @@ import classNames from 'classnames'; import { useContext, useState } from 'react'; +// FIXME: @charles +// eslint-disable-next-line no-restricted-imports import { Route, Routes } from 'react-router-dom'; import useSWRMutation from 'swr/mutation';