Open History to see the last commit
1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4
5const DOM_TEST_ENVIRONMENT_ALLOWLIST: Array<string> = [];
6
7const RESTRICTED_IMPORT_PATHS = [
8 {
9 name: "@t3tools/client-runtime",
10 message:
11 "Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
12 },
13 {
14 name: "@pierre/diffs/react",
15 importNames: ["CodeView"],
16 message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
17 },
18];
19
20const RESTRICTED_UI_VARIANT_PATTERNS = [
21 {
22 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
23 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
24 message:
25 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
26 },
27];
28
29const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
30 name: "lucide-react",
31 importNames: [
32 "GitMerge",
33 "GitMergeIcon",
34 "GitPullRequest",
35 "GitPullRequestIcon",
36 "GitPullRequestArrow",
37 "GitPullRequestArrowIcon",
38 "GitPullRequestClosed",
39 "GitPullRequestClosedIcon",
40 "GitPullRequestDraft",
41 "GitPullRequestDraftIcon",
42 "GitPullRequestCreate",
43 "GitPullRequestCreateIcon",
44 "GitPullRequestCreateArrow",
45 "GitPullRequestCreateArrowIcon",
46 ],
47 message:
48 "Pick a glyph by meaning from PullRequestGlyph in apps/web/src/components/pullRequest/pullRequestIcons.tsx so every surface draws the same pull request the same way.",
49};
50
51export default defineConfig({
52 resolve: {
53 alias: {
54 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
55 },
56 },
57 test: {
58 environment: "node",
59 exclude: [
60 "**/.repos/**",
61 "**/.t3/**",
62 "**/node_modules/**",
63 "**/dist/**",
64 "**/dist-electron/**",
65 "**/.{idea,git,cache,output,temp}/**",
66 ],
67 hookTimeout: 60_000,
68 testTimeout: 60_000,
69 allowOnly: !process.env.CI,
70 // Flaky tests are fixed, not retried.
71 retry: 0,
72 fakeTimers: {
73 toFake: [
74 "setTimeout",
75 "clearTimeout",
76 "setInterval",
77 "clearInterval",
78 "setImmediate",
79 "clearImmediate",
80 "Date",
81 "performance",
82 "requestAnimationFrame",
83 "cancelAnimationFrame",
84 "requestIdleCallback",
85 "cancelIdleCallback",
86 ],
87 },
88 setupFiles: [
89 NodeURL.fileURLToPath(
90 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
91 ),
92 ],
93 },
94 staged: {
95 "*": "vp fmt --no-error-on-unmatched-pattern",
96 },
97 fmt: {
98 ignorePatterns: [
99 ".repos/**",
100 // Macroscope's glob-per-line ignore grammar, not Markdown: formatting
101 // it rewrites `*` as `_` and joins lines.
102 ".macroscope/ignore.md",
103 ".alchemy",
104 "dist",
105 "dist-electron",
106 "node_modules",
107 "pnpm-lock.yaml",
108 "*.tsbuildinfo",
109 "**/routeTree.gen.ts",
110 "**/*.graphql.ts",
111 "packages/source-control-github/schema/**",
112 "apps/server/schema/**",
113 "apps/mobile/android/**",
114 "apps/mobile/ios/**",
115 "apps/mobile/uniwind-types.d.ts",
116 "*.icon/**",
117 ],
118 sortPackageJson: {},
119 overrides: [
120 {
121 files: [".devcontainer/devcontainer.json"],
122 options: {
123 trailingComma: "none",
124 },
125 },
126 ],
127 },
128 lint: {
129 ignorePatterns: [
130 ".repos",
131 ".repos/**",
132 "dist",
133 "dist-electron",
134 "node_modules",
135 "pnpm-lock.yaml",
136 "*.tsbuildinfo",
137 "**/routeTree.gen.ts",
138 "**/*.graphql.ts",
139 "packages/source-control-github/schema/**",
140 "apps/server/schema/**",
141 "apps/mobile/android/**",
142 "apps/mobile/ios/**",
143 "apps/mobile/uniwind-types.d.ts",
144 ],
145 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
146 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
147 settings: {
148 shadcn: { ui: "~/components/ui" },
149 },
150 categories: {
151 correctness: "warn",
152 suspicious: "warn",
153 perf: "warn",
154 },
155 rules: {
156 "unicorn/no-array-sort": "off",
157 "unicorn/consistent-function-scoping": "off",
158 "oxc/no-map-spread": "off",
159 "react-in-jsx-scope": "off",
160 "react-hooks/exhaustive-deps": "off",
161 "eslint/no-shadow": "off",
162 "eslint/no-await-in-loop": "off",
163 "eslint/no-underscore-dangle": "off",
164 "typescript/consistent-return": "off",
165 "typescript/no-base-to-string": "off",
166 "typescript/no-duplicate-type-constituents": "off",
167 "typescript/no-floating-promises": "off",
168 "typescript/no-implied-eval": "off",
169 "typescript/no-meaningless-void-operator": "off",
170 "typescript/no-redundant-type-constituents": "off",
171 "typescript/no-unnecessary-boolean-literal-compare": "off",
172 "typescript/no-unnecessary-type-conversion": "off",
173 "typescript/no-unnecessary-type-arguments": "off",
174 "typescript/no-unnecessary-type-assertion": "off",
175 "typescript/no-unnecessary-type-parameters": "off",
176 "typescript/no-unsafe-type-assertion": "off",
177 "typescript/await-thenable": "off",
178 "typescript/require-array-sort-compare": "off",
179 "typescript/restrict-template-expressions": "off",
180 "typescript/unbound-method": "off",
181 "eslint/no-restricted-imports": [
182 "error",
183 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
184 ],
185 "t3code/no-global-process-runtime": "error",
186 "t3code/no-inline-schema-compile": "warn",
187 "t3code/no-low-value-comments": "error",
188 "t3code/no-manual-effect-runtime-in-tests": "error",
189 "t3code/no-native-title-tooltip": "error",
190 // Test files only (the rule checks the filename). Becomes an error once existing polls are converted.
191 "t3code/no-polling-loop-in-tests": "warn",
192 "t3code/no-raw-mcp-registration": "error",
193 "t3code/no-real-time-wait-in-tests": "error",
194 "t3code/no-test-in-loop": "error",
195 "t3code/no-test-timeout-or-unreasoned-skip": "error",
196 "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }],
197 "t3code/no-unscoped-has": "error",
198 "t3code/no-wall-clock-in-tests": "error",
199 "t3code/namespace-node-imports": "error",
200 "t3code/prefer-catch-tags": "error",
201 "t3code/prefer-effect-fn": "error",
202 "t3code/require-centered-scroll-gutter": "error",
203 "t3code/require-suppression-reason": "error",
204 },
205 overrides: [
206 {
207 files: [
208 "**/*.{test,spec,testkit}.{ts,tsx}",
209 "**/{test,tests,testkit,testing,fixtures,integration}/**",
210 "packages/provider-testing/**",
211 ],
212 rules: { "t3code/prefer-effect-fn": "off" },
213 },
214 {
215 files: ["apps/web/**/*.test.{ts,tsx}"],
216 rules: { "t3code/require-disposable-render": "error" },
217 },
218 {
219 files: ["apps/web/src/**/*.browser.test.{ts,tsx}"],
220 rules: { "t3code/no-frame-waits-in-browser-tests": "error" },
221 },
222 {
223 files: ["**/*.browser.test.*"],
224 rules: { "t3code/no-real-time-wait-in-tests": "off" },
225 },
226 {
227 files: ["apps/**/src/**", "packages/**/src/**"],
228 excludeFiles: DOM_TEST_ENVIRONMENT_ALLOWLIST,
229 rules: { "t3code/no-dom-test-environment": "error" },
230 },
231 {
232 files: ["packages/client-runtime/src/state/**", "apps/{web,mobile,desktop}/src/**"],
233 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: false }] },
234 },
235 {
236 files: [
237 "packages/client-runtime/src/state/runtime.ts",
238 "packages/client-runtime/src/state/vcsAction.ts",
239 ],
240 rules: {
241 "t3code/no-rpc-permission-bypass": [
242 "error",
243 { allowGuardInstallation: true, allowRawClientAccess: false },
244 ],
245 },
246 },
247 {
248 files: [
249 "apps/web/src/components/settings/ConnectionsSettings.tsx",
250 "apps/mobile/src/features/updates/app-updates.ts",
251 "apps/web/src/components/device/DevicePhoneViewport.tsx",
252 "apps/web/src/components/device/DeviceDuoViewport.tsx",
253 ],
254 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }] },
255 },
256 {
257 files: ["packages/client-runtime/src/connection/outdatedHostUpdate.ts"],
258 rules: { "t3code/no-rpc-permission-bypass": "off" },
259 },
260 {
261 files: [
262 "packages/client-runtime/src/rpc/**",
263 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
264 ],
265 rules: { "t3code/no-rpc-permission-bypass": "off" },
266 },
267 {
268 files: ["packages/shared/src/HostProcess.ts"],
269 rules: { "t3code/no-global-process-runtime": "off" },
270 },
271 {
272 // The `t3` npm launcher is published as plain, dependency-free Node.
273 files: ["scripts/npm-launcher/**"],
274 rules: {
275 "t3code/no-global-process-runtime": "off",
276 "t3code/namespace-node-imports": "off",
277 },
278 },
279 {
280 files: ["apps/server/src/mcp/McpHttpServer.ts"],
281 rules: { "t3code/no-raw-mcp-registration": "off" },
282 },
283 {
284 files: ["apps/web/src/**"],
285 excludeFiles: ["apps/web/src/components/ui/**"],
286 rules: {
287 "eslint/no-restricted-imports": [
288 "error",
289 {
290 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
291 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
292 },
293 ],
294 },
295 },
296 {
297 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
298 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
299 },
300 {
301 files: ["apps/mobile/src/**"],
302 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
303 },
304 {
305 files: ["apps/mobile/src/**"],
306 excludeFiles: [
307 "apps/mobile/src/components/ui/AppSymbol.tsx",
308 "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
309 "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
310 ],
311 rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
312 },
313 {
314 // React commits state set in a raw ResizeObserver callback after the paint, so derived
315 // layout lands a frame late. observeResize flushes every observed resize in one render.
316 files: ["apps/web/src/**"],
317 excludeFiles: [
318 "apps/web/src/lib/observeResize.ts",
319 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
320 ],
321 rules: { "t3code/no-raw-resize-observer": "error" },
322 },
323 {
324 files: ["apps/web/src/**"],
325 rules: { "shadcn/no-unknown-classes": "error" },
326 },
327 {
328 files: ["apps/web/src/**"],
329 rules: { "t3code/no-outset-state-indicators": "error" },
330 },
331 {
332 files: ["apps/web/src/**"],
333 rules: { "shadcn/no-raw-colors": "error" },
334 },
335 {
336 // Third-party marks (brand logos, the macOS permission panes, Codex's Computer Use
337 // mark) must keep their exact colors, so the files that hold them are exempt.
338 files: ["apps/web/src/components/Icons.tsx", "apps/web/src/components/JetBrainsIcons.tsx"],
339 rules: { "shadcn/no-raw-colors": "off" },
340 },
341 {
342 files: ["apps/web/src/**"],
343 excludeFiles: ["apps/web/src/components/ui/**"],
344 rules: {
345 "shadcn/require-static-classes": "error",
346 "shadcn/no-arbitrary-values": [
347 "error",
348 {
349 allow: [
350 "layout",
351 "transition",
352 "rounded-[inherit]",
353 "gap-[0.33em]",
354 "px-[0.5em]",
355 "rounded-[0.5em]",
356 "text-[0.86em]",
357 "rounded-[25%]",
358 "text-[length:80cqh]",
359 "bg-[Highlight]",
360 "fill-[#26251E]",
361 "fill-[#EDECEC]",
362 "fill-[#0F0F0F]",
363 "fill-[#F5F5F5]",
364 "fill-[#d97757]",
365 "text-[#d97757]",
366 ],
367 },
368 ],
369 "shadcn/no-restyle": [
370 "error",
371 {
372 allow: ["layout"],
373 contracts: [
374 {
375 // CollapsibleTrigger is a bare button with no styled counterpart
376 // (a disclosure row is not a Button), so its className is the API.
377 // Every other trigger has one: style them with render={<Button …/>}.
378 pattern: "^CollapsibleTrigger$",
379 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
380 },
381 ],
382 },
383 ],
384 },
385 },
386 {
387 // Every web file must compile under the React Compiler. Its bailout rules are errors here,
388 // and manual memoization is redundant. No upstream rule bans useMemo/useCallback, hence
389 // t3code/no-manual-memo.
390 files: ["apps/web/src/**/*.{ts,tsx}"],
391 rules: {
392 "react/exhaustive-effect-dependencies": "error",
393 "react/globals": "error",
394 "react/hooks": "error",
395 "react/immutability": "error",
396 // The compiler memoizes context values; this rule would ask for useMemo.
397 "react/jsx-no-constructed-context-values": "off",
398 "react/memo-dependencies": "error",
399 "react/preserve-manual-memoization": "error",
400 "react/purity": "error",
401 "react/refs": "error",
402 "react/set-state-in-effect": "error",
403 "react/set-state-in-render": "error",
404 "react/static-components": "error",
405 "react/unsupported-syntax": "error",
406 "t3code/no-manual-memo": "error",
407 },
408 },
409 {
410 // The sign-in masthead is T3 brand artwork: fixed gradients, not theme surfaces.
411 files: ["apps/web/src/components/auth/AuthSurfaceShell.tsx"],
412 rules: { "shadcn/no-arbitrary-values": "off" },
413 },
414 {
415 // Shared client code must not call APIs missing from Hermes. Our ESNext
416 // TypeScript target accepts them even when they would crash mobile at launch.
417 // Tests run on Node and are exempt.
418 files: [
419 "apps/mobile/src/**",
420 "packages/client-runtime/src/**",
421 "packages/contracts/src/**",
422 "packages/shared/src/**",
423 ],
424 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
425 rules: { "t3code/no-hermes-unsupported-apis": "error" },
426 },
427 {
428 // Mobile is ratcheting toward full React Compiler coverage
429 // (apps/mobile/src/reactCompilerCoverage.test.ts). Directives would hide bailouts from it;
430 // the manual memo hooks go once the allowlist there is empty.
431 files: ["apps/mobile/src/**/*.{ts,tsx}"],
432 rules: { "t3code/no-manual-memo": ["error", { allowMemoHooks: true }] },
433 },
434 {
435 // The compiler only compiles a use* function that calls a hook; one that calls none is
436 // silently left as a plain function, so whatever it returns loses its caching.
437 files: ["apps/web/src/**/*.{ts,tsx}", "apps/mobile/src/**/*.{ts,tsx}"],
438 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
439 rules: { "t3code/no-hookless-use-function": "error" },
440 },
441 {
442 files: [
443 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
444 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
445 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
446 "apps/mobile/src/features/files/SourceFileSurface.tsx",
447 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
448 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
449 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
450 "apps/mobile/src/features/home/HomeHeader.tsx",
451 "apps/mobile/src/features/review/ReviewSheet.tsx",
452 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
453 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
454 "apps/mobile/src/features/threads/GitActionProgressOverlay.tsx",
455 "apps/mobile/src/features/threads/NewTaskDraftScreen.tsx",
456 "apps/mobile/src/features/threads/ThreadComposer.tsx",
457 "apps/mobile/src/features/threads/ThreadFeed.tsx",
458 "apps/mobile/src/features/settings/appearance/components/FontSizeSliderRow.tsx",
459 "apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx",
460 "apps/mobile/src/features/threads/ThreadQueueControl.tsx",
461 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
462 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
463 "apps/mobile/src/features/threads/thread-list-items.tsx",
464 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
465 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
466 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
467 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
468 "apps/mobile/src/native/SelectableMarkdownText.tsx",
469 ],
470 rules: {
471 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
472 },
473 },
474 ],
475 options: {
476 reportUnusedDisableDirectives: "error",
477 typeAware: false,
478 typeCheck: false,
479 },
480 },
481});