|
| 1 | +'use client'; |
| 2 | +import { useScopedUI } from '@react-zero-ui/core'; |
| 3 | + |
| 4 | +/** |
| 5 | + * This component is intentionally WRONG. |
| 6 | + * – Missing data-attr on <section> |
| 7 | + * – Missing ref attachment on <aside> |
| 8 | + * |
| 9 | + * The Zero-UI ESLint rule should flag both. |
| 10 | + */ |
| 11 | +export default function LintFailures() { |
| 12 | + // #1 Setter attached but no data-scope attr → missingAttr error |
| 13 | + const [scope, setScope] = useScopedUI<'off' | 'on'>('scope', 'off'); |
| 14 | + |
| 15 | + // #2 No ref at all → missingRef error |
| 16 | + const [, setDialog] = useScopedUI<'open' | 'closed'>('dialog', 'closed'); |
| 17 | + |
| 18 | + return ( |
| 19 | + <main className="space-y-6 p-6"> |
| 20 | + {/* ❌ lint error expected here */} |
| 21 | + <section |
| 22 | + ref={setScope.ref} |
| 23 | + className="scope-off:bg-red-100 scope-on:bg-red-600 scope-on:text-white p-4 rounded"> |
| 24 | + <button |
| 25 | + className="border px-3 py-1" |
| 26 | + onClick={() => setScope((prev) => (prev === 'on' ? 'off' : 'on'))}> |
| 27 | + Toggle scope |
| 28 | + </button> |
| 29 | + </section> |
| 30 | + |
| 31 | + {/* ❌ second lint error (missing .ref) */} |
| 32 | + <aside className="dialog-open:block dialog-closed:hidden"> |
| 33 | + This dialog was never linked via <code>ref</code> |
| 34 | + </aside> |
| 35 | + </main> |
| 36 | + ); |
| 37 | +} |
| 38 | + |
| 39 | +/* ------------------------------------------------------------------ * |
| 40 | + | Correct version (for reference) | |
| 41 | + * ------------------------------------------------------------------ * |
| 42 | + const [scope, setScope] = useScopedUI<'off' | 'on'>('scope', 'off'); |
| 43 | + <section |
| 44 | + data-scope={scope} |
| 45 | + ref={setScope.ref} |
| 46 | + > |
| 47 | + … |
| 48 | + </section> |
| 49 | +
|
| 50 | + const [, setDialog] = useScopedUI<'open'|'closed'>('dialog','closed'); |
| 51 | + <aside ref={setDialog.ref} data-dialog="closed">…</aside> |
| 52 | +*/ |
0 commit comments