Skip to content

Commit 540e7cf

Browse files
authored
Merge pull request #77 from feature-sliced/bugfix/LINT-75-wrong-shared-alias
LINT-75(feedback): No support alias in shared layer for PublicAPI
2 parents fe100c7 + 0bf954f commit 540e7cf

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

rules/public-api/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ module.exports = {
3232
* @example
3333
* 'shared/ui/button' // Pass
3434
*/
35-
`**/shared/*(${FS_SEGMENTS_REG})/!(${FS_SEGMENTS_REG})`,
35+
`**/*shared/*(${FS_SEGMENTS_REG})/!(${FS_SEGMENTS_REG})`,
3636

3737
/**
3838
* Allow import from segments in shared
3939
* @example
4040
* 'shared/ui' // Pass
4141
*/
42-
`**/shared/*(${FS_SEGMENTS_REG})`,
42+
`**/*shared/*(${FS_SEGMENTS_REG})`,
4343

4444
/** allow global modules */
4545
`**/node_modules/**`

rules/public-api/index.test.js

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe("PublicAPI import boundaries:", () => {
1919
import { Button } from "shared/ui/button/button";
2020
import { saveOrder } from "entities/order/model/actions";
2121
import { orderModel } from "entities/order/model";
22-
import { TicketCard } from "@app/entities/ticket/ui";
23-
import { Ticket } from "@app/entities/ticket/ui.tsx";
22+
import { TicketCard } from "@src/entities/ticket/ui";
23+
import { Ticket } from "@src/entities/ticket/ui.tsx";
2424
`,
2525
{ filePath: "src/app/ui/index.js" });
2626
assert.strictEqual(report[0].errorCount, 8);
@@ -29,13 +29,13 @@ describe("PublicAPI import boundaries:", () => {
2929
it("Should lint PublicAPI boundaries without errors.", async () => {
3030
const report = await eslint.lintText(`
3131
import { Issues } from "pages/issues";
32-
import { GoodIssues } from "@app/pages/issues";
32+
import { GoodIssues } from "@src/pages/issues";
3333
import { IssueDetails } from "widgets/issue-details";
3434
import { AuthForm } from "features/auth-form";
3535
import { Button } from "shared/ui/button";
3636
import { orderModel } from "entities/order";
3737
import { TicketCard } from "@/entities/ticket";
38-
import { FixButton } from "@app/shared/ui/fix-button";
38+
import { FixButton } from "@src/shared/ui/fix-button";
3939
`, { filePath: "src/app/ui/index.js" });
4040
assert.strictEqual(report[0].errorCount, 0);
4141
});
@@ -52,19 +52,19 @@ describe("PublicAPI import boundaries:", () => {
5252
describe("Allow not segments import from slices:", () => {
5353
it("should lint without errors", async () => {
5454
const report = await eslint.lintText(`
55-
import { AuthForm } from "entities/auth";
56-
import { model } from "../model";
57-
import { styles } from "./styles.module.scss";
58-
`, { filePath: "src/features/form/ui/index.js" });
55+
import { AuthForm } from "entities/auth";
56+
import { model } from "../model";
57+
import { styles } from "./styles.module.scss";
58+
`, { filePath: "src/features/form/ui/index.js" });
5959

6060
assert.strictEqual(report[0].errorCount, 0);
6161
});
6262

6363
it("should lint with errors", async () => {
6464
const report = await eslint.lintText(`
65-
import { AuthForm } from "entities/auth/ui";
66-
import { Button } from "shared/button";
67-
`, { filePath: "src/features/form/ui/index.js" });
65+
import { AuthForm } from "entities/auth/ui";
66+
import { Button } from "shared/button";
67+
`, { filePath: "src/features/form/ui/index.js" });
6868

6969
assert.strictEqual(report[0].errorCount, 2);
7070
});
@@ -73,17 +73,17 @@ describe("PublicAPI import boundaries:", () => {
7373
describe("Allow slices with structure grouping:", () => {
7474
it("should lint with errors", async () => {
7575
const report = await eslint.lintText(`
76-
import { AuthForm } from "entities/auth/form";
77-
`, { filePath: "src/features/form/ui/index.js" });
76+
import { AuthForm } from "entities/auth/form";
77+
`, { filePath: "src/features/form/ui/index.js" });
7878

7979
assert.strictEqual(report[0].errorCount, 0);
8080
});
8181

8282
it("should lint without errors", async () => {
8383
const report = await eslint.lintText(`
84-
import { AuthForm } from "entities/auth/ui";
85-
import { Form } from "shared/button/form";
86-
`, { filePath: "src/features/form/ui/index.js" });
84+
import { AuthForm } from "entities/auth/ui";
85+
import { Form } from "shared/button/form";
86+
`, { filePath: "src/features/form/ui/index.js" });
8787

8888
assert.strictEqual(report[0].errorCount, 2);
8989
});
@@ -92,32 +92,43 @@ describe("PublicAPI import boundaries:", () => {
9292
describe("Allow not segments import in shared segments:", () => {
9393
it("should lint without errors", async () => {
9494
const report = await eslint.lintText(`
95-
import { Form } from "shared/ui/form";
96-
import { AuthAPI } from "shared/api/auth";
97-
import { useGeo } from "shared/lib/hooks";
98-
import { styles } from "shared/ui/styles";
99-
import { CONNECT_ATTEMPTS } from "shared/config";
100-
`, { filePath: "src/features/form/ui/index.js" });
95+
import { Form } from "shared/ui/form";
96+
import { AuthAPI } from "shared/api/auth";
97+
import { useGeo } from "shared/lib/hooks";
98+
import { styles } from "shared/ui/styles";
99+
import { CONNECT_ATTEMPTS } from "shared/config";
100+
`, { filePath: "src/features/form/ui/index.js" });
101101

102102
assert.strictEqual(report[0].errorCount, 0);
103103
});
104104

105105
it("should lint with errors", async () => {
106106
const report = await eslint.lintText(`
107-
import { Hex } from "shared/api/ui";
108-
import { Form } from "shared/ui/lib";
109-
import { AuthForm } from "shared/api/ui";
110-
import { model } from "shared/ui/model";
111-
`, { filePath: "src/features/form/ui/index.js" });
107+
import { Hex } from "shared/api/ui";
108+
import { Form } from "shared/ui/lib";
109+
import { AuthForm } from "shared/api/ui";
110+
import { model } from "shared/ui/model";
111+
`, { filePath: "src/features/form/ui/index.js" });
112112

113113
assert.strictEqual(report[0].errorCount, 4);
114114
});
115115

116116
it("should lint without errors", async () => {
117117
const report = await eslint.lintText(`
118-
import { FancyLabel } from "../../label";
119-
import { model } from "../model";
120-
`, { filePath: "src/shared/ui/button/index.js" });
118+
import { FancyLabel } from "../../label";
119+
import { model } from "../model";
120+
`, { filePath: "src/shared/ui/button/index.js" });
121+
122+
assert.strictEqual(report[0].errorCount, 0);
123+
});
124+
125+
it("should lint aliases without errors", async () => {
126+
const report = await eslint.lintText(`
127+
import { routeNames } from '@/entities/one';
128+
import { fetchRules } from '@entities/two';
129+
import { Three } from '@features/three';
130+
import { Four } from '@/features/four';
131+
`, { filePath: "src/pages/main/ui/index.js" });
121132

122133
assert.strictEqual(report[0].errorCount, 0);
123134
});
@@ -126,24 +137,33 @@ describe("PublicAPI import boundaries:", () => {
126137
describe("Import from segments in shared:", () => {
127138
it("should lint without errors", async () => {
128139
const report = await eslint.lintText(`
129-
import { AuthAPI } from "shared/api";
130-
import { FancyLabel } from 'shared/ui';
131-
import { convertToken } from 'shared/lib';
132-
import { CONNECT_ATTEMPTS } from "shared/config";
133-
`, { filePath: "src/pages/main/ui/index.js" });
140+
import { AuthAPI } from "shared/api";
141+
import { FancyLabel } from 'shared/ui';
142+
import { convertToken } from 'shared/lib';
143+
import { CONNECT_ATTEMPTS } from "shared/config";
144+
`, { filePath: "src/pages/main/ui/index.js" });
134145

135146
assert.strictEqual(report[0].errorCount, 0);
136147
});
137148

138149
it("should lint with errors", async () => {
139150
const report = await eslint.lintText(`
140-
import { AuthAPI } from "shared/auth";
141-
import { FancyLabel } from 'shared/label';
142-
import { convertToken } from 'shared/token';
143-
import { CONNECT_ATTEMPTS } from "shared/const";
144-
`, { filePath: "src/pages/main/ui/index.js" });
151+
import { AuthAPI } from "shared/auth";
152+
import { FancyLabel } from 'shared/label';
153+
import { convertToken } from 'shared/token';
154+
import { CONNECT_ATTEMPTS } from "shared/const";
155+
`, { filePath: "src/pages/main/ui/index.js" });
145156

146157
assert.strictEqual(report[0].errorCount, 4);
147158
});
159+
160+
it("should lint shared aliases without errors", async () => {
161+
const report = await eslint.lintText(`
162+
import { routeNames } from '@/shared/api/router';
163+
import { fetchRules } from '@shared/api/rules';
164+
`, { filePath: "src/pages/main/ui/index.js" });
165+
166+
assert.strictEqual(report[0].errorCount, 0);
167+
});
148168
});
149169
});

0 commit comments

Comments
 (0)