You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
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 intoThe text was updated successfully, but these errors were encountered: