Skip to content

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

@michenly

Description

@michenly

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions