Skip to content

Feat/sub barrel files#249

Open
alilaa wants to merge 5 commits intosoftarc-consulting:mainfrom
alilaa:feat/sub-barrel-files
Open

Feat/sub barrel files#249
alilaa wants to merge 5 commits intosoftarc-consulting:mainfrom
alilaa:feat/sub-barrel-files

Conversation

@alilaa
Copy link
Copy Markdown

@alilaa alilaa commented Apr 16, 2026

Summary

This is a suggested implementation to resolve Support multiple entry files for a single module

Adds opt-in support for sub-barrel files — additional module entry points that follow the naming convention <barrelBaseName>.<suffix>.<ext>.

For example, with barrelFileName: 'public-api.ts', files like public-api.routing.ts and public-api.bookmarks.ts are recognized as valid imports without triggering encapsulation violations.

Motivation

Projects using a barrel file sometimes need to split their public API into logically grouped subsets (routing, bookmarks, models, etc.) to avoid issues with treeshaking . This feature enables that pattern while keeping module boundaries intact.

Changes

Configuration

  • New optional config enableSubBarrelFileSupport: boolean (default false) — zero impact on existing users
  • Added to UserSheriffConfig, Configuration, and defaultConfig

Core logic

  • Module.isBarrelFile(filePath) — new method using pure string operations (no filesystem or path API calls) to check if a file is the main barrel or a sub-barrel. Computes barrelPrefix and barrelExt once in the constructor.
  • accessesBarrelFileForBarrelModules — delegates to module.isBarrelFile() when the feature is enabled; falls back to the existing strict barrelPath === check otherwise.

ESLint error messages

  • Removed the hardcoded (index.ts) reference from the deep-import error message, since users can configure a custom barrelFileName — the old message would be confusing when the barrel file is e.g. public-api.ts
  • When enableSubBarrelFileSupport is enabled, the message now suggests using "the module's barrel file or a sub-barrel file"
  • When disabled, the message says "the module's barrel file" (without mentioning index.ts)

Documentation

  • configuration.md: documented enableSubBarrelFileSupport option and updated barrelFileName description
  • module_boundaries.md: new "Sub-Barrel Files" section

Tests

  • 16 unit tests for Module.isBarrelFile() covering: main barrel, sub-barrel with default/custom barrel names, non-barrel files, files in subdirectories, partial prefix matches, and edge cases
  • 8 integration tests for encapsulation violations with sub-barrel imports (enabled/disabled, barrel/barrel-less modules)
  • Updated existing test-project fixtures for the updated error message wording

Commits

  1. feat(core): support sub-barrel files in encapsulation checks — config + Module.isBarrelFile + encapsulation check + ESLint message
  2. test(core): add tests for sub-barrel file support — unit and integration tests
  3. test(test-projects): update encapsulation fixtures for new error message — fixture updates for wording change
  4. docs(docs): document sub-barrel files and enableSubBarrelFileSupport — documentation

Notes

  • Feature is behind enableSubBarrelFileSupport: false by default — no behavioral change for existing users
  • If enabled without barrel files (barrel-less modules), the feature is safely ignored
  • Zero new dependencies — uses only string operations
  • Sub-barrel files act only as additional entry points; module boundaries are still defined by the main barrel file

alilaa added 5 commits April 16, 2026 11:10
add enableSubBarrelFileSupport config option (default: false) that
allows sub-barrel files to be recognized as valid module entry points

sub-barrel files follow the convention <barrelBaseName>.<suffix>.<ext>
for example, if barrelFileName is 'public-api.ts', files like
'public-api.routing.ts' are treated as valid entry points when enabled

when disabled (default), the encapsulation check uses the original
barrel path equality with zero performance impact for existing users
add unit tests for Module.isBarrelFile() and integration tests for
encapsulation checks with enableSubBarrelFileSupport on and off

update error message strings in existing test fixtures
add sub-barrel files section to module boundaries documentation
add enableSubBarrelFileSupport config reference
@sonarqubecloud
Copy link
Copy Markdown

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.

Support multiple entry files for a single module

1 participant