From 85d857779320c1692139806c1e1cdc382535055c Mon Sep 17 00:00:00 2001 From: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Sun, 22 Sep 2024 00:25:59 +1200 Subject: [PATCH] style: add the tanstack router eslint plugin (#422) * install @tanstack/eslint-plugin-router * add the tanstack router eslint plugin into the config * style: linting the warnings reported by the plugin --- eslint.config.mjs | 2 ++ package.json | 1 + pnpm-lock.yaml | 16 ++++++++++++++++ src/routes/_auth/(reports)/reports._index.tsx | 2 +- src/routes/_public/oidc-callback.tsx | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 0805d5fc..8f11147e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,5 +1,6 @@ // @ts-check import eslintJs from "@eslint/js"; +import tanstackRouterPlugin from "@tanstack/eslint-plugin-router"; import eslintConfigPrettier from "eslint-config-prettier"; import eslintReact from "eslint-plugin-react"; import eslintReactCompiler from "eslint-plugin-react-compiler"; @@ -10,6 +11,7 @@ import tseslint from "typescript-eslint"; export default tseslint.config( eslintJs.configs.recommended, ...tseslint.configs.recommended, + ...tanstackRouterPlugin.configs["flat/recommended"], eslintConfigPrettier, { files: ["**.config.{cjs,mjs,ts,js}", "postbuild.cjs"], diff --git a/package.json b/package.json index 517118a2..30195b98 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@tailwindcss/container-queries": "^0.1.1", "@tailwindcss/forms": "^0.5.9", "@tailwindcss/typography": "^0.5.15", + "@tanstack/eslint-plugin-router": "^1.58.6", "@tanstack/router-plugin": "^1.58.4", "@types/node": "^22.5.4", "@types/react": "^18.3.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b39dce09..50f8a2c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,6 +195,9 @@ importers: '@tailwindcss/typography': specifier: ^0.5.15 version: 0.5.15(tailwindcss@3.4.10) + '@tanstack/eslint-plugin-router': + specifier: ^1.58.6 + version: 1.58.6(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) '@tanstack/router-plugin': specifier: ^1.58.4 version: 1.58.4(vite@5.4.7(@types/node@22.5.4)) @@ -1700,6 +1703,11 @@ packages: peerDependencies: tailwindcss: '>=3.0.0 || insiders || >=4.0.0-alpha.20' + '@tanstack/eslint-plugin-router@1.58.6': + resolution: {integrity: sha512-8nqu8vYqV4hA7Bq6fBi+YqwH7n6C9U/uMQCwyIEej1Qvzsblb/QHfSMYk8T6fWcnAgmgvPETWgar9/K+wd17ng==} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + '@tanstack/history@1.57.6': resolution: {integrity: sha512-ppAJbnUaHdHmccVmplcd1ivX4GMPHxhStSquuuz0TSAEPEpz0iOVBur4iKfvIuMKm24c40nhvaEwZbKGVfbrGg==} engines: {node: '>=12'} @@ -5097,6 +5105,14 @@ snapshots: postcss-selector-parser: 6.0.10 tailwindcss: 3.4.10 + '@tanstack/eslint-plugin-router@1.58.6(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4)': + dependencies: + '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + eslint: 9.9.1(jiti@1.21.0) + transitivePeerDependencies: + - supports-color + - typescript + '@tanstack/history@1.57.6': {} '@tanstack/match-sorter-utils@8.19.4': diff --git a/src/routes/_auth/(reports)/reports._index.tsx b/src/routes/_auth/(reports)/reports._index.tsx index fa0368e7..5187ded2 100644 --- a/src/routes/_auth/(reports)/reports._index.tsx +++ b/src/routes/_auth/(reports)/reports._index.tsx @@ -29,6 +29,7 @@ export const Route = createFileRoute("/_auth/(reports)/reports/")({ searchListOptions: fetchReportsListOptions({ auth }), }; }, + loaderDeps: ({ search: { category } }) => ({ category }), loader: async ({ context }) => { const { queryClient, searchListOptions } = context; @@ -38,7 +39,6 @@ export const Route = createFileRoute("/_auth/(reports)/reports/")({ return; }, - loaderDeps: ({ search: { category } }) => ({ category }), component: ReportSearchPage, }); diff --git a/src/routes/_public/oidc-callback.tsx b/src/routes/_public/oidc-callback.tsx index 220178d6..79e6a3c1 100644 --- a/src/routes/_public/oidc-callback.tsx +++ b/src/routes/_public/oidc-callback.tsx @@ -15,6 +15,7 @@ export const Route = createFileRoute("/_public/oidc-callback")({ state: z.string().optional(), session_state: z.string().optional(), }), + beforeLoad: ({ search }) => ({ search }), loaderDeps: ({ search }) => ({ redirect: search?.redirect, code: search?.code, @@ -22,7 +23,6 @@ export const Route = createFileRoute("/_public/oidc-callback")({ state: search?.state, session_state: search?.session_state, }), - beforeLoad: ({ search }) => ({ search }), loader: async ({ context, preload, location }) => { const locationPathname = location.pathname; if (preload || !locationPathname.includes("oidc-callback")) return;