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

Add eslint rule to stop using index file for exporting #230

Open
michenly opened this issue Apr 8, 2021 · 0 comments
Open

Add eslint rule to stop using index file for exporting #230

michenly opened this issue Apr 8, 2021 · 0 comments

Comments

@michenly
Copy link
Contributor

michenly commented Apr 8, 2021

Motivation

Having index file while convenient, leads to performance issue in test and build, especially in a ESM world.
We should stop using component index all together and write a eslint rule that stop it.

There is already a decision for Shopify/web top stop using component/index but it really should be stop everywhere
https://github.com/Shopify/web/blob/master/documentation/decisions/09%20-%20Explicit%20root%20components%20imports.md

Propose Rule

While the actual reason to stop using index file have to do with the number of files being check.
(example:
a file that imports 1 other file that imports 1 other file that imports 1 other file that imports 1 other file that imports 1 other file that imports 1 other file that imports 1 other file that imports 1 other file = 6 total files
vs 1 file that imports 4 files that don't import anything from there = 5 total files

both will be equally bad on performance)

The biggest offender to those are currently component/index or any index file that export a lot of things, because the chances are not all the object being exported will be use upon import.

So I propose that we add a rule to stop any index file that export more than 10 things, and make the this arbitrary number editable in the lint rule.

https://github.com/Shopify/web-configs/blob/main/packages/eslint-plugin/docs/rules/strict-component-boundaries.md and
https://github.com/Shopify/web-configs/blob/main/packages/eslint-plugin/lib/rules/images-no-direct-imports.js
both of those rules are in direct conflict with what is being propose and should be update/delete/adjusted at the same time.

no-restricted-imports used in web and https://github.com/Shopify/web-configs/blob/dab62e4f72e14c1f33ae6a6a626f890e2a872f3e/packages/eslint-plugin/docs/rules/no-ancestor-directory-import.md could also be rules that we look into

@michenly michenly changed the title Add eslint rule to stop using index file that only export components Add eslint rule to stop using index file for exporting Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants