Skip to content

Commit

Permalink
Merge pull request #109 from rokashkovvd/master
Browse files Browse the repository at this point in the history
fix: add app layer rule
  • Loading branch information
illright authored Apr 30, 2024
2 parents 03091f4 + b883dfe commit fa3ad76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rules/layers-slices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ const getNotSharedLayersRules = () =>
allow: layersLib.getLowerLayers(layer),
}));

const sharedLayerRule = {
from: "shared",
allow: "shared",
};
const slicelessLayerRules = [
{
from: "shared",
allow: "shared",
},
{
from: "app",
allow: "app",
}
];

const getLayersBoundariesElements = () =>
layersLib.FS_LAYERS.map((layer) => ({
Expand Down Expand Up @@ -46,7 +52,7 @@ module.exports = {
{
"default": "disallow",
"message": "\"${file.type}\" is not allowed to import \"${dependency.type}\" | See rules: https://feature-sliced.design/docs/reference/layers/overview ",
"rules": [...getNotSharedLayersRules(), sharedLayerRule, ...getGodModeRules()],
"rules": [...getNotSharedLayersRules(), ...slicelessLayerRules, ...getGodModeRules()],
},
],
},
Expand Down
22 changes: 22 additions & 0 deletions rules/layers-slices/layers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,26 @@ describe("Import boundaries between layers", () => {
assert.strictEqual(report[0].errorCount, 0);
});

it("should lint without errors when import from app.", async () => {
const validCodeSnippet = [
`import "app/styles/styles.css"`,
`import { withProviders } from "app/providers"`,
].join("\n");

const report = await eslint.lintText(validCodeSnippet, {
filePath: "src/app/ui/app.tsx",
});
assert.strictEqual(report[0].errorCount, 0);
});

it("should lint with errors when import from app.", async () => {
const wrongImports = [
`import { withProviders } from "app/providers"`,
];

const report = await eslint.lintText(wrongImports.join("\n"), {
filePath: "src/features/add-user/model.tsx",
});
assert.strictEqual(report[0].errorCount, wrongImports.length);
});
});

0 comments on commit fa3ad76

Please sign in to comment.