Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vite.config.ts

406 lines14.6 KB

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