Skip to content

Commit

Permalink
Merge pull request #40 from feature-sliced/refactor/LINT-35-move-rule…
Browse files Browse the repository at this point in the history
…-config

LINT-35(INTEGRATION):  Move rule-configs close to tests
  • Loading branch information
Krakazybik authored Dec 11, 2021
2 parents ef9589d + 7d51a70 commit 54604ae
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 21 deletions.
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) => ({
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";
```
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.
File renamed without changes.

0 comments on commit 54604ae

Please sign in to comment.