-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chore(eslint): Enforce import order #52499
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~77 bytes removed 📉 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~78 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~56 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
I personally liked having internal/external dependencies separated since it seemed more organized. I also personally don't think that import order is very important in terms of DevX. I wonder what others think though -- I don't know any practical reasons to go either way. |
My opinion about these rules: I don’t really care about the What I don’t like is the
My guess is that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing this up, @scinos.
Personally, I don’t care much about the docblocks, as long as we’re consistent throughout the codebase. I personally used to see some value in splitting the imports to internal and external, as it made things more readable, but at the same time, more and more of the repo code is in packages now, so it all ends up being external anyway…
Regarding sorted imports, for my brain this improves readability and I prefer having it, it does make the code more readable in my opinion - especially if you scan through code like you diagonally read through a page of a book (that's what I often do). I’ve preferred sorting the imports in my code, but I’m not sure it will be as preferred by all calypso devs, thus I’m not sure enforcing a rule for that would make sense.
In any case, this is worth trying out IMHO but will have to be very short-lived PR.
I like the I think it's valuable though to be aligned with Gutenberg standards. Consider proposing the same change there. Personally, I feel that import ordering affects my devex very little. It just doesn't matter much. But often I find myself instinctively reordering imports in PRs so that local relative ones ( |
This PR has been marked as stale due to lack of activity within the last 30 days. |
Being done in #54448 |
EXPERIMENT, DO NOT MERGE
Changes proposed in this Pull Request
wpcalypso/import-docblock
for packages. No more mandatory/* External dependencies */
comment blocks./** * External dependencies */
,/** * Internal dependencies */
and similar blocksimport/order
import/order
The changes were introduced using automated tools:
/**\n* External dependencies\n*/
and replace it by an empty line. Same forInternal dependencies
,WordPress dependencies
,Module dependencies
andType dependencies
.prettier
to get rid of the extra new lines.import/order
in.eslintrc.js
and apply the auto-fix.Next steps
If we like it, decide how to apply this to the repo. We can do one massive PR for all the repo, many small PRs (eg: one per package/dir), or anything in between.
Alternative: there is an improved version of the rule in Gutenberg: https://github.com/WordPress/gutenberg/blob/trunk/packages/eslint-plugin/rules/dependency-group.js. We could adopt that as well. I'm not sure if it will work together with
import/order
to enforce a specific order inside each group.