Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
156 lines (153 loc) · 4.07 KB
/
Copy patheslint.config.js
File metadata and controls
156 lines (153 loc) · 4.07 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import js from "@eslint/js";
import tseslint from "typescript-eslint";
import prettier from "eslint-config-prettier";
// Dependency rule: which internal packages each package may import.
const ALLOWED = {
core: [],
kit: ["core"],
// mock-lmstudio is imported by llm tests only (the client is tested against the fake server).
llm: ["core", "kit", "mock-lmstudio"],
mcp: ["core", "kit"],
"mock-lmstudio": [],
evals: ["core", "kit", "llm", "mock-lmstudio"],
};
const ALL = Object.keys(ALLOWED);
const dependencyRules = ALL.map((pkg) => {
const forbidden = ALL.filter((p) => p !== pkg && !ALLOWED[pkg].includes(p));
return {
files: [`packages/${pkg}/**/*.{ts,tsx}`],
rules: {
"no-restricted-imports": [
"error",
{
patterns: forbidden.map((p) => ({
group: [`@lucid/${p}`, `@lucid/${p}/*`],
message: `packages/${pkg} must not import @lucid/${p}.`,
})),
},
],
},
};
});
export default tseslint.config(
{
ignores: [
"**/dist/**",
"**/out/**",
"**/node_modules/**",
"**/coverage/**",
"**/release/**",
"_site/**",
"site/**/*.d.ts",
],
},
js.configs.recommended,
...tseslint.configs.strictTypeChecked.map((c) => ({ ...c, files: ["**/*.{ts,tsx}"] })),
// Build scripts run in Node.
{
files: ["**/*.mjs"],
languageOptions: {
globals: {
URL: "readonly",
process: "readonly",
console: "readonly",
fetch: "readonly",
Buffer: "readonly",
},
},
},
// The GitHub Pages site's script runs in the browser.
{
files: ["site/**/*.js"],
languageOptions: {
sourceType: "module",
globals: {
window: "readonly",
document: "readonly",
localStorage: "readonly",
sessionStorage: "readonly",
navigator: "readonly",
fetch: "readonly",
setTimeout: "readonly",
Number: "readonly",
Object: "readonly",
IntersectionObserver: "readonly",
Date: "readonly",
JSON: "readonly",
Promise: "readonly",
Error: "readonly",
String: "readonly",
Math: "readonly",
isNaN: "readonly",
},
},
},
// electron-builder hooks are CommonJS.
{
files: ["**/*.cjs"],
languageOptions: {
sourceType: "commonjs",
globals: {
require: "readonly",
exports: "writable",
process: "readonly",
console: "readonly",
},
},
},
{
files: ["**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
projectService: { allowDefaultProject: ["*.config.ts"] },
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ["**/*.{ts,tsx}"],
rules: {
// `const { seq: _seq, ...rest } = edge` is the idiomatic way to omit a property.
"@typescript-eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }],
// Numbers and booleans in template strings are fine and common in logs and reports.
"@typescript-eslint/restrict-template-expressions": [
"error",
{ allowNumber: true, allowBoolean: true },
],
},
},
// packages/core is pure: no DOM, Electron or network, on top of the dependency rule.
{
files: ["packages/core/**/*.ts"],
rules: {
"no-restricted-globals": ["error", "window", "document", "fetch", "localStorage"],
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["@lucid/*"],
message: "packages/core must not import other @lucid packages.",
},
{
group: [
"electron",
"fs",
"http",
"https",
"net",
"node:fs",
"node:http",
"node:https",
"node:net",
],
message: "packages/core must stay pure (no I/O).",
},
],
},
],
},
},
...dependencyRules.filter((r) => !r.files[0].startsWith("packages/core/")),
prettier,
);