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

vite.config.ts

345 lines13.6 KB

1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4​
5/** Import restrictions every file keeps, including the one module exempt from the glyph rule. */
6const RESTRICTED_IMPORT_PATHS = [
7 {
8 name: "@t3tools/client-runtime",
9 message:
10 "Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
11 },
12 {
13 name: "@pierre/diffs/react",
14 importNames: ["CodeView"],
15 message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
16 },
17];
18​
19/**
20 * The cva functions behind components/ui exports. They style a foreign element to look
21 * like a Button or Toggle, which bypasses the component's variants; render the component
22 * instead (`render={<Button …/>}`, or `SelectButton` for a picker trigger).
23 */
24const RESTRICTED_UI_VARIANT_PATTERNS = [
25 {
26 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
27 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
28 message:
29 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
30 },
31];
32​
33/** Lucide's pull-request glyphs, which only `pullRequestIcons.tsx` may name. */
34const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
35 name: "lucide-react",
36 importNames: [
37 "GitMerge",
38 "GitMergeIcon",
39 "GitPullRequest",
40 "GitPullRequestIcon",
41 "GitPullRequestArrow",
42 "GitPullRequestArrowIcon",
43 "GitPullRequestClosed",
44 "GitPullRequestClosedIcon",
45 "GitPullRequestDraft",
46 "GitPullRequestDraftIcon",
47 "GitPullRequestCreate",
48 "GitPullRequestCreateIcon",
49 "GitPullRequestCreateArrow",
50 "GitPullRequestCreateArrowIcon",
51 ],
52 message:
53 "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.",
54};
55​
56export default defineConfig({
57 resolve: {
58 alias: {
59 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
60 },
61 },
62 test: {
63 environment: "node",
64 exclude: [
65 "**/.repos/**",
66 "**/.t3/**",
67 "**/node_modules/**",
68 "**/dist/**",
69 "**/dist-electron/**",
70 "**/.{idea,git,cache,output,temp}/**",
71 ],
72 hookTimeout: 60_000,
73 testTimeout: 60_000,
74 setupFiles: [
75 NodeURL.fileURLToPath(
76 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
77 ),
78 ],
79 },
80 staged: {
81 // Formatter only for now — no lint or typecheck on commit.
82 "*": "vp fmt --no-error-on-unmatched-pattern",
83 },
84 fmt: {
85 ignorePatterns: [
86 ".repos/**",
87 // Macroscope's glob-per-line ignore grammar, not Markdown: formatting
88 // it rewrites `*` as `_` and joins lines.
89 ".macroscope/ignore.md",
90 ".alchemy",
91 "dist",
92 "dist-electron",
93 "node_modules",
94 "pnpm-lock.yaml",
95 "*.tsbuildinfo",
96 "**/routeTree.gen.ts",
97 "apps/mobile/android/**",
98 "apps/mobile/ios/**",
99 "apps/mobile/uniwind-types.d.ts",
100 "*.icon/**",
101 ],
102 sortPackageJson: {},
103 overrides: [
104 {
105 files: [".devcontainer/devcontainer.json"],
106 options: {
107 trailingComma: "none",
108 },
109 },
110 ],
111 },
112 lint: {
113 ignorePatterns: [
114 ".repos",
115 ".repos/**",
116 "dist",
117 "dist-electron",
118 "node_modules",
119 "pnpm-lock.yaml",
120 "*.tsbuildinfo",
121 "**/routeTree.gen.ts",
122 "apps/mobile/android/**",
123 "apps/mobile/ios/**",
124 "apps/mobile/uniwind-types.d.ts",
125 ],
126 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
127 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
128 settings: {
129 shadcn: { ui: "~/components/ui" },
130 },
131 categories: {
132 correctness: "warn",
133 suspicious: "warn",
134 perf: "warn",
135 },
136 rules: {
137 "unicorn/no-array-sort": "off",
138 "unicorn/consistent-function-scoping": "off",
139 "oxc/no-map-spread": "off",
140 "react-in-jsx-scope": "off",
141 "react-hooks/exhaustive-deps": "off",
142 "eslint/no-shadow": "off",
143 "eslint/no-await-in-loop": "off",
144 "eslint/no-underscore-dangle": "off",
145 "typescript/consistent-return": "off",
146 "typescript/no-base-to-string": "off",
147 "typescript/no-duplicate-type-constituents": "off",
148 "typescript/no-floating-promises": "off",
149 "typescript/no-implied-eval": "off",
150 "typescript/no-meaningless-void-operator": "off",
151 "typescript/no-redundant-type-constituents": "off",
152 "typescript/no-unnecessary-boolean-literal-compare": "off",
153 "typescript/no-unnecessary-type-conversion": "off",
154 "typescript/no-unnecessary-type-arguments": "off",
155 "typescript/no-unnecessary-type-assertion": "off",
156 "typescript/no-unnecessary-type-parameters": "off",
157 "typescript/no-unsafe-type-assertion": "off",
158 "typescript/await-thenable": "off",
159 "typescript/require-array-sort-compare": "off",
160 "typescript/restrict-template-expressions": "off",
161 "typescript/unbound-method": "off",
162 "eslint/no-restricted-imports": [
163 "error",
164 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
165 ],
166 "t3code/no-global-process-runtime": "error",
167 "t3code/no-inline-schema-compile": "warn",
168 "t3code/no-manual-effect-runtime-in-tests": "error",
169 "t3code/no-native-title-tooltip": "error",
170 "t3code/no-test-in-loop": "error",
171 "t3code/no-unscoped-has": "error",
172 "t3code/namespace-node-imports": "error",
173 },
174 overrides: [
175 {
176 // The one place that reads the host platform to seed the injected references.
177 files: ["packages/shared/src/hostProcess.ts"],
178 rules: { "t3code/no-global-process-runtime": "off" },
179 },
180 {
181 files: ["apps/web/src/**"],
182 excludeFiles: ["apps/web/src/components/ui/**"],
183 rules: {
184 "eslint/no-restricted-imports": [
185 "error",
186 {
187 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
188 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
189 },
190 ],
191 },
192 },
193 {
194 // The one module allowed to name lucide's pull-request glyphs; everything else picks
195 // from its vocabulary. The other import restrictions still apply here.
196 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
197 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
198 },
199 {
200 files: ["apps/mobile/src/**"],
201 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
202 },
203 {
204 // Every class in web code must be one Tailwind generates: a typo or a class nothing
205 // declares ships silently unstyled. JS hooks use data attributes, not class names.
206 files: ["apps/web/src/**"],
207 rules: { "shadcn/no-unknown-classes": "error" },
208 },
209 {
210 // Colors come from theme tokens so status tones follow custom themes. components/ui
211 // has no findings and stays covered too.
212 files: ["apps/web/src/**"],
213 rules: { "shadcn/no-raw-colors": "error" },
214 },
215 {
216 // Third-party marks (brand logos, the macOS permission panes, Codex's Computer Use
217 // mark) must keep their exact colors, so the files that hold them are exempt.
218 files: ["apps/web/src/components/Icons.tsx", "apps/web/src/components/JetBrainsIcons.tsx"],
219 rules: { "shadcn/no-raw-colors": "off" },
220 },
221 {
222 // components/ui exports own their look. App code picks a variant or size instead
223 // of restyling with className; layout classes (width, flex, margin, position) stay
224 // allowed because placement belongs to the parent. components/ui is for generic
225 // primitives: a look that belongs to one feature stays in that feature's component.
226 files: ["apps/web/src/**"],
227 excludeFiles: ["apps/web/src/components/ui/**"],
228 rules: {
229 // A className built at runtime on a ui component is one no-restyle cannot read.
230 "shadcn/require-static-classes": "error",
231 // Appearance values come from the theme and Tailwind's scales. Layout stays free
232 // (placement belongs to the parent); the other entries are values no scale can hold.
233 "shadcn/no-arbitrary-values": [
234 "error",
235 {
236 allow: [
237 "layout",
238 // Which properties an element animates is per-element behaviour, like layout,
239 // not a design value; timing curves and durations still come from the theme.
240 "transition",
241 // Overlays that follow their frame's corner, which is set at runtime
242 // (floating preview) or by the element they decorate (composer outline).
243 "rounded-[inherit]",
244 // Inline chips size in em so they scale with the text they sit in
245 // (the composer honours the prompt font-size preference).
246 "gap-[0.33em]",
247 "px-[0.5em]",
248 "rounded-[0.5em]",
249 "text-[0.86em]",
250 // Project icons render from 14px to 48px and keep one proportional corner.
251 "rounded-[25%]",
252 // An emoji project icon fills its container, whatever size the parent gives it.
253 "text-[length:80cqh]",
254 // The platform's own selection colour on a selected composer chip.
255 "bg-[Highlight]",
256 // Brand marks keep their brand colours (Cursor, Grok, Claude).
257 "fill-[#26251E]",
258 "fill-[#EDECEC]",
259 "fill-[#0F0F0F]",
260 "fill-[#F5F5F5]",
261 "fill-[#d97757]",
262 "text-[#d97757]",
263 ],
264 },
265 ],
266 "shadcn/no-restyle": [
267 "error",
268 {
269 allow: ["layout"],
270 contracts: [
271 {
272 // CollapsibleTrigger is a bare button with no styled counterpart
273 // (a disclosure row is not a Button), so its className is the API.
274 // Every other trigger has one: style them with render={<Button …/>}.
275 pattern: "^CollapsibleTrigger$",
276 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
277 },
278 ],
279 },
280 ],
281 },
282 },
283 {
284 // The sign-in masthead is T3 brand artwork: fixed gradients, not theme surfaces.
285 files: ["apps/web/src/components/auth/AuthSurfaceShell.tsx"],
286 rules: { "shadcn/no-arbitrary-values": "off" },
287 },
288 {
289 // Shared client code must not call APIs missing from Hermes. Our ESNext
290 // TypeScript target accepts them even when they would crash mobile at launch.
291 // Tests run on Node and are exempt.
292 files: [
293 "apps/mobile/src/**",
294 "packages/client-runtime/src/**",
295 "packages/contracts/src/**",
296 "packages/shared/src/**",
297 ],
298 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
299 rules: { "t3code/no-hermes-unsupported-apis": "error" },
300 },
301 {
302 // Reviewed native and third-party interop boundaries that cannot consume a className.
303 files: [
304 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
305 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
306 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
307 "apps/mobile/src/features/files/SourceFileSurface.tsx",
308 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
309 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
310 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
311 "apps/mobile/src/features/home/HomeHeader.tsx",
312 "apps/mobile/src/features/review/ReviewSheet.tsx",
313 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
314 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
315 "apps/mobile/src/features/threads/GitActionProgressOverlay.tsx",
316 "apps/mobile/src/features/threads/NewTaskDraftScreen.tsx",
317 "apps/mobile/src/features/threads/ThreadComposer.tsx",
318 "apps/mobile/src/features/threads/ThreadFeed.tsx",
319 "apps/mobile/src/features/settings/appearance/components/FontSizeSliderRow.tsx",
320 "apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx",
321 "apps/mobile/src/features/threads/ThreadQueueControl.tsx",
322 "apps/mobile/src/features/threads/ThreadAgentsSheet.tsx",
323 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
324 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
325 "apps/mobile/src/features/threads/git/GitOverviewSheet.tsx",
326 "apps/mobile/src/features/threads/thread-list-items.tsx",
327 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
328 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
329 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
330 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
331 "apps/mobile/src/native/SelectableMarkdownText.android.tsx",
332 ],
333 rules: {
334 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
335 },
336 },
337 ],
338 options: {
339 reportUnusedDisableDirectives: "error",
340 // Revisit once Oxlint's tsgolint path can integrate with @effect/tsgo diagnostics.
341 typeAware: false,
342 typeCheck: false,
343 },
344 },
345});