import { readdirSync, readFileSync } from 'node:fs' import { createRequire } from 'node:module' import { RuleTester } from 'eslint' import ts from 'typescript' import { parser } from 'typescript-eslint' import { describe, expect, it } from 'vitest' import { BASE_UI_PARTS, baseUiModule, noRebuiltBehaviour, OWNED_BEHAVIOURS, ROLE_PARTS, utilityOf, WALKING_KEYS, } from './no-rebuilt-behaviour' RuleTester.describe = describe RuleTester.it = it RuleTester.itOnly = it.only const tester = new RuleTester({ languageOptions: { parser, parserOptions: { ecmaFeatures: { jsx: true } } }, linterOptions: { reportUnusedDisableDirectives: 'off' }, }) const component = (body: string) => `export function Probe() {\n return (\n${body}\n )\n}\n` const effect = (body: string) => `useEffect(() => {\n${body}\n}, [])\n` const LIST = ' To pick several, `ChipInput`; to search and act, `CommandPalette`; to tick several in a list, `Checkbox` with `row`; for the list a text editor opens as you type, `SuggestionMenu`.' tester.run('no-rebuilt-behaviour', noRebuiltBehaviour, { valid: [ // Base UI and portals { name: 'a part from the package', code: "import { Select, Popover } from '@estiva-app/ui'" }, { name: 'react-dom without createPortal', code: "import { flushSync } from 'react-dom'\nflushSync(() => {})" }, { name: 'a package whose name only starts like Base UI', code: "import x from '@base-uix/react'" }, // listeners { name: 'the window coming back is not a floating part', code: effect(" window.addEventListener('focus', refresh)\n document.addEventListener('visibilitychange', refresh)\n window.addEventListener('storage', sync)") }, { name: 'a listener on an element, not the page', code: effect(" ref.current.addEventListener('keydown', onKey)") }, { name: 'an event the code computes', code: effect(' document.addEventListener(name, handler)') }, { name: "the app's own event on window", code: effect(" window.addEventListener('highlight-tag-click', open)") }, // keys { name: 'Enter and Escape in a field are typing', code: "const onKeyDown = (e) => {\n if (e.key === 'Enter') send()\n if (e.key === 'Escape') cancel()\n}" }, { name: 'a shortcut letter', code: "const onKeyDown = (e) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') open()\n}" }, { name: 'the word ArrowDown that is not a key', code: "const label = 'ArrowDown'\nif (label === 'ArrowDown') go()" }, // roles { name: 'role img on an svg', code: component(' ') }, { name: 'the roles that describe rather than behave', code: component('
measured
') }, { name: 'tabIndex on a control', code: component('