eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Rule for banning `export {} from '...'`

Open blended-bram opened this issue 1 year ago • 2 comments

A new rule that allows you to ban the creation of export {} from '...'.

This will help enforce a policy to not create barrel files, which are index.js / index.ts files that only serves to export parts of other modules.

This is not a commentary on the good or bad for this way of organizing modules and packages, I'd just like to be able to set up linting rules over its usage.

With eslint's own settings we can already control the file patterns any individual rule applies to. Perhaps having a flag to distinguish between export-only files and files that mix re-exported elements and exports of locally defined elements. Although that could also be achieved with lint-ignore comments.

blended-bram avatar Oct 02 '24 10:10 blended-bram

Barrel files are incredibly bad, and commentary on that is welcome.

You can already ban this form with no-restricted-syntax, so it doesn't really make sense to make a full-blown rule for it.

If you want a "no barrel files" rule, that would have more merit.

ljharb avatar Oct 02 '24 14:10 ljharb

I didn't know about no-restricted-syntax; thanks for pointing it out. Then this issue can become a direct feature request for a no-barrel-exports rule.

blended-bram avatar Oct 08 '24 10:10 blended-bram

I'm closing this as a duplicate of: https://github.com/import-js/eslint-plugin-import/issues/2922

soryy708 avatar Jan 23 '25 20:01 soryy708