From f5d6038ed4b592427e88e0f0aa2e3e78cb430583 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Mon, 31 Jan 2022 22:09:12 +0300 Subject: [PATCH 1/2] fix(alias): import order ~ and @ alias support --- rules/import-order/index.js | 2 +- rules/import-order/index.test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rules/import-order/index.js b/rules/import-order/index.js index 8601d9d..9fab896 100644 --- a/rules/import-order/index.js +++ b/rules/import-order/index.js @@ -10,7 +10,7 @@ module.exports = { { pathGroups: layersLib.FS_LAYERS.map( (layer) => ({ - pattern: `**/${layer}/**` , + pattern: `**/?(@|~)${layer}/**` , group: "internal", position: "after", }), diff --git a/rules/import-order/index.test.js b/rules/import-order/index.test.js index b431824..5e4a04a 100644 --- a/rules/import-order/index.test.js +++ b/rules/import-order/index.test.js @@ -43,4 +43,24 @@ describe("Import order:", () => { assert.strictEqual(report[0].errorCount, 0); }); + + it("aliased layers should lint with errors.", async () => { + const report = await eslint.lintText(` + import { Third } from '@shared/third'; + import { Second } from '@entities/second'; + import { First } from '@features/first'; + `); + + assert.strictEqual(report[0].errorCount, 2); + }); + + it("aliased layers should lint without errors.", async () => { + const report = await eslint.lintText(` + import { First } from '@features/first'; + import { Second } from '@entities/second'; + import { Third } from '@shared/third'; + `); + + assert.strictEqual(report[0].errorCount, 0); + }); }); From 9c00ebf1198751d7f6f9bea45a767383d4c947b8 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Mon, 31 Jan 2022 23:26:38 +0300 Subject: [PATCH 2/2] fix(alias): support of all aliases --- rules/import-order/index.js | 2 +- rules/import-order/index.test.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rules/import-order/index.js b/rules/import-order/index.js index 9fab896..534f647 100644 --- a/rules/import-order/index.js +++ b/rules/import-order/index.js @@ -10,7 +10,7 @@ module.exports = { { pathGroups: layersLib.FS_LAYERS.map( (layer) => ({ - pattern: `**/?(@|~)${layer}/**` , + pattern: `**/?(*)${layer}/**` , group: "internal", position: "after", }), diff --git a/rules/import-order/index.test.js b/rules/import-order/index.test.js index 5e4a04a..1336fdd 100644 --- a/rules/import-order/index.test.js +++ b/rules/import-order/index.test.js @@ -22,17 +22,22 @@ describe("Import order:", () => { import { LoginForm } from "features/login-form"; // 4 import { Header } from "widgets/header"; // 5 import { debounce } from "shared/lib/fp"; + import { One } from "@entities/one"; + import { Two } from "~entities/two"; `); - assert.strictEqual(report[0].errorCount, 7); + assert.strictEqual(report[0].errorCount, 8); }); it("should lint without errors.", async () => { const report = await eslint.lintText(` import axios from "axios"; // 1) external libs + import { Zero } from "@widget/zero"; // Layers: widget - Alias import { Header } from "widgets/header"; // 2.1) Layers: widgets import { LoginForm } from "features/login-form"; // 2.2) Layers: features import { authModel } from "entities/auth"; // 2.3) Layers: entities + import { One } from "@entities/one"; // Layers: entities - Alias + import { Two } from "@entities/two"; // Layers: entities - Alias import { Cart } from "@/entities/cart"; // Layers: entities - Alias import { Input } from "~/shared/ui"; // Layers: shared - Alias import { Button } from "shared/ui"; // 2.4) Layers: shared