Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-rule: force re-export style #3158

Open
ClementEXWiki opened this issue Feb 20, 2025 · 4 comments
Open

New-rule: force re-export style #3158

ClementEXWiki opened this issue Feb 20, 2025 · 4 comments

Comments

@ClementEXWiki
Copy link

Here is a proposal for a new rule: forbidding imports followed by equivalent exports, and prefer re-export syntax instead.

Example:

// Forbidden
import { obj } from 'module'
export { obj }

// Allowed
export { obj } from 'module'

I didn't find any similar rule in the docs, and I think it would be nice to have one to enforce consistent styling of re-exports.

@ljharb
Copy link
Member

ljharb commented Feb 20, 2025

Re-exporting in general is something best avoided, especially in a barrel-file context. Rather than having a rule that enforces a consistent way to do something unadvisable, I'd rather have one that discourages re-exports entirely in favor of requiring consumers to deep-import.

@soryy708
Copy link
Collaborator

Related:

@ClementEXWiki
Copy link
Author

I do agree that it's a bad practice ; but we have some legacy code bases where it's used all over the place, and a rule enforcing a particular writing style would be really appreciated.
It could be named some like unrecommended-reexport-barrel-files or something like that to emphasize the fact that it shouldn't be used for new projects, but is still relevant for older ones.

@ljharb
Copy link
Member

ljharb commented Feb 24, 2025

If you're going to be making changes to those files based on a rule, why not remove the barrel file instead at that time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants