diff --git a/coral/.eslintrc.cjs b/coral/.eslintrc.cjs index 3d9d510c23..0b5e2e976d 100644 --- a/coral/.eslintrc.cjs +++ b/coral/.eslintrc.cjs @@ -19,7 +19,8 @@ module.exports = { }, "plugins": [ "react", - "@typescript-eslint" + "@typescript-eslint", + "no-relative-import-paths" ], "settings": { "react": { @@ -27,5 +28,8 @@ module.exports = { } }, "rules": { + "no-relative-import-paths/no-relative-import-paths": [ + "error" + ] } } diff --git a/coral/jest.config.ts b/coral/jest.config.ts index 26bbba659d..ee0ed304fa 100644 --- a/coral/jest.config.ts +++ b/coral/jest.config.ts @@ -7,10 +7,10 @@ export default { moduleFileExtensions: ["js", "jsx", "ts", "tsx"], preset: "ts-jest", testEnvironment: "jsdom", - setupFilesAfterEnv: ['/test-setup/setup-files-after-env.ts'], + setupFilesAfterEnv: ["/test-setup/setup-files-after-env.ts"], moduleNameMapper: { ".+\\.(png|jpg|ttf|woff|woff2|svg)$": "jest-transform-stub", "\\.css$": "identity-obj-proxy", - "^@/(.*)$": "/src/$1", + "^src/(.*)$": "/src/$1", }, }; diff --git a/coral/package.json b/coral/package.json index 8055a978e9..ce2c7f9648 100644 --- a/coral/package.json +++ b/coral/package.json @@ -46,6 +46,7 @@ "@vitejs/plugin-react": "^2.1.0", "eslint": "^8.25.0", "eslint-config-prettier": "^8.5.0", + "eslint-plugin-no-relative-import-paths": "^1.4.0", "eslint-plugin-react": "^7.31.10", "husky": "^8.0.1", "identity-obj-proxy": "^3.0.0", diff --git a/coral/pnpm-lock.yaml b/coral/pnpm-lock.yaml index 440f38acea..9e83e8f9ac 100644 --- a/coral/pnpm-lock.yaml +++ b/coral/pnpm-lock.yaml @@ -14,6 +14,7 @@ specifiers: '@vitejs/plugin-react': ^2.1.0 eslint: ^8.25.0 eslint-config-prettier: ^8.5.0 + eslint-plugin-no-relative-import-paths: ^1.4.0 eslint-plugin-react: ^7.31.10 husky: ^8.0.1 identity-obj-proxy: ^3.0.0 @@ -49,6 +50,7 @@ devDependencies: '@vitejs/plugin-react': 2.1.0_vite@3.1.8 eslint: 8.25.0 eslint-config-prettier: 8.5.0_eslint@8.25.0 + eslint-plugin-no-relative-import-paths: 1.4.0 eslint-plugin-react: 7.31.10_eslint@8.25.0 husky: 8.0.1 identity-obj-proxy: 3.0.0 @@ -2135,6 +2137,10 @@ packages: eslint: 8.25.0 dev: true + /eslint-plugin-no-relative-import-paths/1.4.0: + resolution: {integrity: sha512-J/ok26KqJM+20VsxNEcHc9kyW0dcFHBlihOO5FFv/GQqwcW+G1UngbHLpnPAdOQ1dJg5Ljk/40csqfZ3mnneUw==} + dev: true + /eslint-plugin-react/7.31.10_eslint@8.25.0: resolution: {integrity: sha512-e4N/nc6AAlg4UKW/mXeYWd3R++qUano5/o+t+wnWxIf+bLsOaH3a4q74kX3nDjYym3VBN4HyO9nEn1GcAqgQOA==} engines: {node: '>=4'} diff --git a/coral/src/main.tsx b/coral/src/main.tsx index e9e17d0e29..0ebc3bb80c 100644 --- a/coral/src/main.tsx +++ b/coral/src/main.tsx @@ -1,7 +1,7 @@ import React from "react"; import ReactDOM from "react-dom/client"; import { RouterProvider } from "react-router-dom"; -import router from "./router"; +import router from "src/router"; import "@aivenio/design-system/dist/styles.css"; diff --git a/coral/src/pages/hello/index.test.tsx b/coral/src/pages/hello/index.test.tsx index cd395dc5ae..acebab5464 100644 --- a/coral/src/pages/hello/index.test.tsx +++ b/coral/src/pages/hello/index.test.tsx @@ -1,4 +1,4 @@ -import HelloPage from "./index"; +import HelloPage from "src/pages/hello"; import { render, cleanup, screen } from "@testing-library/react"; describe("HelloPage", () => { diff --git a/coral/src/pages/index.test.tsx b/coral/src/pages/index.test.tsx index d5f03d5b18..022549f61f 100644 --- a/coral/src/pages/index.test.tsx +++ b/coral/src/pages/index.test.tsx @@ -1,4 +1,4 @@ -import HomePage from "./index"; +import HomePage from "src/pages"; import { render, cleanup, screen } from "@testing-library/react"; describe("HomePage", () => { diff --git a/coral/src/router.tsx b/coral/src/router.tsx index 998a501d38..9adeb744d3 100644 --- a/coral/src/router.tsx +++ b/coral/src/router.tsx @@ -1,6 +1,6 @@ import { createBrowserRouter, Navigate, RouteObject } from "react-router-dom"; -import HomePage from "./pages/index"; -import HelloPage from "./pages/hello"; +import HomePage from "src/pages"; +import HelloPage from "src/pages/hello"; const routes: Array = [ { diff --git a/coral/tsconfig.json b/coral/tsconfig.json index 3d0a51a86e..30aea56764 100644 --- a/coral/tsconfig.json +++ b/coral/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": ".", "target": "ESNext", "useDefineForClassFields": true, "lib": ["DOM", "DOM.Iterable", "ESNext"], diff --git a/coral/vite.config.ts b/coral/vite.config.ts index 86302e5cc6..504312d7e8 100644 --- a/coral/vite.config.ts +++ b/coral/vite.config.ts @@ -1,5 +1,6 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; +import { resolve } from "path"; // https://vitejs.dev/config/ export default defineConfig({ @@ -16,4 +17,9 @@ export default defineConfig({ EXAMPLE: "", }, }, + resolve: { + alias: { + src: resolve(resolve(__dirname), "./src"), + }, + }, });