From f2eebe95bde72820ff189718dd7d84ce6eb7733a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 16 Apr 2024 03:46:45 -0700 Subject: [PATCH] chore: Adds deprecated-imports-next-router (#14486) --- .../oauth-clients/OAuthClientForm.tsx | 2 +- .../platform/oauth-clients/index.tsx | 2 +- .../eslint-plugin/src/configs/recommended.ts | 1 + .../rules/deprecated-imports-next-router.ts | 38 +++++++++++++++++++ packages/eslint-plugin/src/rules/index.ts | 1 + packages/lib/next-seo.config.ts | 9 +---- .../examples/base/src/pages/[bookingUid].tsx | 2 +- .../examples/base/src/pages/booking.tsx | 2 +- .../examples/base/src/pages/bookings.tsx | 2 +- 9 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts diff --git a/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx b/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx index 39ad429caa..7225896d9d 100644 --- a/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx +++ b/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx @@ -1,4 +1,4 @@ -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; import type { FC } from "react"; import React, { useState, useCallback, useEffect } from "react"; import { useForm, useFieldArray } from "react-hook-form"; diff --git a/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx b/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx index 5daeb9fb7c..8daef7c847 100644 --- a/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx +++ b/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx @@ -1,5 +1,5 @@ import { QueryClientProvider, QueryClient } from "@tanstack/react-query"; -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; import React from "react"; import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout"; diff --git a/packages/eslint-plugin/src/configs/recommended.ts b/packages/eslint-plugin/src/configs/recommended.ts index f1e114d4be..05c5405e75 100644 --- a/packages/eslint-plugin/src/configs/recommended.ts +++ b/packages/eslint-plugin/src/configs/recommended.ts @@ -3,6 +3,7 @@ const recommended = { parserOptions: { sourceType: "module" }, rules: { "@calcom/eslint/deprecated-imports": "error", + "@calcom/eslint/deprecated-imports-next-router": "error", "@calcom/eslint/avoid-web-storage": "error", "@calcom/eslint/avoid-prisma-client-import-for-enums": "error", }, diff --git a/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts b/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts new file mode 100644 index 0000000000..d0cef9e229 --- /dev/null +++ b/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts @@ -0,0 +1,38 @@ +import { ESLintUtils } from "@typescript-eslint/utils"; + +const createRule = ESLintUtils.RuleCreator((name) => `https://developer.cal.com/eslint/rule/${name}`); + +const rule = createRule({ + name: "deprecated-imports-next-router", + meta: { + fixable: "code", + docs: { + description: "Importing router from 'next/router' is deprecated, use 'next/navigation' instead", + recommended: "error", + }, + messages: { + "deprecated-next-router": + "Importing router from 'next/router' is deprecated, use 'next/navigation' instead", + }, + type: "problem", + schema: [], + }, + defaultOptions: [], + create(context) { + return { + ImportDeclaration(node) { + if (node.source.value === "next/router") { + context.report({ + node, + messageId: "deprecated-next-router", + fix: function (fixer) { + return fixer.replaceText(node.source, "'next/navigation'"); + }, + }); + } + }, + }; + }, +}); + +export default rule; diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index 60ce126178..da144ae093 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -5,4 +5,5 @@ export default { "deprecated-imports": require("./deprecated-imports").default, "avoid-web-storage": require("./avoid-web-storage").default, "avoid-prisma-client-import-for-enums": require("./avoid-prisma-client-import-for-enums").default, + "deprecated-imports-next-router": require("./deprecated-imports-next-router").default, } as ESLint.Plugin["rules"]; diff --git a/packages/lib/next-seo.config.ts b/packages/lib/next-seo.config.ts index edff0d59f4..27c2590179 100644 --- a/packages/lib/next-seo.config.ts +++ b/packages/lib/next-seo.config.ts @@ -1,5 +1,4 @@ import type { DefaultSeoProps, NextSeoProps } from "next-seo"; -import type { Router } from "next/router"; import { APP_NAME, SEO_IMG_DEFAULT, SEO_IMG_OGIMG } from "@calcom/lib/constants"; @@ -47,12 +46,6 @@ export const seoConfig: { * @param path NextJS' useRouter().asPath * @returns */ -export const buildCanonical = ({ - origin, - path, -}: { - origin: Location["origin"]; - path: Router["asPath"] | null; -}) => { +export const buildCanonical = ({ origin, path }: { origin: Location["origin"]; path: string | null }) => { return `${origin}${path === "/" ? "" : path}`.split("?")[0]; }; diff --git a/packages/platform/examples/base/src/pages/[bookingUid].tsx b/packages/platform/examples/base/src/pages/[bookingUid].tsx index 54968af26b..3c85817162 100644 --- a/packages/platform/examples/base/src/pages/[bookingUid].tsx +++ b/packages/platform/examples/base/src/pages/[bookingUid].tsx @@ -2,7 +2,7 @@ import { Navbar } from "@/components/Navbar"; import { CheckCircle2Icon } from "lucide-react"; import { X } from "lucide-react"; import { Inter } from "next/font/google"; -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; import { useGetBooking, useCancelBooking } from "@calcom/atoms"; import dayjs from "@calcom/dayjs"; diff --git a/packages/platform/examples/base/src/pages/booking.tsx b/packages/platform/examples/base/src/pages/booking.tsx index 1a8f8c81ef..e796616841 100644 --- a/packages/platform/examples/base/src/pages/booking.tsx +++ b/packages/platform/examples/base/src/pages/booking.tsx @@ -1,6 +1,6 @@ import { Navbar } from "@/components/Navbar"; import { Inter } from "next/font/google"; -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; import { useState } from "react"; import { Booker, useEventTypesPublic } from "@calcom/atoms"; diff --git a/packages/platform/examples/base/src/pages/bookings.tsx b/packages/platform/examples/base/src/pages/bookings.tsx index d9d38c4db5..ee4e0aed19 100644 --- a/packages/platform/examples/base/src/pages/bookings.tsx +++ b/packages/platform/examples/base/src/pages/bookings.tsx @@ -1,6 +1,6 @@ import { Navbar } from "@/components/Navbar"; import { Inter } from "next/font/google"; -import { useRouter } from "next/router"; +import { useRouter } from "next/navigation"; import { useGetBookings } from "@calcom/atoms"; import dayjs from "@calcom/dayjs";