Skip to content
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

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

Merged
merged 4 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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,13 +1,14 @@
const { getLowerLayers, FS_LAYERS } = require("./helpers");
const { layersLib } = require("../../utils/layers");

const getLayersRules = () =>
FS_LAYERS.map((layer) => ({

layersLib.FS_LAYERS.map((layer) => ({
from: layer,
allow: getLowerLayers(layer),
allow: layersLib.getLowerLayers(layer),
}));

const getLayersBoundariesElements = () =>
FS_LAYERS.map((layer) => ({
layersLib.FS_LAYERS.map((layer) => ({
Comment on lines +1 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: 🔥🔥🔥

type: layer,
pattern: `${layer}/*`,
mode: "folder",
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";
```
azinit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { getUpperLayers, FS_SEGMENTS, FS_LAYERS } = require("./helpers");
const { layersLib } = require("../../utils/layers");

const FS_SEGMENTS_REG = FS_SEGMENTS.join("|");
const FS_LAYERS_REG = FS_LAYERS.join("|");
const FS_SEGMENTS_REG = layersLib.FS_SEGMENTS.join("|");
const FS_LAYERS_REG = layersLib.FS_LAYERS.join("|");

module.exports = {
parserOptions: {
Expand All @@ -19,7 +19,7 @@ module.exports = {
* 'entities/form/ui' // Fail
* 'entities/form' // Pass
*/
`**/*(${getUpperLayers("shared").join("|")})/!(${FS_SEGMENTS_REG})`,
`**/*(${layersLib.getUpperLayers("shared").join("|")})/!(${FS_SEGMENTS_REG})`,

/**
* Allow slices with structure grouping
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
2 changes: 1 addition & 1 deletion test/config.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require("assert");
const cfg = require("../");
const utils = require("./utils/tools");
const utils = require("../utils/tools");

describe("config is valid", () => {
it("parserOptions ~ Record<string, string>", () => {
Expand Down
2 changes: 1 addition & 1 deletion helpers.js → utils/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const FS_SEGMENTS = [
const getLowerLayers = (layer) => FS_LAYERS.slice(FS_LAYERS.indexOf(layer) + 1);
const getUpperLayers = (layer) => FS_LAYERS.slice(0, FS_LAYERS.indexOf(layer));

module.exports = { FS_LAYERS, FS_SEGMENTS, getLowerLayers, getUpperLayers };
module.exports.layersLib = { FS_LAYERS, FS_SEGMENTS, getLowerLayers, getUpperLayers } ;
File renamed without changes.
File renamed without changes.