Skip to content

Commit

Permalink
Merge pull request #81 from feature-sliced/bugfix/LINT-75-wrong-impor…
Browse files Browse the repository at this point in the history
…t-order-for-aliases

LINT-75(feedback): Wrong import order for aliased layers
  • Loading branch information
azinit authored Jan 31, 2022
2 parents 0f08f1c + 9c00ebf commit fe100c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rules/import-order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
{
pathGroups: layersLib.FS_LAYERS.map(
(layer) => ({
pattern: `**/${layer}/**` ,
pattern: `**/?(*)${layer}/**` ,
group: "internal",
position: "after",
}),
Expand Down
27 changes: 26 additions & 1 deletion rules/import-order/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,4 +48,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);
});
});

0 comments on commit fe100c7

Please sign in to comment.