/** * Unit tests for the `healthlog/spacing-scale` rule — pt-* / pb-* slot * padding on CardHeader/CardContent is banned (the Card is gap-based; * density lives on the Card itself). Covers modifier prefixes, * cn()/ternary/template collection, the safe-area non-match, and the * scope gating shared with the sibling rules. */ import { describe, it } from "vitest"; import { RuleTester } from "eslint"; import rule from "../spacing-scale.js"; RuleTester.describe = describe; RuleTester.it = it; RuleTester.itOnly = it.only; const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2023, sourceType: "module", parserOptions: { ecmaFeatures: { jsx: true } }, }, }); const APP_FILE = "/repo/src/components/insights/example.tsx"; ruleTester.run("spacing-scale", rule, { valid: [ // Density on the Card itself is the sanctioned pattern. { code: 'x', filename: APP_FILE, }, // Slots without className, or with unrelated classes, are fine. { code: "", filename: APP_FILE }, { code: '', filename: APP_FILE, }, // Other paddings on slots are not this rule's business. { code: '', filename: APP_FILE, }, // Safe-area helpers are not scale steps and never match. { code: '', filename: APP_FILE, }, // pt-/pb- on arbitrary elements stays legal — the contract is about // the gap-based Card slots only. { code: '
', filename: APP_FILE }, // Outside the enforced roots nothing matches. { code: '', filename: "/repo/scripts/tool.tsx", }, // Test files are exempt. { code: '', filename: "/repo/src/components/__tests__/example.test.tsx", }, // The card-shell `5` check is scoped to the bg-card+border pair, so the // justified list-marker inset never trips it (no shell). { code: '
    ', filename: APP_FILE, }, // A directional inset ON a shell is out of scope (pl-5/pr-5 not banned). { code: '
    ', filename: APP_FILE, }, // Form-body rhythm without a shell surface is fine. { code: '
    ', filename: APP_FILE, }, // A shell already on-scale is fine. { code: '
    ', filename: APP_FILE, }, // bg-card without a border is not treated as a shell. { code: '
    ', filename: APP_FILE, }, ], invalid: [ { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // Modifier-prefixed and fractional steps. { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // Arbitrary-value padding. { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // Collected through cn() args… { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // …ternaries… { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }, { messageId: "slotPadding" }], }, // …and template literals. { code: "", filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // Member-expression component tails match too. { code: '', filename: APP_FILE, errors: [{ messageId: "slotPadding" }], }, // Card-shell `5` step: bg-card + border + p-5 on one element. { code: '
    ', filename: APP_FILE, errors: [{ messageId: "cardShellStep5" }], }, // …py-5, …space-y-5, …gap-5 on a shell all trip it. { code: '
    ', filename: APP_FILE, errors: [{ messageId: "cardShellStep5" }], }, { code: '
    ', filename: APP_FILE, errors: [{ messageId: "cardShellStep5" }], }, // Split across cn() args — the join still sees the shell + the step-5. { code: '
    ', filename: APP_FILE, errors: [{ messageId: "cardShellStep5" }], }, // Modifier-prefixed step on a shell. { code: '
    ', filename: APP_FILE, errors: [{ messageId: "cardShellStep5" }], }, ], });