Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
305 lines (296 loc) · 10.1 KB
/
Copy patheslint.config.js
File metadata and controls
305 lines (296 loc) · 10.1 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import js from "@eslint/js";
import pluginQuery from "@tanstack/eslint-plugin-query";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import i18next from "eslint-plugin-i18next";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import globals from "globals";
import tseslint from "typescript-eslint";
/** Output no rule can ask an author to change. */
const GENERATED = ["src/lib/bindings.ts", "src/lib/ipc/**", "src/routeTree.gen.ts"];
/** Every directory under `src/modules`, so each can be told apart from the rest. */
const MODULES = [
"deep-link",
"diagnostics",
"editor",
"gallery",
"home",
"keys",
"launcher",
"library",
"migration",
"patcher",
"settings",
"shell",
"updater",
"workshop",
];
/** English that ships in no release build, so none of it is a message. */
const DEV_ONLY = ["src/**/*.gallery.tsx", "src/modules/gallery/**"];
const NOT_MODULE_SOURCE = ["src/**/*.test.{ts,tsx}", "src/test/**", ...GENERATED];
/* The stock merger reads `text-*` against Tailwind's own sizes alone, so it
files a tier of ours under text colour and drops it when a colour stands
beside it. `@/utils` exports the one that knows them. */
const TAILWIND_MERGE = {
group: ["tailwind-merge"],
message: "Merge classes with `twMerge` from `@/utils`.",
};
/* What every file under `src` is kept away from, whichever module it is in. */
const RESTRICTED = [
{
group: ["@/components/*"],
message: "Import a component through the barrel, `@/components`.",
},
{
group: ["@base-ui/react/*"],
message: "Reach Base UI through its wrapper in `src/components`.",
},
{
group: ["lucide-react"],
message: "Icons are Phosphor duotone: DS-ICON-WEIGHT.",
},
TAILWIND_MERGE,
];
/* What a module draws through a wrapper in `src/components` and never by hand. */
const NATIVE_CONTROLS = [
{
selector: "JSXOpeningElement[name.name='button']",
message: "Draw a press with `Button`, `IconButton` or a pressable `Badge` from `@/components`.",
},
{
/* An `iframe` is named by its `title`, so it keeps one. */
selector:
"JSXOpeningElement[name.type='JSXIdentifier'][name.name=/^(?!iframe$)[a-z]/] > JSXAttribute[name.name='title']",
message: "A DOM `title` never reaches the keyboard. Wrap the element in `Tooltip`.",
},
];
/**
* The barrel rule, as seen from inside `owner`.
*
* Only another module's insides are out of bounds. A module reaching past its
* own barrel is how a file avoids the import cycle the barrel would close, so
* the rule would otherwise argue against the fix for it.
*/
function barrelRule(owner) {
const group = ["@/modules/*/**"];
if (owner) group.push(`!@/modules/${owner}/**`);
return { group, message: "Import another module through its barrel, `@/modules/<name>`." };
}
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["**/*.{ts,tsx}"],
plugins: {
react: reactPlugin,
"react-hooks": reactHooksPlugin,
"simple-import-sort": simpleImportSort,
},
languageOptions: {
globals: {
...globals.browser,
...globals.es2020,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
react: {
version: "detect",
},
},
rules: {
...reactPlugin.configs.recommended.rules,
...reactPlugin.configs["jsx-runtime"].rules,
...reactHooksPlugin.configs.recommended.rules,
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/no-explicit-any": "warn",
"react/prop-types": "off",
/* Import order is oxfmt's `sortImports`, so `pnpm format` fixes it and
`format:check` gates it. Two owners would fight over the same lines. */
"simple-import-sort/exports": "error",
},
},
...pluginQuery.configs["flat/recommended-strict"],
{
/* Cycles are oxlint's job, in `.oxlintrc.json`: the graph walk costs
ESLint more than every other rule here put together. */
files: ["src/**/*.{ts,tsx}"],
ignores: GENERATED,
rules: {
"max-lines": ["warn", { max: 400, skipBlankLines: true, skipComments: true }],
},
},
{
files: ["src/**/*.{ts,tsx}"],
ignores: ["src/**/*.test.{ts,tsx}", "src/test/**", ...DEV_ONLY, ...GENERATED],
plugins: { i18next },
languageOptions: {
parserOptions: {
// Type information lets the rule skip a literal whose type is a string union.
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
"i18next/no-literal-string": [
"warn",
{
mode: "all",
"jsx-attributes": {
exclude: [
// Every class-list prop, such as `className` and `triggerClassName`.
".*[cC]lassName",
"data-ui",
"to",
"href",
"id",
"name",
"type",
"role",
"variant",
"size",
"weight",
"for",
"key",
"src",
"rel",
"target",
// A key combination the Kbd splits on "+", not a sentence.
"shortcut",
// A resizable panel's share of its group, written as a percentage.
"maxSize",
],
},
callees: {
exclude: [
"invoke",
"listen",
"emit",
"useKeys",
"navigate",
"console\\..*",
"setProperty",
"removeProperty",
"querySelector",
"closest",
"getElementById",
// A prefix or suffix test compares against a key, never copy.
".*\\.(startsWith|endsWith)",
],
},
"object-properties": {
// "transform" is a CSS value in a keyframe, never copy.
exclude: ["to", "search", "key", "id", "className", "data-ui", "transform"],
},
words: {
exclude: [
// Ids, paths and class tokens: copy has a capital or a space.
"^[a-z0-9_./:-]+$",
// Punctuation bracketing a value the code interpolates, never a sentence.
"^[\\s(){}\\[\\]<>,.:;/|·–—+-]+$",
// A modifier or a key name of a chord, which a keycap shows as it is.
"^(Ctrl|Control|Alt|Shift|Space)$",
// A CSS value that reads a custom property, or a bare length.
".*var\\(--.*",
"^[\\d.]+(px|%|em|rem)?( [\\d.]+(px|%|em|rem)?)*$",
],
},
},
],
},
},
{
/* The structural rules src/AGENTS.md states as prose. Warnings, because the
moves in docs/research/frontend-architecture-audit.md have not landed. */
files: ["src/**/*.{ts,tsx}"],
ignores: ["src/**/*.test.{ts,tsx}", "src/test/**", ...GENERATED],
rules: {
"no-restricted-imports": ["warn", { patterns: [barrelRule(null), ...RESTRICTED] }],
},
},
/* One block per module, each blind to its own insides. Last match wins in a
flat config, so these replace the rule the block above sets. */
...MODULES.map((owner) => ({
files: [`src/modules/${owner}/**/*.{ts,tsx}`],
ignores: NOT_MODULE_SOURCE,
rules: {
"no-restricted-imports": ["warn", { patterns: [barrelRule(owner), ...RESTRICTED] }],
},
})),
{
files: ["src/**/*.tsx"],
ignores: ["src/components/**", "src/**/*.test.tsx", "src/test/**", ...GENERATED],
rules: {
"no-restricted-syntax": ["warn", ...NATIVE_CONTROLS],
},
},
{
/* The wrappers are what the rule points every other file at, so they reach
Base UI and each other freely. The merger is not one of those, and a
wrapper reaching the stock one loses the type tier like anything else. */
files: ["src/components/**/*.{ts,tsx}"],
rules: {
"no-restricted-imports": ["warn", { patterns: [TAILWIND_MERGE] }],
},
},
{
/* Where the configured merger is built. */
files: ["src/utils/twMerge.ts"],
rules: { "no-restricted-imports": "off" },
},
{
/* React Three Fiber's reconciler draws ThreeJS objects rather than DOM nodes, so
every element and prop in this directory is one the DOM rule has never heard of. */
files: [
"src/modules/viewport/**/*.tsx",
"src/modules/workshop/bin/vfx/**/*.tsx",
"src/modules/workshop/bin/map/components/ImportPreview.tsx",
"src/modules/workshop/bin/map/components/MapCharacters.tsx",
"src/modules/workshop/bin/map/components/MapFocus.tsx",
"src/modules/workshop/bin/map/components/MapMarkers.tsx",
"src/modules/workshop/bin/map/components/MapParticles.tsx",
"src/modules/workshop/bin/map/components/MeshHighlight.tsx",
"src/modules/workshop/bin/map/components/NavGridOutlines.tsx",
"src/modules/workshop/bin/map/components/PlaceableGizmo.tsx",
"src/modules/workshop/bin/map/components/PlaceableShapes.tsx",
"src/modules/workshop/bin/map/components/RegionBoundaries.tsx",
"src/modules/workshop/bin/map/components/RegionHandles.tsx",
"src/modules/workshop/bin/map/components/RegionVertexMarkers.tsx",
"src/modules/workshop/bin/map/components/SunHandle.tsx",
"src/modules/workshop/bin/spells/components/MissileViewport.tsx",
"src/modules/workshop/bin/spells/components/AbilityPreview.tsx",
"src/modules/workshop/bin/spells/components/AbilityScene.tsx",
"src/modules/workshop/objectsBrowser/components/ObjectPreviewScene.tsx",
],
rules: { "react/no-unknown-property": "off" },
},
{
files: ["scripts/**/*.mjs"],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
ignores: [
"**/dist/",
"**/node_modules/",
"**/target/",
"**/.claude/",
"src-tauri/",
"gen/",
"prettier.config.js",
"src/paraglide/",
],
},
eslintConfigPrettier,
);