Skip to content

Add ESLint rule to disallow barrel/entrypoint imports#21296

Draft
NullVoxPopuli-ai-agent wants to merge 4 commits intoemberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/no-barrel-imports-lint-rule
Draft

Add ESLint rule to disallow barrel/entrypoint imports#21296
NullVoxPopuli-ai-agent wants to merge 4 commits intoemberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/no-barrel-imports-lint-rule

Conversation

@NullVoxPopuli-ai-agent
Copy link
Copy Markdown
Contributor

Summary

  • Adds a custom ESLint rule (local/no-barrel-imports) that prevents internal source files from importing from barrel/entrypoint files like @ember/-internals/glimmer and @ember/-internals/environment
  • Source files in packages/ (excluding tests/ and type-tests/) must import directly from specific lib/ subpaths (e.g., @ember/-internals/glimmer/lib/renderer) to enable proper tree-shaking
  • The rule is registered as a local ESLint plugin in eslint.config.mjs -- no external package needed

This is a regression-prevention measure following the manual barrel import cleanup.

Test plan

  • Verified the rule flags barrel imports in source files (e.g., packages/@ember/routing/index.ts)
  • Verified the rule does NOT flag test files (tests/ directories)
  • Verified the rule does NOT flag the barrel's own index.ts (which uses relative ./lib/... imports)
  • Verified the rule flags files within a package's own lib/ that import from their barrel
  • Run pnpm run lint:eslint after 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

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>

// 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([
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it — will expand to all barrel imports with auto-fix that traces re-exports to their source files.

NullVoxPopuli and others added 3 commits April 4, 2026 01:35
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants