From 76cbba0c7957af8aaa3421dee2c8b28763f0ac0d Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Wed, 6 Nov 2024 10:50:42 +1300 Subject: [PATCH 1/4] Enable no-cycle eslint rule --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 0e3de29e..bc9d3518 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -45,6 +45,7 @@ module.exports = { 'react-hooks/exhaustive-deps': 'warn', 'react-hooks/rules-of-hooks': 'error', semi: 'off', + 'import/no-cycle': 'warn', }, overrides: [ { From 5fd2cae098e1de7ed899156ea9a908af92c9e666 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Wed, 6 Nov 2024 10:50:56 +1300 Subject: [PATCH 2/4] Fix cyclic imports --- examples/routing-with-resources/about.tsx | 1 + examples/routing-with-resources/home.tsx | 1 + examples/routing-with-resources/routes.tsx | 1 + .../utils/get-resources-for-next-location/index.ts | 2 +- src/resources/controllers/use-resource/index.ts | 8 +++++--- src/resources/plugin/index.ts | 2 +- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/routing-with-resources/about.tsx b/examples/routing-with-resources/about.tsx index 8d51f4ee..e52a17b0 100644 --- a/examples/routing-with-resources/about.tsx +++ b/examples/routing-with-resources/about.tsx @@ -1,5 +1,6 @@ import React from 'react'; +// eslint-disable-next-line import/no-cycle import { homeRoute } from './routes'; import { Link, useQueryParam } from 'react-resource-router'; diff --git a/examples/routing-with-resources/home.tsx b/examples/routing-with-resources/home.tsx index 3e8a078b..30f433c4 100644 --- a/examples/routing-with-resources/home.tsx +++ b/examples/routing-with-resources/home.tsx @@ -1,5 +1,6 @@ import React from 'react'; +// eslint-disable-next-line import/no-cycle import { aboutRoute } from './routes'; import { Link } from 'react-resource-router'; diff --git a/examples/routing-with-resources/routes.tsx b/examples/routing-with-resources/routes.tsx index a1119107..ff46860e 100644 --- a/examples/routing-with-resources/routes.tsx +++ b/examples/routing-with-resources/routes.tsx @@ -1,3 +1,4 @@ +/* eslint-disable import/no-cycle */ import { About, aboutResource } from './about'; import { Home, homeResource } from './home'; diff --git a/src/resources/controllers/resource-store/utils/get-resources-for-next-location/index.ts b/src/resources/controllers/resource-store/utils/get-resources-for-next-location/index.ts index 3776e811..2297bab6 100644 --- a/src/resources/controllers/resource-store/utils/get-resources-for-next-location/index.ts +++ b/src/resources/controllers/resource-store/utils/get-resources-for-next-location/index.ts @@ -1,4 +1,4 @@ -import { RouterContext } from '../../../../../index'; +import { type RouterContext } from '../../../../../index'; import { ResourceStoreContext, RouteResource, diff --git a/src/resources/controllers/use-resource/index.ts b/src/resources/controllers/use-resource/index.ts index 6426884c..8e630580 100644 --- a/src/resources/controllers/use-resource/index.ts +++ b/src/resources/controllers/use-resource/index.ts @@ -1,19 +1,21 @@ import { useCallback, useMemo } from 'react'; import { createHook } from 'react-sweet-state'; +import { type RouterContext } from '../../../common/types'; import { - RouterContext, RouterStore, useRouterStoreActions, +} from '../../../controllers/router-store'; +import { type EntireRouterState, type AllRouterActions, -} from '../../../index'; +} from '../../../controllers/router-store/types'; import { RouteResource, RouteResourceResponse, RouteResourceUpdater, UseResourceHookResponse, -} from '../../index'; +} from '../../common/types'; import { useResourceStore, useResourceStoreActions } from '../resource-store'; type UseResourceOptions = { diff --git a/src/resources/plugin/index.ts b/src/resources/plugin/index.ts index 4b077ef9..a60ed024 100644 --- a/src/resources/plugin/index.ts +++ b/src/resources/plugin/index.ts @@ -1,4 +1,4 @@ -import { Plugin, RouterContext } from '../../index'; +import type { Plugin, RouterContext } from '../../index'; import type { ResourceStoreContext, RouteResourceResponse, From 87bfb508a2352898e03b5b30926795678995a03c Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Wed, 6 Nov 2024 11:20:28 +1300 Subject: [PATCH 3/4] Change no-cycle to error --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index bc9d3518..82417b14 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -45,7 +45,7 @@ module.exports = { 'react-hooks/exhaustive-deps': 'warn', 'react-hooks/rules-of-hooks': 'error', semi: 'off', - 'import/no-cycle': 'warn', + 'import/no-cycle': 'error', }, overrides: [ { From cb59d99effcd2945bcb098c00ce13b946581f026 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Thu, 7 Nov 2024 08:59:37 +1300 Subject: [PATCH 4/4] Add changeset --- .changeset/angry-points-live.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/angry-points-live.md diff --git a/.changeset/angry-points-live.md b/.changeset/angry-points-live.md new file mode 100644 index 00000000..a2c768b2 --- /dev/null +++ b/.changeset/angry-points-live.md @@ -0,0 +1,5 @@ +--- +"react-resource-router": patch +--- + +Remove cyclic imports and add eslint rule to stop future issues