Skip to content

Commit

Permalink
Merge pull request #77 from feature-sliced/bugfix/LINT-75-wrong-share…
Browse files Browse the repository at this point in the history
…d-alias

LINT-75(feedback): No support alias in shared layer for PublicAPI
  • Loading branch information
azinit authored Jan 31, 2022
2 parents fe100c7 + 0bf954f commit 540e7cf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 42 deletions.
4 changes: 2 additions & 2 deletions rules/public-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**`
Expand Down
100 changes: 60 additions & 40 deletions rules/public-api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
});
});

0 comments on commit 540e7cf

Please sign in to comment.