Add ESLint rule to disallow barrel/entrypoint imports#21296
Draft
NullVoxPopuli-ai-agent wants to merge 4 commits intoemberjs:mainfrom
Draft
Add ESLint rule to disallow barrel/entrypoint imports#21296NullVoxPopuli-ai-agent wants to merge 4 commits intoemberjs:mainfrom
NullVoxPopuli-ai-agent wants to merge 4 commits intoemberjs:mainfrom
Conversation
Internal source files should import directly from specific lib/ files (e.g., '@ember/-internals/glimmer/lib/renderer') rather than from barrel index files (e.g., '@ember/-internals/glimmer') to enable proper tree-shaking by bundlers. This rule covers @ember/-internals/glimmer and @ember/-internals/environment, and only applies to non-test source files in packages/. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
eslint/rules/no-barrel-imports.js
Outdated
|
|
||
| // Barrel packages that should not be imported directly from source files. | ||
| // Each entry maps a bare package specifier to a human-readable hint. | ||
| const BARREL_PACKAGES = new Map([ |
Contributor
There was a problem hiding this comment.
it's just all of them. and an autofixer should read in the import from the barrel file, and get its real path. an error should still occur if the imported thing is a re-export
Contributor
Author
There was a problem hiding this comment.
Got it — will expand to all barrel imports with auto-fix that traces re-exports to their source files.
The rule now: - Detects ALL barrel imports (any import that resolves to an index.ts), not just a hardcoded list of packages - Provides auto-fix that reads the barrel's index.ts, traces each imported name to its actual source file, and rewrites the import - Groups imports by source file when multiple names come from the same file - Reports without fix for cases it can't trace (export *, namespace imports) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Error messages now show the exact source file paths to import from - export * from barrels are resolved by parsing the source file's exports and expanding to named exports in the auto-fix - export * from single-source barrels are fixed by rewriting the source path - import * as Foo from single-source barrels are also fixable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A barrel is a file that re-exports from other files (has export { } from
or export * from). A standalone module that defines its own exports
(like @ember/template-compilation which defines precompileTemplate
directly) is not a barrel and should not be flagged.
979 errors (down from 1298 — 319 false positives eliminated).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
local/no-barrel-imports) that prevents internal source files from importing from barrel/entrypoint files like@ember/-internals/glimmerand@ember/-internals/environmentpackages/(excludingtests/andtype-tests/) must import directly from specificlib/subpaths (e.g.,@ember/-internals/glimmer/lib/renderer) to enable proper tree-shakingeslint.config.mjs-- no external package neededThis is a regression-prevention measure following the manual barrel import cleanup.
Test plan
packages/@ember/routing/index.ts)tests/directories)index.ts(which uses relative./lib/...imports)lib/that import from their barrelpnpm run lint:eslintafter all barrel imports have been replaced with direct imports (depends on Remove barrel file imports from internal code #21295 landing first)🤖 Generated with Claude Code