import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { RuleTester } from 'eslint' import { parser } from 'typescript-eslint' import { describe, it } from 'vitest' import { noFieldOutsideAForm } from './no-field-outside-a-form' RuleTester.describe = describe RuleTester.it = it RuleTester.itOnly = it.only const tester = new RuleTester({ languageOptions: { parser, parserOptions: { ecmaFeatures: { jsx: true } } }, linterOptions: { reportUnusedDisableDirectives: 'off' }, }) /** An app on disk, so the app's re-exports are followed to their part, as Peek's are. */ const root = mkdtempSync(join(tmpdir(), 'no-field-outside-a-form-')) const write = (path: string, text: string) => { mkdirSync(dirname(join(root, path)), { recursive: true }) writeFileSync(join(root, path), text) } write('app/package.json', '{ "name": "app" }') write('app/src/components/ui/Field.tsx', "export { Field } from '@estiva-app/ui'\n") write('app/src/components/ui/Textarea.tsx', "export { Textarea } from '@estiva-app/ui'\n") write('app/src/components/ui/ConfirmDialog.tsx', "export { ConfirmDialog } from '@estiva-app/ui'\n") const app = join(root, 'app/src/Probe.tsx') const ui = (...parts: string[]) => `import { ${parts.join(', ')} } from '@estiva-app/ui'\n` const component = (body: string, imports = '') => `${imports}export function Probe({ text, set }: { text: string; set: (v: string) => void }) {\n return (\n${body}\n )\n}\n` const loose = (part: string) => [{ messageId: 'loose', data: { part } }] tester.run('no-field-outside-a-form', noFieldOutsideAForm, { valid: [ { name: "Peek's ResolveDialog: a DialogShell with a Form", code: component(' {}}>\n
{}}>\n