Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(lint): flag package-internal imports through a barrel (#9080)

Cindy Zhangbcb16db0e820
diff --git a/AGENTS.md b/AGENTS.md
index 7a40a28b89..f944dfa24e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -169,6 +169,7 @@ Documentation lives in two places:
- **Testing**: Vitest (colocated tests)
- **Components**: `packages/core/`
- **Storybook**: `apps/storybook/`
+- **Imports inside a package**: import the defining module (`'../List/List'`), never a folder's index barrel (`'../List'`); public consumers import `@astryxdesign/core`. `@astryx/no-internal-barrel-import` enforces it.
## JSDoc Conventions
diff --git a/eslint.config.js b/eslint.config.js
index 3e5b0d70cb..a79a6880a8 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -3,11 +3,13 @@
import {defineConfig} from 'eslint/config';
import {includeIgnoreFile} from '@eslint/compat';
import path from 'node:path';
+import {readFileSync} from 'node:fs';
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintReact from '@eslint-react/eslint-plugin';
import reactCompiler from 'eslint-plugin-react-compiler';
import astryxPlugin from './internal/eslint-plugin-astryx/index.js';
+import {scope as internalBarrelScope} from './internal/eslint-plugin-astryx/no-internal-barrel-import.js';
/* global process */
@@ -31,6 +33,18 @@ const astryxConfig = isStrictMode
: astryxPlugin.configs.recommended;
const reactSeverity = isStrictMode ? 'error' : 'warn';
+// Barrel imports that existed when `@astryx/no-internal-barrel-import` arrived,
+// by repo-relative file. The list only shrinks.
+const internalBarrelBaseline = JSON.parse(
+ readFileSync(
+ path.join(
+ import.meta.dirname,
+ 'internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json',
+ ),
+ 'utf8',
+ ),
+);
+
// The internal plugin is plain untyped JS (kept out of the lint/type surface),
// so its inferred shape doesn't satisfy ESLint's strict `Plugin` type. One
// localized assertion here keeps every `plugins` entry below type-checked.
@@ -848,6 +862,27 @@ export default defineConfig(
'no-restricted-syntax': 'off',
},
},
+ // Inside a package's own shipped source, import the module that defines a
+ // name, not a folder's index (a barrel): a lazily imported module that goes
+ // through a barrel pulls every sibling export into its graph, which broke
+ // the single-file bundle. Public consumers keep importing from the package
+ // entry. The barrel imports that predate the rule are listed in the
+ // baseline and stay allowed until a codemod removes them; anything new is
+ // reported (an error in strict mode, so a pull request that adds one fails
+ // lint, while main stays green). Type-only imports are erased and allowed.
+ {
+ files: internalBarrelScope.files,
+ ignores: internalBarrelScope.ignores,
+ plugins: {
+ '@astryx': astryxEslintPlugin,
+ },
+ rules: {
+ '@astryx/no-internal-barrel-import': [
+ reactSeverity,
+ {baseline: internalBarrelBaseline, root: import.meta.dirname},
+ ],
+ },
+ },
// richtext — the pre-existing backlog, held at `warn` while it is worked
// off. Must come last so it overrides the blocks above.
//
diff --git a/internal/eslint-plugin-astryx/README.md b/internal/eslint-plugin-astryx/README.md
index 7e089cae57..0814f704f3 100644
--- a/internal/eslint-plugin-astryx/README.md
+++ b/internal/eslint-plugin-astryx/README.md
@@ -188,6 +188,28 @@ function useSortedNames(names: string[]) {
}
```
+### `@astryx/no-internal-barrel-import`
+
+Reports a relative import, inside a package's own shipped source, that
+resolves to a folder's index file (a barrel) instead of the module that defines
+what it imports: `import {List} from '../List'` rather than
+`import {List} from '../List/List'`. A barrel pulls every sibling export into
+the importer's module graph, so a lazily imported module that goes through one
+drags unrelated code, and in a single-file bundle import cycles, along with it.
+It checks `import`, `export … from` and literal `import()`; type-only imports
+and exports are erased by the compiler and allowed. Public consumers keep
+importing from the package entry (`@astryxdesign/core`), which this rule never
+reads.
+
+The repo config turns it on for `packages/*/src`, outside tests, stories and
+test helpers, at the strict-mode severity (an error in CI). Barrel imports that
+existed when the rule arrived are listed by file in
+`no-internal-barrel-import.baseline.json` and stay allowed until a codemod
+removes them; remove an entry when you fix its import, and never add one.
+`node internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.mjs`
+rewrites the list from the source (`--check` verifies it), for example after
+merging `main` into this rule's own branch or after a codemod.
+
### `@astryx/no-core-internal-import`
Reports imports of Core's internal subpaths (`@astryxdesign/core/internal` and
diff --git a/internal/eslint-plugin-astryx/index.js b/internal/eslint-plugin-astryx/index.js
index ec3077132d..beea64894f 100644
--- a/internal/eslint-plugin-astryx/index.js
+++ b/internal/eslint-plugin-astryx/index.js
@@ -22,6 +22,7 @@
* - no-unstable-merged-refs: Flags render-time mergeRefs callbacks and unstable callback inputs to useMergedRefs
* - no-light-dark-outside-theme: Flags CSS light-dark() in component source (a light/dark decision belongs to the theme layer, where a token pair reaches both schemes in every theme)
* - no-core-internal-import: Keeps Core's internal subpaths (@astryxdesign/core/internal/*) inside Core and Lab
+ * - no-internal-barrel-import: Flags a package-internal relative import that resolves to a folder's index (a barrel) instead of the defining module
* - no-raw-color: Flags a raw colour value (hex, rgb(), hsl(), oklch(), …) anywhere in component source, including inside light-dark()/color-mix(), behind a const, in a template literal, or as a var() fallback — the shapes no-hardcoded-styles cannot see
*
* Philosophy: Strict for agents (CI), lenient for humans (local dev)
@@ -54,6 +55,7 @@ import noUnstableMergedRefsRule from './no-unstable-merged-refs.js';
import copyrightHeaderRule from './copyright-header.js';
import noRawConsoleCliRule from './no-raw-console-cli.js';
import noCoreInternalImportRule from './no-core-internal-import.js';
+import noInternalBarrelImportRule from './no-internal-barrel-import.js';
import requireBasePropsRule from './require-base-props.js';
import requireRefPropRule from './require-ref-prop.js';
import requireBasePropsPassthroughRule from './require-baseprops-passthrough.js';
@@ -360,6 +362,7 @@ const plugin = {
'copyright-header': copyrightHeaderRule,
'no-raw-console-cli': noRawConsoleCliRule,
'no-core-internal-import': noCoreInternalImportRule,
+ 'no-internal-barrel-import': noInternalBarrelImportRule,
'no-hardcoded-i18n-string': noHardcodedI18nStringRule,
'i18n-key-format': i18nKeyFormatRule,
'require-table-section': requireTableSectionRule,
diff --git a/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json b/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json
new file mode 100644
index 0000000000..65be00675e
--- /dev/null
+++ b/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json
@@ -0,0 +1,721 @@
+{
+ "packages/core/src/AppShell/AppShell.tsx": ["../i18n", "../utils"],
+ "packages/core/src/AspectRatio/AspectRatio.tsx": ["../utils"],
+ "packages/core/src/Avatar/Avatar.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Avatar/AvatarStatusDot.tsx": ["../utils"],
+ "packages/core/src/AvatarGroup/AvatarGroup.tsx": [
+ "../Avatar",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx": [
+ "../Avatar",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Badge/Badge.tsx": ["../utils"],
+ "packages/core/src/Banner/Banner.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Blockquote/Blockquote.tsx": ["../utils"],
+ "packages/core/src/BottomSheet/BottomSheetSwitcher.tsx": ["../utils"],
+ "packages/core/src/Breadcrumbs/BreadcrumbItem.tsx": ["../Icon", "../utils"],
+ "packages/core/src/Breadcrumbs/Breadcrumbs.tsx": ["../i18n", "../utils"],
+ "packages/core/src/ButtonGroup/ButtonGroup.tsx": ["../utils"],
+ "packages/core/src/Calendar/Calendar.tsx": [
+ "../Button",
+ "../Icon",
+ "../VisuallyHidden",
+ "../hooks",
+ "../i18n",
+ "../utils",
+ "./hooks"
+ ],
+ "packages/core/src/Calendar/hooks/useCalendarDays.ts": ["../../i18n"],
+ "packages/core/src/Calendar/hooks/useCalendarNavigation.ts": ["../../i18n"],
+ "packages/core/src/Card/Card.tsx": ["../utils"],
+ "packages/core/src/Carousel/Carousel.tsx": [
+ "../Button",
+ "../Icon",
+ "../Layer",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Center/Center.tsx": ["../utils"],
+ "packages/core/src/Chat/ChatComposer.tsx": ["../Icon", "../i18n", "../utils"],
+ "packages/core/src/Chat/ChatComposerDrawer.tsx": [
+ "../Badge",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatComposerInput.tsx": [
+ "../Badge",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatDictationButton.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatLayout.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Chat/ChatLayoutScrollButton.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatMessage.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Chat/ChatMessageBubble.tsx": ["../utils"],
+ "packages/core/src/Chat/ChatMessageList.tsx": [
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatMessageMetadata.tsx": [
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatPastedTextToken.tsx": [
+ "../Badge",
+ "../Button",
+ "../HoverCard",
+ "../i18n"
+ ],
+ "packages/core/src/Chat/ChatSendButton.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/ChatSystemMessage.tsx": ["../Divider", "../utils"],
+ "packages/core/src/Chat/ChatTokenizedText.tsx": ["../Badge", "../utils"],
+ "packages/core/src/Chat/ChatToolCalls.tsx": [
+ "../Badge",
+ "../Icon",
+ "../Spinner",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Chat/useSpeechRecognition.ts": ["../i18n"],
+ "packages/core/src/Chat/useTriggerMenu.tsx": ["../i18n", "../utils"],
+ "packages/core/src/CheckboxList/CheckboxList.tsx": ["../Tooltip", "../utils"],
+ "packages/core/src/CheckboxList/CheckboxListItem.tsx": ["../i18n"],
+ "packages/core/src/Citation/Citation.tsx": ["../Icon", "../i18n", "../utils"],
+ "packages/core/src/ClickableCard/ClickableCard.tsx": ["../utils"],
+ "packages/core/src/Code/Code.tsx": ["../utils"],
+ "packages/core/src/CodeBlock/CodeBlock.tsx": [
+ "../Icon",
+ "../IconButton",
+ "../i18n",
+ "../theme/syntax",
+ "../utils"
+ ],
+ "packages/core/src/CodeBlock/highlightStyles.ts": ["../theme"],
+ "packages/core/src/Collapsible/Collapsible.tsx": ["../Icon", "../utils"],
+ "packages/core/src/Collapsible/CollapsibleGroup.tsx": ["../utils"],
+ "packages/core/src/CommandPalette/CommandPalette.tsx": [
+ "../Dialog",
+ "../Layout",
+ "../Selector",
+ "../i18n"
+ ],
+ "packages/core/src/CommandPalette/CommandPaletteEmpty.tsx": ["../utils"],
+ "packages/core/src/CommandPalette/CommandPaletteFooter.tsx": [
+ "../Kbd",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/CommandPalette/CommandPaletteGroup.tsx": ["../utils"],
+ "packages/core/src/CommandPalette/CommandPaletteInput.tsx": [
+ "../Icon",
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/CommandPalette/CommandPaletteItem.tsx": ["../utils"],
+ "packages/core/src/CommandPalette/CommandPaletteList.tsx": [
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/ComplexSelector/ComplexSelector.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/ContextMenu/ContextMenu.tsx": [
+ "../Button",
+ "../Heading",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateInput/DateInput.tsx": [
+ "../Calendar",
+ "../Calendar/hooks",
+ "../Field",
+ "../Icon",
+ "../Popover",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateInput/MonthScroller.tsx": [
+ "../Calendar",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateInput/MonthYearWheels.tsx": ["../i18n", "../utils"],
+ "packages/core/src/DateInput/NativeDateField.tsx": [
+ "../Calendar",
+ "../Field",
+ "../Icon",
+ "../InputGroup",
+ "../SizeContext",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../hooks",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateInput/TouchDateField.tsx": [
+ "../BottomSheet",
+ "../Button",
+ "../Calendar",
+ "../Field",
+ "../Icon",
+ "../IconButton",
+ "../InputGroup",
+ "../SizeContext",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../hooks",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateInput/Wheel.tsx": ["../utils"],
+ "packages/core/src/DateRangeInput/DateRangeInput.tsx": [
+ "../Calendar",
+ "../Calendar/hooks",
+ "../Field",
+ "../Icon",
+ "../Popover",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateTimeInput/DateTimeInput.tsx": [
+ "../Calendar",
+ "../Calendar/hooks",
+ "../Field",
+ "../Icon",
+ "../Popover",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateTimeInput/NativeDateSegment.tsx": [
+ "../Icon",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateTimeInput/NativeTimeSegment.tsx": [
+ "../Icon",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DateTimeInput/TouchDateTimeField.tsx": [
+ "../BottomSheet",
+ "../Button",
+ "../Calendar",
+ "../Field",
+ "../Icon",
+ "../IconButton",
+ "../SegmentedControl",
+ "../Spinner",
+ "../Tooltip",
+ "../hooks",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Drawer/Drawer.tsx": [
+ "../Layer",
+ "../Layout",
+ "../hooks",
+ "../utils"
+ ],
+ "packages/core/src/Drawer/DrawerHeader.tsx": [
+ "../Button",
+ "../Heading",
+ "../Icon",
+ "../Layout",
+ "../Text",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/DropdownMenu.tsx": [
+ "../Button",
+ "../Heading",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx": [
+ "../Icon",
+ "../Indicator",
+ "../Item",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/DropdownMenuDivider.tsx": ["../Divider"],
+ "packages/core/src/DropdownMenu/DropdownMenuGroup.tsx": ["../utils"],
+ "packages/core/src/DropdownMenu/DropdownMenuItem.tsx": [
+ "../Icon",
+ "../Item",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/DropdownMenuRadioGroup.tsx": ["../utils"],
+ "packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx": [
+ "../Icon",
+ "../Indicator",
+ "../Item",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx": [
+ "../Icon",
+ "../Item",
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/DropdownMenu/renderDropdownItems.tsx": ["../utils"],
+ "packages/core/src/Field/Field.tsx": ["../VisuallyHidden", "../utils"],
+ "packages/core/src/FileInput/FileInput.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/FormLayout/FormLayout.tsx": ["../utils"],
+ "packages/core/src/Grid/Grid.tsx": ["../utils"],
+ "packages/core/src/Grid/GridSpan.tsx": ["../utils"],
+ "packages/core/src/InputGroup/InputGroup.tsx": ["../Field", "../utils"],
+ "packages/core/src/InputGroup/InputGroupText.tsx": ["../utils"],
+ "packages/core/src/Kbd/Kbd.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Layout/LayoutPanel.tsx": ["../utils"],
+ "packages/core/src/Lightbox/Lightbox.tsx": [
+ "../Icon",
+ "../IconButton",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Link/Link.tsx": [
+ "../Icon",
+ "../Text",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Markdown/Markdown.fr23.bench.ts": ["./plugins"],
+ "packages/core/src/Markdown/Markdown.tsx": [
+ "../CodeBlock",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Markdown/plugins/HeadingLinksRenderer.tsx": [
+ "../../Icon",
+ "../../i18n",
+ "../../utils"
+ ],
+ "packages/core/src/MetadataList/MetadataList.tsx": ["../i18n", "../utils"],
+ "packages/core/src/MetadataList/MetadataListItem.tsx": ["../utils"],
+ "packages/core/src/MobileNav/MobileNav.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/MobileNav/MobileNavToggle.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/MoreMenu/MoreMenu.tsx": ["../Icon", "../i18n"],
+ "packages/core/src/MultiSelector/MultiSelector.tsx": [
+ "../Badge",
+ "../CheckboxInput",
+ "../Divider",
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/NavIcon/NavIcon.tsx": ["../utils"],
+ "packages/core/src/NavMenu/NavHeadingMenu.tsx": ["../utils"],
+ "packages/core/src/NavMenu/NavHeadingMenuItem.tsx": [
+ "../Icon",
+ "../Text",
+ "../utils"
+ ],
+ "packages/core/src/NumberInput/NumberInput.tsx": [
+ "../Field",
+ "../Icon",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Outline/Outline.tsx": ["../i18n", "../utils"],
+ "packages/core/src/OverflowList/OverflowList.tsx": ["../utils"],
+ "packages/core/src/Overlay/Overlay.tsx": ["../utils"],
+ "packages/core/src/Overlay/OverlayScrim.tsx": ["../utils"],
+ "packages/core/src/Pagination/Pagination.tsx": [
+ "../Button",
+ "../Icon",
+ "../NumberInput",
+ "../Selector",
+ "../Text",
+ "../utils"
+ ],
+ "packages/core/src/Popover/Popover.tsx": ["../Button", "../i18n"],
+ "packages/core/src/Popover/usePopover.tsx": [
+ "../Button",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/PowerSearch/PowerSearch.tsx": [
+ "../Avatar",
+ "../Icon",
+ "../Token",
+ "../Tokenizer",
+ "../i18n"
+ ],
+ "packages/core/src/PowerSearch/PowerSearchEditPopover.tsx": [
+ "../Button",
+ "../Icon",
+ "../Selector",
+ "../Stack",
+ "../TreeList",
+ "../i18n"
+ ],
+ "packages/core/src/PowerSearch/PowerSearchToken.tsx": ["../Token", "../i18n"],
+ "packages/core/src/PowerSearch/PowerSearchValueEditor.tsx": [
+ "../DateInput",
+ "../DateRangeInput",
+ "../NumberInput",
+ "../Selector",
+ "../TextInput",
+ "../TimeInput",
+ "../Tokenizer",
+ "../Typeahead",
+ "../i18n"
+ ],
+ "packages/core/src/PowerSearch/usePowerSearchSource.ts": [
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/ProgressBar/ProgressBar.tsx": [
+ "../VisuallyHidden",
+ "../utils"
+ ],
+ "packages/core/src/RadioList/RadioList.tsx": ["../Tooltip", "../utils"],
+ "packages/core/src/RadioList/RadioListItem.tsx": [
+ "../Indicator",
+ "../Item",
+ "../utils"
+ ],
+ "packages/core/src/Resizable/ResizeHandle.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Section/Section.tsx": ["../utils"],
+ "packages/core/src/SegmentedControl/SegmentedControl.tsx": [
+ "../Tooltip",
+ "../utils"
+ ],
+ "packages/core/src/SegmentedControl/SegmentedControlItem.tsx": ["../utils"],
+ "packages/core/src/SelectableCard/SelectableCard.tsx": ["../utils"],
+ "packages/core/src/Selector/Selector.tsx": [
+ "../Divider",
+ "../Field",
+ "../Icon",
+ "../Indicator",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Selector/SelectorBottomSheet.tsx": [
+ "../Heading",
+ "../Section"
+ ],
+ "packages/core/src/Selector/SelectorOption.tsx": [
+ "../Icon",
+ "../Item",
+ "../utils"
+ ],
+ "packages/core/src/SideNav/SideNav.tsx": ["../i18n", "../utils"],
+ "packages/core/src/SideNav/SideNavCollapseButton.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/SideNav/SideNavHeading.tsx": [
+ "../Icon",
+ "../Link",
+ "../Tooltip",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/SideNav/SideNavItem.tsx": [
+ "../Icon",
+ "../Tooltip",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/SideNav/SideNavSection.tsx": [
+ "../VisuallyHidden",
+ "../utils"
+ ],
+ "packages/core/src/Skeleton/Skeleton.tsx": ["../utils"],
+ "packages/core/src/Slider/Slider.tsx": [
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/StatusDot/StatusDot.tsx": ["../utils"],
+ "packages/core/src/Stepper/Step.tsx": [
+ "../Icon",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Stepper/Stepper.tsx": [
+ "../Icon",
+ "../IconButton",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Switch/Switch.tsx": [
+ "../Spinner",
+ "../Tooltip",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/TabList/Tab.tsx": ["../utils"],
+ "packages/core/src/TabList/TabList.tsx": ["../Icon", "../i18n", "../utils"],
+ "packages/core/src/TabList/TabMenu.tsx": ["../Icon", "../utils"],
+ "packages/core/src/Table/BaseTable.tsx": [
+ "../EmptyState",
+ "../Text",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Table/Table.tsx": ["../i18n", "../utils"],
+ "packages/core/src/Table/TableBody.tsx": ["../utils"],
+ "packages/core/src/Table/TableCell.tsx": ["../utils"],
+ "packages/core/src/Table/TableFooter.tsx": ["../utils"],
+ "packages/core/src/Table/TableHeader.tsx": ["../utils"],
+ "packages/core/src/Table/TableHeaderCell.tsx": ["../utils"],
+ "packages/core/src/Table/TableRow.tsx": ["../utils"],
+ "packages/core/src/Table/TableSelectionToolbar.tsx": [
+ "../Button",
+ "../Toolbar",
+ "../i18n"
+ ],
+ "packages/core/src/Table/plugins/columnResize/useTableColumnResize.tsx": [
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/filtering/useTableFiltering.tsx": [
+ "../../../Button",
+ "../../../DateInput",
+ "../../../Icon",
+ "../../../MultiSelector",
+ "../../../NumberInput",
+ "../../../Popover",
+ "../../../Selector",
+ "../../../TextInput",
+ "../../../TimeInput",
+ "../../../Tokenizer",
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx": [
+ "../../../Icon",
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/pagination/useTablePagination.tsx": [
+ "../../../Pagination",
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx": [
+ "../../../Icon",
+ "../../../VisuallyHidden",
+ "../../../i18n",
+ "../../../utils"
+ ],
+ "packages/core/src/Table/plugins/rowStatus/useTableRowStatus.tsx": [
+ "../../../Icon",
+ "../../../Tooltip",
+ "../../../VisuallyHidden",
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/selection/useTableSelection.tsx": [
+ "../../../CheckboxInput",
+ "../../../i18n",
+ "../../../utils"
+ ],
+ "packages/core/src/Table/plugins/sortable/useTableSortable.tsx": [
+ "../../../Icon",
+ "../../../i18n"
+ ],
+ "packages/core/src/Table/plugins/tree/useTableTreeData.tsx": [
+ "../../../Icon",
+ "../../../i18n",
+ "../../../utils"
+ ],
+ "packages/core/src/Table/tableContextMenu.tsx": ["../ContextMenu", "../Icon"],
+ "packages/core/src/TextArea/TextArea.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/TextInput/TextInput.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Thumbnail/Thumbnail.tsx": [
+ "../Button",
+ "../Icon",
+ "../Skeleton",
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/TimeInput/TimeInput.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/TimeInput/TouchTimeField.tsx": [
+ "../BottomSheet",
+ "../Button",
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Tooltip",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Timer/Timer.tsx": ["../Text", "../utils"],
+ "packages/core/src/Timestamp/Timestamp.tsx": [
+ "../Text",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Toast/Toast.tsx": [
+ "../Button",
+ "../Icon",
+ "../i18n",
+ "../theme",
+ "../utils"
+ ],
+ "packages/core/src/Toast/ToastViewport.tsx": ["../i18n", "../utils"],
+ "packages/core/src/ToggleButton/ToggleButton.tsx": ["../Button"],
+ "packages/core/src/ToggleButton/ToggleButtonGroup.tsx": ["../utils"],
+ "packages/core/src/Token/Token.tsx": ["../Icon", "../i18n", "../utils"],
+ "packages/core/src/Token/TokenLink.tsx": ["../utils"],
+ "packages/core/src/Tokenizer/Tokenizer.tsx": [
+ "../Field",
+ "../Icon",
+ "../OverflowList",
+ "../Spinner",
+ "../Token",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Toolbar/Toolbar.tsx": ["../utils"],
+ "packages/core/src/TopNav/TopNav.tsx": ["../i18n", "../utils"],
+ "packages/core/src/TopNav/TopNavHeading.tsx": [
+ "../Icon",
+ "../Link",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/TopNav/TopNavItem.tsx": ["../utils"],
+ "packages/core/src/TopNav/TopNavMegaMenu.tsx": ["../Icon", "../utils"],
+ "packages/core/src/TopNav/TopNavMegaMenuFeaturedCard.tsx": ["../utils"],
+ "packages/core/src/TopNav/TopNavMegaMenuItem.tsx": ["../utils"],
+ "packages/core/src/TopNav/TopNavMenu.tsx": ["../Icon", "../utils"],
+ "packages/core/src/TreeList/TreeList.tsx": ["../utils"],
+ "packages/core/src/TreeList/TreeListBranches.tsx": ["../utils"],
+ "packages/core/src/TreeList/TreeListItem.tsx": [
+ "../Icon",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Typeahead/BaseTypeahead.tsx": [
+ "../Icon",
+ "../Spinner",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Typeahead/Typeahead.tsx": [
+ "../Field",
+ "../Icon",
+ "../Spinner",
+ "../Token",
+ "../Tooltip",
+ "../VisuallyHidden",
+ "../i18n",
+ "../utils"
+ ],
+ "packages/core/src/Typeahead/TypeaheadItem.tsx": ["../utils"],
+ "packages/core/src/hooks/useInputStatusIcon.tsx": [
+ "../Icon",
+ "../Tooltip",
+ "../i18n"
+ ],
+ "packages/core/src/hooks/useKeyboardHint.tsx": ["../Kbd", "../i18n"],
+ "packages/lab/src/Comments/CommentComposer.tsx": ["../EmojiPicker"],
+ "packages/lab/src/Schedule/Schedule.tsx": ["./plugins"]
+}
diff --git a/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.mjs b/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.mjs
new file mode 100644
index 0000000000..1b267bef86
--- /dev/null
+++ b/internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.mjs
@@ -0,0 +1,87 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file no-internal-barrel-import.baseline.mjs
+ * @description Writes (or, with --check, verifies) the baseline of barrel
+ * imports that `@astryx/no-internal-barrel-import` allows: every relative
+ * import in shipped `packages/*\/src` source that resolves to a folder's index
+ * today. Run it after merging main into a branch that changes the rule's
+ * scope, or after a codemod removes barrel imports, so the list only ever
+ * names imports that still exist.
+ *
+ * node internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.mjs [--check]
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+import {ESLint} from 'eslint';
+import {scope} from './no-internal-barrel-import.js';
+
+const root = path.resolve(import.meta.dirname, '../..');
+const baselineFile = path.join(
+ import.meta.dirname,
+ 'no-internal-barrel-import.baseline.json',
+);
+const ruleId = '@astryx/no-internal-barrel-import';
+
+// Lint with the repo config, but with an empty baseline, so every barrel
+// import in scope is reported once.
+const eslint = new ESLint({
+ cwd: root,
+ // Some packages' sources are ignored by the repo config entirely.
+ errorOnUnmatchedPattern: false,
+ ruleFilter: ({ruleId: id}) => id === ruleId,
+ overrideConfig: [
+ {
+ files: scope.files,
+ ignores: scope.ignores,
+ rules: {[ruleId]: ['error', {baseline: {}, root}]},
+ },
+ ],
+});
+const packages = fs
+ .readdirSync(path.join(root, 'packages'))
+ .filter(name => fs.existsSync(path.join(root, 'packages', name, 'src')))
+ .map(name => `packages/${name}/src`);
+const results = await eslint.lintFiles(packages);
+
+const found = new Map();
+for (const result of results) {
+ for (const message of result.messages) {
+ if (message.ruleId !== ruleId) {
+ continue;
+ }
+ const source = /'([^']+)'/.exec(message.message)?.[1];
+ const file = path.relative(root, result.filePath).split(path.sep).join('/');
+ if (source != null) {
+ if (!found.has(file)) {
+ found.set(file, new Set());
+ }
+ found.get(file).add(source);
+ }
+ }
+}
+const baseline = Object.fromEntries(
+ [...found.keys()].sort().map(file => [file, [...found.get(file)].sort()]),
+);
+const text = `${JSON.stringify(baseline, null, 2)}\n`;
+
+if (process.argv.includes('--check')) {
+ const current = fs.readFileSync(baselineFile, 'utf8');
+ if (JSON.stringify(JSON.parse(current)) !== JSON.stringify(baseline)) {
+ console.error(
+ 'no-internal-barrel-import baseline is out of date; run this script without --check.',
+ );
+ process.exit(1);
+ }
+ console.log('no-internal-barrel-import baseline is up to date.');
+} else {
+ fs.writeFileSync(baselineFile, text);
+ const imports = Object.values(baseline).reduce(
+ (n, list) => n + list.length,
+ 0,
+ );
+ console.log(
+ `Wrote ${imports} barrel imports in ${found.size} files to ${path.relative(root, baselineFile)}.`,
+ );
+}
diff --git a/internal/eslint-plugin-astryx/no-internal-barrel-import.js b/internal/eslint-plugin-astryx/no-internal-barrel-import.js
new file mode 100644
index 0000000000..ddd0df7ae5
--- /dev/null
+++ b/internal/eslint-plugin-astryx/no-internal-barrel-import.js
@@ -0,0 +1,199 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file no-internal-barrel-import.js
+ * @description Reports a relative import, inside a package's own source, that
+ * resolves to a folder's index file (a barrel) rather than to the module that
+ * defines what it imports: `import {List} from '../List'` instead of
+ * `import {List} from '../List/List'`. A barrel pulls every sibling export into
+ * the importer's module graph, so a lazily imported module that goes through
+ * one drags unrelated code (and, in a single-file bundle, import cycles) with
+ * it. Public consumers keep importing from the package entry
+ * (`@astryxdesign/core`); this rule only reads relative specifiers.
+ *
+ * Reported, for `import`, `export … from` and `import()` with a literal
+ * specifier: a `./` or `../` path that names a directory holding an
+ * `index.{ts,tsx,js,jsx,mjs}` and no same-named module file. Type-only
+ * imports and exports are left alone, since the compiler erases them.
+ *
+ * Options: `{baseline: {[repoRelativeFile]: string[]}, root: string}`.
+ * `baseline` lists barrel imports that already existed when the rule was
+ * introduced; those stay allowed, file by file and specifier by specifier, so
+ * the rule catches new barrel imports without failing on the existing ones.
+ * The list only shrinks. Its keys are relative to `root`, the repository root
+ * (default: the directory ESLint runs from), so linting from a package
+ * directory finds the same entries.
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+
+/**
+ * Where the repo config turns the rule on: shipped package source. Tests,
+ * stories and test helpers never ship, so they may import barrels; a barrel
+ * itself (a folder's or a package's index) is the public surface and may
+ * re-export from other barrels (`architecture:public-component-api`). Shared
+ * with the baseline script so both lint the same files.
+ */
+export const scope = {
+ files: ['packages/*/src/**/*.{ts,tsx,mts,cts,js,jsx,mjs}'],
+ ignores: [
+ '**/index.*',
+ '**/*.test.*',
+ '**/*.spec.*',
+ '**/*.stories.*',
+ '**/*.testing.*',
+ '**/*.render-testing.*',
+ '**/__tests__/**',
+ '**/__fixtures__/**',
+ '**/dist/**',
+ ],
+};
+
+const MODULE_EXTENSIONS = [
+ '.ts',
+ '.tsx',
+ '.mts',
+ '.cts',
+ '.js',
+ '.jsx',
+ '.mjs',
+];
+const INDEX_FILES = MODULE_EXTENSIONS.map(extension => `index${extension}`);
+
+function isFile(file) {
+ try {
+ return fs.statSync(file).isFile();
+ } catch {
+ return false;
+ }
+}
+
+function isDirectory(directory) {
+ try {
+ return fs.statSync(directory).isDirectory();
+ } catch {
+ return false;
+ }
+}
+
+/**
+ * Whether a relative specifier, imported from `importer`, resolves to a
+ * folder's index rather than to a module file.
+ *
+ * @param {string} importer absolute path of the importing file
+ * @param {string} specifier the import's source string
+ * @returns {boolean}
+ */
+export function resolvesToBarrel(importer, specifier) {
+ if (!(
+ specifier === '.' ||
+ specifier === '..' ||
+ /^\.\.?\//.test(specifier)
+ )) {
+ return false;
+ }
+ const target = path.resolve(path.dirname(importer), specifier);
+ // Naming the index itself still reaches the barrel: '../List/index',
+ // '../List/index.ts', or '../List/index.js', which TypeScript resolves to
+ // index.ts.
+ const base = path.basename(target);
+ if (
+ (base === 'index' || INDEX_FILES.includes(base)) &&
+ INDEX_FILES.some(index => isFile(path.join(path.dirname(target), index)))
+ ) {
+ return true;
+ }
+ if (isFile(target)) {
+ return false;
+ }
+ if (MODULE_EXTENSIONS.some(extension => isFile(target + extension))) {
+ return false;
+ }
+ return (
+ isDirectory(target) &&
+ INDEX_FILES.some(index => isFile(path.join(target, index)))
+ );
+}
+
+function isTypeOnly(node) {
+ if (node.importKind === 'type' || node.exportKind === 'type') {
+ return true;
+ }
+ const specifiers = node.specifiers ?? [];
+ return (
+ specifiers.length > 0 &&
+ specifiers.every(
+ specifier =>
+ specifier.importKind === 'type' || specifier.exportKind === 'type',
+ )
+ );
+}
+
+const rule = {
+ meta: {
+ type: 'problem',
+ docs: {
+ description:
+ "Disallow package-internal imports through a folder's index (barrel); import the defining module",
+ },
+ schema: [
+ {
+ type: 'object',
+ properties: {
+ baseline: {
+ type: 'object',
+ additionalProperties: {type: 'array', items: {type: 'string'}},
+ },
+ root: {type: 'string'},
+ },
+ additionalProperties: false,
+ },
+ ],
+ messages: {
+ barrel:
+ "'{{source}}' resolves to a folder's index (a barrel). Inside a package, import the module that defines it (for example '../List/List', not '../List'), so a lazily imported module does not pull in every sibling export.",
+ },
+ },
+ create(context) {
+ const filename = context.filename;
+ const baseline = context.options[0]?.baseline ?? {};
+ const root = context.options[0]?.root ?? context.cwd;
+ const relative = path.relative(root, filename).split(path.sep).join('/');
+ const allowed = new Set(baseline[relative] ?? []);
+
+ function check(node, source) {
+ if (typeof source !== 'string' || allowed.has(source)) {
+ return;
+ }
+ if (resolvesToBarrel(filename, source)) {
+ context.report({node, messageId: 'barrel', data: {source}});
+ }
+ }
+
+ return {
+ ImportDeclaration(node) {
+ if (!isTypeOnly(node)) {
+ check(node.source, node.source.value);
+ }
+ },
+ ExportNamedDeclaration(node) {
+ if (node.source != null && !isTypeOnly(node)) {
+ check(node.source, node.source.value);
+ }
+ },
+ ExportAllDeclaration(node) {
+ if (node.exportKind !== 'type') {
+ check(node.source, node.source.value);
+ }
+ },
+ ImportExpression(node) {
+ if (node.source.type === 'Literal') {
+ check(node.source, node.source.value);
+ }
+ },
+ };
+ },
+};
+
+export default rule;
diff --git a/internal/eslint-plugin-astryx/no-internal-barrel-import.test.mjs b/internal/eslint-plugin-astryx/no-internal-barrel-import.test.mjs
new file mode 100644
index 0000000000..5600b922b2
--- /dev/null
+++ b/internal/eslint-plugin-astryx/no-internal-barrel-import.test.mjs
@@ -0,0 +1,135 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file no-internal-barrel-import.test.mjs
+ */
+
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import {RuleTester} from 'eslint';
+import tseslint from 'typescript-eslint';
+import rule from './no-internal-barrel-import.js';
+
+// A miniature package: `List/` is a barrel over `List/List.tsx`, `utils.ts`
+// is a plain module, and `Thing/` has no index at all.
+const root = fs.mkdtempSync(path.join(os.tmpdir(), 'barrel-rule-'));
+const write = (file, text = 'export {};\n') => {
+ fs.mkdirSync(path.dirname(path.join(root, file)), {recursive: true});
+ fs.writeFileSync(path.join(root, file), text);
+};
+write('src/List/index.ts', "export {List} from './List';\n");
+write('src/List/List.tsx');
+write('src/List/ListItem.tsx');
+write('src/utils.ts');
+write('src/Thing/Thing.tsx');
+write('src/index.ts');
+write('src/Menu/Menu.tsx');
+
+const importer = path.join(root, 'src/Menu/Menu.tsx');
+const fromCwd = path
+ .relative(process.cwd(), importer)
+ .split(path.sep)
+ .join('/');
+
+const ruleTester = new RuleTester({
+ languageOptions: {
+ parser: tseslint.parser,
+ ecmaVersion: 2022,
+ sourceType: 'module',
+ },
+});
+
+const message = source =>
+ `'${source}' resolves to a folder's index (a barrel). Inside a package, import the module that defines it (for example '../List/List', not '../List'), so a lazily imported module does not pull in every sibling export.`;
+
+ruleTester.run('no-internal-barrel-import', rule, {
+ valid: [
+ // The defining module.
+ {code: `import {List} from '../List/List';`, filename: importer},
+ {code: `import {ListItem} from '../List/ListItem';`, filename: importer},
+ // A plain module file, and a directory with no index.
+ {code: `import {x} from '../utils';`, filename: importer},
+ {code: `import {x} from '../Thing/Thing';`, filename: importer},
+ // Public consumers import the package entry; only relative paths count.
+ {code: `import {List} from '@astryxdesign/core';`, filename: importer},
+ {code: `import {List} from '@astryxdesign/core/List';`, filename: importer},
+ // Type-only imports and exports are erased by the compiler.
+ {code: `import type {ListProps} from '../List';`, filename: importer},
+ {code: `import {type ListProps} from '../List';`, filename: importer},
+ {code: `export type {ListProps} from '../List';`, filename: importer},
+ // A barrel import that existed when the rule arrived stays allowed.
+ {
+ code: `import {List} from '../List';`,
+ filename: importer,
+ options: [{baseline: {[fromCwd]: ['../List']}}],
+ },
+ // Baseline keys are relative to `root`, wherever ESLint runs from.
+ {
+ code: `import {List} from '../List';`,
+ filename: importer,
+ options: [{baseline: {'src/Menu/Menu.tsx': ['../List']}, root}],
+ },
+ // A `.js` specifier for an ordinary module is not a barrel.
+ {code: `import {List} from '../List/List.js';`, filename: importer},
+ // A computed dynamic import is not a literal path.
+ {code: `const m = import(name);`, filename: importer},
+ ],
+ invalid: [
+ {
+ code: `import {List, ListItem} from '../List';`,
+ filename: importer,
+ errors: [{message: message('../List')}],
+ },
+ {
+ code: `import {List, type ListProps} from '../List';`,
+ filename: importer,
+ errors: [{message: message('../List')}],
+ },
+ {
+ code: `export {List} from '../List';`,
+ filename: importer,
+ errors: [{message: message('../List')}],
+ },
+ {
+ code: `export * from '../List';`,
+ filename: importer,
+ errors: [{message: message('../List')}],
+ },
+ {
+ code: `const lazy = () => import('../List');`,
+ filename: importer,
+ errors: [{message: message('../List')}],
+ },
+ // The package's own root index is a barrel too.
+ {
+ code: `import {x} from '..';`,
+ filename: importer,
+ errors: [{message: message('..')}],
+ },
+ // Naming the index file still reaches the barrel.
+ {
+ code: `import {List} from '../List/index';`,
+ filename: importer,
+ errors: [{message: message('../List/index')}],
+ },
+ // A `.js` specifier TypeScript maps onto index.ts.
+ {
+ code: `import {List} from '../List/index.js';`,
+ filename: importer,
+ errors: [{message: message('../List/index.js')}],
+ },
+ {
+ code: `const lazy = () => import('../List/index.ts');`,
+ filename: importer,
+ errors: [{message: message('../List/index.ts')}],
+ },
+ // The baseline allows only the listed file and specifier.
+ {
+ code: `import {List} from '../List';`,
+ filename: importer,
+ options: [{baseline: {'src/Other/Other.tsx': ['../List']}}],
+ errors: [{message: message('../List')}],
+ },
+ ],
+});