diff --git a/rules/public-api/index.js b/rules/public-api/index.js index c459c55..a82fabd 100644 --- a/rules/public-api/index.js +++ b/rules/public-api/index.js @@ -32,14 +32,14 @@ module.exports = { * @example * 'shared/ui/button' // Pass */ - `**/shared/*(${FS_SEGMENTS_REG})/!(${FS_SEGMENTS_REG})`, + `**/*shared/*(${FS_SEGMENTS_REG})/!(${FS_SEGMENTS_REG})`, /** * Allow import from segments in shared * @example * 'shared/ui' // Pass */ - `**/shared/*(${FS_SEGMENTS_REG})`, + `**/*shared/*(${FS_SEGMENTS_REG})`, /** allow global modules */ `**/node_modules/**` diff --git a/rules/public-api/index.test.js b/rules/public-api/index.test.js index c74dfba..e0d6c96 100644 --- a/rules/public-api/index.test.js +++ b/rules/public-api/index.test.js @@ -19,8 +19,8 @@ describe("PublicAPI import boundaries:", () => { import { Button } from "shared/ui/button/button"; import { saveOrder } from "entities/order/model/actions"; import { orderModel } from "entities/order/model"; - import { TicketCard } from "@app/entities/ticket/ui"; - import { Ticket } from "@app/entities/ticket/ui.tsx"; + import { TicketCard } from "@src/entities/ticket/ui"; + import { Ticket } from "@src/entities/ticket/ui.tsx"; `, { filePath: "src/app/ui/index.js" }); assert.strictEqual(report[0].errorCount, 8); @@ -29,13 +29,13 @@ describe("PublicAPI import boundaries:", () => { it("Should lint PublicAPI boundaries without errors.", async () => { const report = await eslint.lintText(` import { Issues } from "pages/issues"; - import { GoodIssues } from "@app/pages/issues"; + import { GoodIssues } from "@src/pages/issues"; import { IssueDetails } from "widgets/issue-details"; import { AuthForm } from "features/auth-form"; import { Button } from "shared/ui/button"; import { orderModel } from "entities/order"; import { TicketCard } from "@/entities/ticket"; - import { FixButton } from "@app/shared/ui/fix-button"; + import { FixButton } from "@src/shared/ui/fix-button"; `, { filePath: "src/app/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); @@ -52,19 +52,19 @@ describe("PublicAPI import boundaries:", () => { describe("Allow not segments import from slices:", () => { it("should lint without errors", async () => { const report = await eslint.lintText(` - import { AuthForm } from "entities/auth"; - import { model } from "../model"; - import { styles } from "./styles.module.scss"; - `, { filePath: "src/features/form/ui/index.js" }); + import { AuthForm } from "entities/auth"; + import { model } from "../model"; + import { styles } from "./styles.module.scss"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); it("should lint with errors", async () => { const report = await eslint.lintText(` - import { AuthForm } from "entities/auth/ui"; - import { Button } from "shared/button"; - `, { filePath: "src/features/form/ui/index.js" }); + import { AuthForm } from "entities/auth/ui"; + import { Button } from "shared/button"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 2); }); @@ -73,17 +73,17 @@ describe("PublicAPI import boundaries:", () => { describe("Allow slices with structure grouping:", () => { it("should lint with errors", async () => { const report = await eslint.lintText(` - import { AuthForm } from "entities/auth/form"; - `, { filePath: "src/features/form/ui/index.js" }); + import { AuthForm } from "entities/auth/form"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); it("should lint without errors", async () => { const report = await eslint.lintText(` - import { AuthForm } from "entities/auth/ui"; - import { Form } from "shared/button/form"; - `, { filePath: "src/features/form/ui/index.js" }); + import { AuthForm } from "entities/auth/ui"; + import { Form } from "shared/button/form"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 2); }); @@ -92,32 +92,43 @@ describe("PublicAPI import boundaries:", () => { describe("Allow not segments import in shared segments:", () => { it("should lint without errors", async () => { const report = await eslint.lintText(` - import { Form } from "shared/ui/form"; - import { AuthAPI } from "shared/api/auth"; - import { useGeo } from "shared/lib/hooks"; - import { styles } from "shared/ui/styles"; - import { CONNECT_ATTEMPTS } from "shared/config"; - `, { filePath: "src/features/form/ui/index.js" }); + import { Form } from "shared/ui/form"; + import { AuthAPI } from "shared/api/auth"; + import { useGeo } from "shared/lib/hooks"; + import { styles } from "shared/ui/styles"; + import { CONNECT_ATTEMPTS } from "shared/config"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); it("should lint with errors", async () => { const report = await eslint.lintText(` - import { Hex } from "shared/api/ui"; - import { Form } from "shared/ui/lib"; - import { AuthForm } from "shared/api/ui"; - import { model } from "shared/ui/model"; - `, { filePath: "src/features/form/ui/index.js" }); + import { Hex } from "shared/api/ui"; + import { Form } from "shared/ui/lib"; + import { AuthForm } from "shared/api/ui"; + import { model } from "shared/ui/model"; + `, { filePath: "src/features/form/ui/index.js" }); assert.strictEqual(report[0].errorCount, 4); }); it("should lint without errors", async () => { const report = await eslint.lintText(` - import { FancyLabel } from "../../label"; - import { model } from "../model"; - `, { filePath: "src/shared/ui/button/index.js" }); + import { FancyLabel } from "../../label"; + import { model } from "../model"; + `, { filePath: "src/shared/ui/button/index.js" }); + + assert.strictEqual(report[0].errorCount, 0); + }); + + it("should lint aliases without errors", async () => { + const report = await eslint.lintText(` + import { routeNames } from '@/entities/one'; + import { fetchRules } from '@entities/two'; + import { Three } from '@features/three'; + import { Four } from '@/features/four'; + `, { filePath: "src/pages/main/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); @@ -126,24 +137,33 @@ describe("PublicAPI import boundaries:", () => { describe("Import from segments in shared:", () => { it("should lint without errors", async () => { const report = await eslint.lintText(` - import { AuthAPI } from "shared/api"; - import { FancyLabel } from 'shared/ui'; - import { convertToken } from 'shared/lib'; - import { CONNECT_ATTEMPTS } from "shared/config"; - `, { filePath: "src/pages/main/ui/index.js" }); + import { AuthAPI } from "shared/api"; + import { FancyLabel } from 'shared/ui'; + import { convertToken } from 'shared/lib'; + import { CONNECT_ATTEMPTS } from "shared/config"; + `, { filePath: "src/pages/main/ui/index.js" }); assert.strictEqual(report[0].errorCount, 0); }); it("should lint with errors", async () => { const report = await eslint.lintText(` - import { AuthAPI } from "shared/auth"; - import { FancyLabel } from 'shared/label'; - import { convertToken } from 'shared/token'; - import { CONNECT_ATTEMPTS } from "shared/const"; - `, { filePath: "src/pages/main/ui/index.js" }); + import { AuthAPI } from "shared/auth"; + import { FancyLabel } from 'shared/label'; + import { convertToken } from 'shared/token'; + import { CONNECT_ATTEMPTS } from "shared/const"; + `, { filePath: "src/pages/main/ui/index.js" }); assert.strictEqual(report[0].errorCount, 4); }); + + it("should lint shared aliases without errors", async () => { + const report = await eslint.lintText(` + import { routeNames } from '@/shared/api/router'; + import { fetchRules } from '@shared/api/rules'; + `, { filePath: "src/pages/main/ui/index.js" }); + + assert.strictEqual(report[0].errorCount, 0); + }); }); });