From 34217c639f28662300082435e05b2dbf1c3562b2 Mon Sep 17 00:00:00 2001 From: Dmitriy Bratchikov Date: Mon, 27 May 2024 14:37:25 +0700 Subject: [PATCH] feature: add FSD eslint config --- .eslintrc.cjs | 196 +++++++++++++++++++++++++++++++++++++++++++++++++ .eslintrc.json | 3 - 2 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 .eslintrc.cjs delete mode 100644 .eslintrc.json diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..9a53b97 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,196 @@ +module.exports = { + root: true, + env: { browser: true, es2020: true }, + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "next/core-web-vitals", + "plugin:react-hooks/recommended", + ], + ignorePatterns: ["dist", ".eslintrc.cjs"], + parser: "@typescript-eslint/parser", + plugins: ["react-refresh", "boundaries"], + settings: { + "import/resolver": { + typescript: { + alwaysTryTypes: true, + }, + }, + "boundaries/include": ["src/**/*"], + "boundaries/elements": [ + { + type: "app", + pattern: "app", + }, + { + type: "pages", + pattern: "src/pages/*", + capture: ["page"], + }, + { + type: "widgets", + pattern: "widgets/*", + capture: ["widget"], + }, + { + type: "features", + pattern: "features/*", + capture: ["feature"], + }, + { + type: "entities", + pattern: "entities/*", + capture: ["entity"], + }, + { + type: "shared", + pattern: "shared/*", + capture: ["segment"], + }, + ], + }, + rules: { + "react-refresh/only-export-components": 0, + "boundaries/entry-point": [ + 2, + { + default: "disallow", + rules: [ + { + target: [ + [ + "shared", + { + segment: "lib", + }, + ], + ], + allow: "*/index.ts", + }, + { + target: [ + [ + "shared", + { + segment: "lib", + }, + ], + ], + allow: "*.(ts|tsx)", + }, + { + target: [ + [ + "shared", + { + segment: "constants", + }, + ], + ], + allow: "index.ts", + }, + { + target: [ + [ + "shared", + { + segment: "ui", // ("ui"|"constants") + }, + ], + ], + allow: "**", + }, + { + target: ["app", "pages", "widgets", "features", "entities"], + allow: "index.(ts|tsx)", + }, + ], + }, + ], + "boundaries/element-types": [ + 2, + { + default: "allow", + message: "${file.type} is not allowed to import (${dependency.type})", + rules: [ + { + from: ["shared"], + disallow: ["app", "pages", "widgets", "features", "entities"], + message: + "Shared module must not import upper layers (${dependency.type})", + }, + { + from: ["entities"], + message: "Entity must not import upper layers (${dependency.type})", + disallow: ["app", "pages", "widgets", "features"], + }, + { + from: ["entities"], + message: "Entity must not import other entity", + disallow: [ + [ + "entities", + { + entity: "!${entity}", + }, + ], + ], + }, + { + from: ["features"], + message: + "Feature must not import upper layers (${dependency.type})", + disallow: ["app", "pages", "widgets"], + }, + { + from: ["features"], + message: "Feature must not import other feature", + disallow: [ + [ + "features", + { + feature: "!${feature}", + }, + ], + ], + }, + { + from: ["widgets"], + message: + "Feature must not import upper layers (${dependency.type})", + disallow: ["app", "pages"], + }, + { + from: ["widgets"], + message: "Widget must not import other widget", + disallow: [ + [ + "widgets", + { + widget: "!${widget}", + }, + ], + ], + }, + { + from: ["pages"], + message: "Page must not import upper layers (${dependency.type})", + disallow: ["app"], + }, + { + from: ["pages"], + message: "Page must not import other page", + disallow: [ + [ + "pages", + { + page: "!${page}", + }, + ], + ], + }, + ], + }, + ], + }, +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 287ba35..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["next/core-web-vitals", "plugin:react-hooks/recommended"] -}