-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patheslint.config.ts
More file actions
99 lines (94 loc) · 3.14 KB
/
Copy patheslint.config.ts
File metadata and controls
99 lines (94 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import js from "@eslint/js";
import type { ESLint } from "eslint";
import pluginReact from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import { defineConfig } from "eslint/config";
import globals from "globals";
import tseslint from "typescript-eslint";
/**
* Architecture boundaries (docs/architecture.md, "Dependency direction").
* Every cross-boundary import uses the `@/` alias, so the graph is enforced
* with import-specifier patterns — no resolver needed. Patterns use gitignore
* semantics: exclusions are directory-level (`@/features/*`) so that `!`
* negations can re-allow whole feature folders; `@/entrypoints/*` is
* forbidden everywhere outside entrypoints.
*/
type RestrictedImportsRule = [
"error",
{ patterns: { group: string[]; message: string }[] },
];
const boundary = (files: string[], forbidden: string[]) => ({
files,
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: forbidden,
message:
"Import crosses an architecture boundary — see docs/architecture.md (Dependency direction).",
},
],
},
] satisfies RestrictedImportsRule as RestrictedImportsRule,
},
});
const featureBoundary = (
own: string,
allowedFeatures: string[],
extraForbidden: string[] = [],
) =>
boundary(
[`features/${own}/**`],
[
"@/features/*",
`!@/features/${own}`,
...allowedFeatures.map((feature) => `!@/features/${feature}`),
"@/entrypoints/*",
...extraForbidden,
],
);
const architectureBoundaries = [
boundary(
["domain/**"],
["@/features/*", "@/components/*", "@/lib/*", "@/entrypoints/*"],
),
boundary(["lib/**"], ["@/features/*", "@/components/*", "@/entrypoints/*"]),
boundary(["components/**"], ["@/features/*", "@/entrypoints/*"]),
featureBoundary("catalog", [], ["@/components/*"]),
featureBoundary("session", [], ["@/components/*"]),
featureBoundary("preferences", []),
featureBoundary("audit", ["preferences"]),
featureBoundary("course-search", ["catalog", "audit"]),
featureBoundary("dashboard", ["audit", "course-search", "preferences"]),
featureBoundary("planner", ["audit", "course-search", "dashboard"]),
featureBoundary("audit-scraping", ["audit", "session"], ["@/components/*"]),
featureBoundary("popup", ["audit", "session"]),
featureBoundary("banner", ["audit", "session"]),
];
export default defineConfig([
{ ignores: [".output/**", ".wxt/**"] },
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
plugins: { js },
extends: ["js/recommended"],
languageOptions: { globals: globals.browser },
},
tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
{
plugins: { "react-hooks": reactHooks as unknown as ESLint.Plugin },
rules: {
"react/react-in-jsx-scope": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/no-explicit-any": "warn",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
},
},
...architectureBoundaries,
]);