Skip to content

Commit b883dfe

Browse files
committed
fix: add app layer rule
1 parent 03091f4 commit b883dfe

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

rules/layers-slices/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ const getNotSharedLayersRules = () =>
66
allow: layersLib.getLowerLayers(layer),
77
}));
88

9-
const sharedLayerRule = {
10-
from: "shared",
11-
allow: "shared",
12-
};
9+
const slicelessLayerRules = [
10+
{
11+
from: "shared",
12+
allow: "shared",
13+
},
14+
{
15+
from: "app",
16+
allow: "app",
17+
}
18+
];
1319

1420
const getLayersBoundariesElements = () =>
1521
layersLib.FS_LAYERS.map((layer) => ({
@@ -46,7 +52,7 @@ module.exports = {
4652
{
4753
"default": "disallow",
4854
"message": "\"${file.type}\" is not allowed to import \"${dependency.type}\" | See rules: https://feature-sliced.design/docs/reference/layers/overview ",
49-
"rules": [...getNotSharedLayersRules(), sharedLayerRule, ...getGodModeRules()],
55+
"rules": [...getNotSharedLayersRules(), ...slicelessLayerRules, ...getGodModeRules()],
5056
},
5157
],
5258
},

rules/layers-slices/layers.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,26 @@ describe("Import boundaries between layers", () => {
102102
assert.strictEqual(report[0].errorCount, 0);
103103
});
104104

105+
it("should lint without errors when import from app.", async () => {
106+
const validCodeSnippet = [
107+
`import "app/styles/styles.css"`,
108+
`import { withProviders } from "app/providers"`,
109+
].join("\n");
110+
111+
const report = await eslint.lintText(validCodeSnippet, {
112+
filePath: "src/app/ui/app.tsx",
113+
});
114+
assert.strictEqual(report[0].errorCount, 0);
115+
});
116+
117+
it("should lint with errors when import from app.", async () => {
118+
const wrongImports = [
119+
`import { withProviders } from "app/providers"`,
120+
];
121+
122+
const report = await eslint.lintText(wrongImports.join("\n"), {
123+
filePath: "src/features/add-user/model.tsx",
124+
});
125+
assert.strictEqual(report[0].errorCount, wrongImports.length);
126+
});
105127
});

0 commit comments

Comments
 (0)