Skip to content

LINT-35(INTEGRATION): Move rule-configs close to tests #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
"sourceType": "module",
},
extends: [
path.resolve(__dirname, "./public-api-boundaries.js"),
path.resolve(__dirname, "./layers-slices-boundaries.js")
path.resolve(__dirname, "./rules/public-api-boundaries"),
path.resolve(__dirname, "./rules/layers-slices-boundaries")
],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"publish:minor": "npm version minor && npm publish",
"publish:major": "npm version major && npm publish",
"clean": "git clean -fxd",
"test": "mocha test/**.test.js"
"test": "mocha **/**.test.js"
},
"peerDependencies": {
"eslint": ">=6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getLowerLayers, FS_LAYERS } = require("./helpers");
const { getLowerLayers, FS_LAYERS } = require("../../utils/helpers");

const getLayersRules = () =>
FS_LAYERS.map((layer) => ({
Expand Down
19 changes: 19 additions & 0 deletions rules/layers-slices-boundaries/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @feature-sliced/layers-slices-boundaries

Reference: [Cross-communication](https://feature-sliced.design/docs/concepts/cross-communication)

```js
// 👎 Fail
// 🛣 features/auth-form/index.ts
import { getRoute } from "pages/auth";
import { getStore } from "app/store";
import { getAuthCtx } from "features/logout";
import { UserAvatar } from "features/viewer-picker";

// 👍 Pass
// 🛣 features/auth-form/index.ts
import { sessionModel } from "entities/session";
import { Form, Button } from "shared/ui";
import { getAuthCtx } from "entities/session";
import { UserAvatar } from "entities/user";
```
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { ESLint } = require("eslint");
const assert = require("assert");
const { getRandomImportByLayerName } = require("./utils/tools");
const { mockImports } = require("./utils/mock-import");
const cfg = require("..");
const { mockImports } = require("../../utils/mock-import");
const cfg = require("./");

const eslint = new ESLint({
useEslintrc: false,
baseConfig: mockImports(cfg),
});

describe("Import boundaries between slices", () => {
describe("Import boundaries between slices and layers", () => {

it("should lint with cross-import errors between pages.", async () => {
const wrongImports = [
Expand Down Expand Up @@ -75,4 +74,29 @@ describe("Import boundaries between slices", () => {

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

it("should lint with cross-import errors.", async () => {
const wrongImports = [
`import { getRoute } from "pages/auth";`,
`import { getStore } from "app/store";`,
];

const report = await eslint.lintText(wrongImports.join("\n"), {
filePath: "src/shared/lib/index.js",
});
assert.strictEqual(report[0].errorCount, wrongImports.length);
});

it("should lint without errors.", async () => {
const validCodeSnippet = [
`import { sessionModel } from "entities/session";`,
`import { Form, Button } from "shared/ui";`,
].join("\n");

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

});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getUpperLayers, FS_SEGMENTS, FS_LAYERS } = require("./helpers");
const { getUpperLayers, FS_SEGMENTS, FS_LAYERS } = require("../../utils/helpers");

const FS_SEGMENTS_REG = FS_SEGMENTS.join("|");
const FS_LAYERS_REG = FS_LAYERS.join("|");
Expand Down
24 changes: 24 additions & 0 deletions rules/public-api-boundaries/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @feature-sliced/public-api-boundaries

Reference: [PublicAPI](https://feature-sliced.design/docs/concepts/public-api)

```js
// 👎 Fail
import { Issues } from "pages/issues/ui";
import { IssueDetails } from "widgets/issue-details/ui/details"
import { AuthForm } from "features/auth-form/ui/form"
import { Button } from "shared/ui/button/button";
import { saveOrder } from "entities/order/model/actions";
import { orderModel } from "entities/order/model";
import { TicketCard } from "@/entities/ticket/ui";

// 👍 Pass
import { Issues } from "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 { AuthForm } from "features/auth/form"
import { Button } from "shared/ui";
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ESLint } = require("eslint");
const assert = require("assert");
const { mockImports } = require("./utils/mock-import");
const cfg = require("../public-api-boundaries");
const { mockImports } = require("../../utils/mock-import");
const cfg = require("./");

const eslint = new ESLint({
useEslintrc: false,
Expand Down
38 changes: 0 additions & 38 deletions test/layers-boundaries.test.js

This file was deleted.

File renamed without changes.
File renamed without changes.