Files
lincodex/frontend/eslint.config.mjs
T
2026-10-05 14:23:31 +03:00

111 lines
3.3 KiB
JavaScript

import js from "@eslint/js";
import boundaries from "eslint-plugin-boundaries";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
const layerNames = ["app", "pages", "widgets", "features", "entities", "shared"];
const upwardPolicies = layerNames.flatMap((layer, index) => {
const higherLayers = layerNames.slice(0, index);
return higherLayers.length > 0
? [
{
from: { element: { type: layer } },
disallow: { to: { element: { type: higherLayers } } },
},
]
: [];
});
const sliceLayers = ["pages", "widgets", "features", "entities"];
const peerSlicePolicies = sliceLayers.flatMap((layer) => [
{
from: { element: { type: layer } },
disallow: { to: { element: { type: layer } } },
},
{
from: { element: { type: layer } },
allow: {
to: {
element: {
type: layer,
captured: { slice: "{{from.element.captured.slice}}" },
},
},
},
},
]);
const publicEntryPolicies = layerNames.flatMap((sourceLayer, sourceIndex) =>
sliceLayers
.filter((targetLayer) => layerNames.indexOf(targetLayer) > sourceIndex)
.flatMap((targetLayer) => [
{
from: { element: { type: sourceLayer } },
disallow: { to: { element: { type: targetLayer } } },
},
{
from: { element: { type: sourceLayer } },
allow: {
to: { element: { type: targetLayer, fileInternalPath: "index.ts" } },
},
},
]),
);
export default tseslint.config(
{
ignores: ["dist/**", "coverage/**", "src/shared/api/endpoints/**", "src/shared/api/schemas/**"],
},
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
plugins: {
boundaries,
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
settings: {
"boundaries/root-path": ".",
"import/resolver": {
node: { extensions: [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx"] },
},
"boundaries/elements": [
{ type: "app", pattern: "src/app", partialMatch: false },
{ type: "pages", pattern: "src/pages/*", partialMatch: false, capture: ["slice"] },
{ type: "widgets", pattern: "src/widgets/*", partialMatch: false, capture: ["slice"] },
{
type: "features",
pattern: ["src/features/*", "scripts/fixtures/src/features/*"],
partialMatch: false,
capture: ["slice"],
},
{ type: "entities", pattern: "src/entities/*", partialMatch: false, capture: ["slice"] },
{ type: "shared", pattern: "src/shared", partialMatch: false },
],
},
rules: {
...reactHooks.configs.flat.recommended.rules,
"no-console": ["error", { allow: ["warn", "error"] }],
"no-debugger": "error",
"react-refresh/only-export-components": ["error", { allowConstantExport: true }],
"boundaries/dependencies": [
"error",
{
default: "allow",
policies: [...upwardPolicies, ...peerSlicePolicies, ...publicEntryPolicies],
},
],
},
},
{
files: ["src/**/*.{ts,tsx}"],
plugins: { boundaries },
rules: { "boundaries/no-unknown-files": "error" },
},
);