diff --git a/package.json b/package.json index e69b854..50cccd4 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "lint": "oxlint", "deploy": "pnpm build && wrangler deploy", "seo": "vite-node scripts/seo.ts", + "tw:fix": "vite-node scripts/tw-fix.ts", "core:build": "pnpm --filter @fadeltd/devtools-core build" }, "dependencies": { @@ -36,6 +37,7 @@ "react-router": "8.4.0" }, "devDependencies": { + "@tailwindcss/node": "4.3.3", "@tailwindcss/vite": "4.3.3", "@types/node": "24.9.2", "@types/react": "19.3.0", diff --git a/packages/core/src/id-gen/ulid.test.ts b/packages/core/src/id-gen/ulid.test.ts index 1c0cd34..fb04a77 100644 --- a/packages/core/src/id-gen/ulid.test.ts +++ b/packages/core/src/id-gen/ulid.test.ts @@ -154,8 +154,10 @@ describe('monotonic ULID', () => { describe('ULID through generateIds', () => { it('is canonical uppercase by default, lowercase on request', () => { - const [upper] = generateIds(opts({ count: 1 }), mulberry32(1)).ids - const [lower] = generateIds(opts({ count: 1, letterCase: 'lower' }), mulberry32(1)).ids + // Both calls need the same clock: with the real one, a millisecond tick + // between them changes the time prefix and the comparison fails. + const [upper] = generateIds(opts({ count: 1 }), mulberry32(1), fixed(T)).ids + const [lower] = generateIds(opts({ count: 1, letterCase: 'lower' }), mulberry32(1), fixed(T)).ids expect(upper).toMatch(ULID) expect(lower).toBe(upper!.toLowerCase()) }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 80210dc..8e9143e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,9 @@ importers: specifier: 8.4.0 version: 8.4.0(react-dom@19.3.0(react@19.3.0))(react@19.3.0) devDependencies: + '@tailwindcss/node': + specifier: 4.3.3 + version: 4.3.3 '@tailwindcss/vite': specifier: 4.3.3 version: 4.3.3(vite@8.3.0(@types/node@24.9.2)(esbuild@0.28.1)(jiti@2.7.0)) diff --git a/scripts/tailwind.test.ts b/scripts/tailwind.test.ts new file mode 100644 index 0000000..3f3c821 --- /dev/null +++ b/scripts/tailwind.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest' +import { applyFindings, findInSource, findNonCanonical } from './tailwind' + +// A stand-in canonicalizer, so the extraction tests don't depend on Tailwind. +const fake = (token: string) => ({ 'w-[220px]': 'w-55', 'rounded-[2px]': 'rounded-xs' })[token] ?? token + +describe('findInSource', () => { + it('finds classes in className strings, cn() arguments and template literals', () => { + const src = [ + `const a =
`, + `const b = cn('p-2', on && 'rounded-[2px]')`, + 'const c = `gap-2 ${x} w-[220px]`', + ].join('\n') + const found = findInSource('x.tsx', src, fake) + expect(found.map((f) => [f.line, f.from, f.to])).toEqual([ + [1, 'w-[220px]', 'w-55'], + [2, 'rounded-[2px]', 'rounded-xs'], + [3, 'w-[220px]', 'w-55'], + ]) + }) + + it('ignores JSX text, so an apostrophe cannot open a fake string', () => { + const src = `const a =Don't w-[220px] it's fine
` + expect(findInSource('x.tsx', src, fake)).toEqual([]) + }) + + it('reports offsets that applyFindings can rewrite exactly', () => { + const src = `` + const out = applyFindings(src, findInSource('x.tsx', src, fake)) + expect(out).toBe(``) + }) +}) + +describe('src/', () => { + // The guard: new code must use the canonical spelling. Run `pnpm tw:fix --write`. + it('has no non-canonical Tailwind classes', { timeout: 60_000 }, async () => { + const findings = await findNonCanonical() + expect(findings.map((f) => `${f.file}:${f.line} ${f.from} → ${f.to}`)).toEqual([]) + }) +}) diff --git a/scripts/tailwind.ts b/scripts/tailwind.ts new file mode 100644 index 0000000..01be5d3 --- /dev/null +++ b/scripts/tailwind.ts @@ -0,0 +1,123 @@ +/** + * Find Tailwind classes that have a canonical spelling, using Tailwind's own + * canonicalizer -- the engine behind the editor's "can be written as" hints. + * + * Only string and template literals are inspected (parsed with oxc via Vite), + * never JSX text, so an apostrophe in "Don't" cannot open a fake string. + * Each token is canonicalized on its own: collapsing `mt-2 mb-2` into `my-2` + * would change which classes a conditional `cn()` branch toggles. + */ +import { readFileSync, readdirSync, statSync } from 'node:fs' +import { join, relative } from 'node:path' +import { __unstable__loadDesignSystem } from '@tailwindcss/node' +import { parseAst } from 'vite' + +export interface Finding { + file: string + line: number + column: number + /** Absolute offset of the token in the file. */ + offset: number + from: string + to: string +} + +type DesignSystem = AwaitedNo shortcuts registered.
diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index a9fa8bf..ced4a1c 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -97,7 +97,7 @@ export function Sidebar() { // Animating width needs overflow-hidden above, or the labels spill // across the main pane mid-transition. Respects reduced-motion. 'transition-[width] duration-200 ease-out motion-reduce:transition-none', - sidebarCollapsed ? 'w-[52px]' : 'w-[220px]', + sidebarCollapsed ? 'w-13' : 'w-55', )} > {/* At the top, where it is actually visible, and aligned with the header diff --git a/src/components/layout/ToolFrame.tsx b/src/components/layout/ToolFrame.tsx index f8fd225..22346ef 100644 --- a/src/components/layout/ToolFrame.tsx +++ b/src/components/layout/ToolFrame.tsx @@ -57,7 +57,7 @@ export function ToolFrame({ {actions !== undefined && (
{/* Inputs */}
-
+
- {value}
+ {value}
)
}
diff --git a/src/tools/id-gen/IdGenTool.tsx b/src/tools/id-gen/IdGenTool.tsx
index 9cd46b0..ae70fe4 100644
--- a/src/tools/id-gen/IdGenTool.tsx
+++ b/src/tools/id-gen/IdGenTool.tsx
@@ -301,9 +301,9 @@ export default function IdGenTool() {
-
+
-
+
{issue.snippet.lines.map((l) => (
diff --git a/src/tools/jwt/JwtTool.tsx b/src/tools/jwt/JwtTool.tsx
index 6d03ddf..f01e30f 100644
--- a/src/tools/jwt/JwtTool.tsx
+++ b/src/tools/jwt/JwtTool.tsx
@@ -225,7 +225,7 @@ function Decoded({ result }: { result: JwtResult }) {
{formatCount(signature.bytes)} bytes · not verified
{signature.base64url !== '' && (
-
+
{signature.base64url}
)}
@@ -271,7 +271,7 @@ function ClaimLine({ claim }: { claim: ClaimRow }) {
{claim.name}
{claim.label}
-
+
{time === null ? (
{claim.display}
) : (
@@ -294,8 +294,8 @@ function Issue({ issue, error = false }: { issue: JwtIssue; error?: boolean }) {
const Icon = error ? CircleX : TriangleAlert
return (
-
- {issue.message}
+
+ {issue.message}
)
}
@@ -323,7 +323,7 @@ function TokenSummary({ result }: { result: JwtResult }) {
return (
-
+
{pieces}
{truncated && (
… {formatCount(result.token.length - MAX_SUMMARY)} more
@@ -350,7 +350,7 @@ function Segment({ part, marked, even }: { part: TokenPart; marked: number | und
return (
{visible.slice(0, at)}
- {ch}
+ {ch}
{visible.slice(at + ch.length)}
)
diff --git a/src/tools/number/NumberTool.tsx b/src/tools/number/NumberTool.tsx
index fbb1923..5f8db76 100644
--- a/src/tools/number/NumberTool.tsx
+++ b/src/tools/number/NumberTool.tsx
@@ -117,7 +117,7 @@ function ErrorLine({ input, error }: { input: string; error: InputError }) {
{context !== null && (
{context.before}
- {context.bad === '' ? ' ' : context.bad}
+ {context.bad === '' ? ' ' : context.bad}
{context.after}
)}
diff --git a/src/tools/text-stats/TextStatsTool.tsx b/src/tools/text-stats/TextStatsTool.tsx
index 6636603..871969f 100644
--- a/src/tools/text-stats/TextStatsTool.tsx
+++ b/src/tools/text-stats/TextStatsTool.tsx
@@ -249,9 +249,9 @@ export default function TextStatsTool() {
{/* The bar sits in its own track so a full-width bar cannot
push the numbers -- which are the actual data -- off the row. */}
-
+
diff --git a/src/tools/timestamp/TimestampTool.tsx b/src/tools/timestamp/TimestampTool.tsx
index 47e724c..f5dcb51 100644
--- a/src/tools/timestamp/TimestampTool.tsx
+++ b/src/tools/timestamp/TimestampTool.tsx
@@ -83,7 +83,7 @@ function Row({ label, value, note }: { label: string; value: string | null; note
return (
- {label}
+ {label}
{value ?? {note ?? '—'}}
@@ -170,7 +170,7 @@ export default function TimestampTool() {
className="self-start"
/>