-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Linting: Sort imports #28839
Linting: Sort imports #28839
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 2e2d4f3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
…/storybook into norbert/sort-imports
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.
LGTM
29 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
|
||
import { DocsContext } from '@storybook/blocks'; | ||
import { global } from '@storybook/global'; | ||
import type { Decorator, ReactRenderer } from '@storybook/react'; | ||
|
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.
Why is there a blank line here and not between the previous two lines?
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.
So what I truly wanted was to provide a bit more order to storybook package import, by separating having them in a fixed order.
I think this improved readability a little.
I can't order packages in a certain way and NOT include the whitespace-line.
(well I CAN, but it's an all or nothing kinda of setting)
This is the setting I landed on:
storybook/scripts/prettier.config.js
Lines 31 to 39 in d8554e3
'^node:', | |
'^(vitest|@testing-library)', | |
'^react(-dom(/client)?(/server)?)?$', | |
'^storybook/internal', | |
'^@storybook/[^-]*$', | |
'^@storybook/(?!addon-)(.*)$', | |
'^@storybook/addon-(.*)$', | |
'<THIRD_PARTY_MODULES>', | |
'^[./]', |
And so imports are "bucketed" according to these regexes. And then each bucket is sorted, and placed with a whitespace-line.
This line: '^@storybook/[^-]*$',
, means: any package that starts with @storybook/
and then has no -
in it, is a bucket.
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.
My main goal was to ensure the renderer (e.g. @storybook/react
) in stories files are hoisted above deprecated packages (@storybook/preview-api
, etc).
What I did
I enhanced the prettier config so it also sorts imports in a way that makes the most sense for the storybook monorepo.
This PR touches a lot of files, so to make it easier: here's the new prettier config:
storybook/scripts/prettier.config.js
Lines 1 to 45 in faa0cd5
the
'@trivago/prettier-plugin-sort-imports'
plugin for prettier is what performs the magic, and it's configured with theimportOrder
,importOrderSeparation
andimportOrderSortSpecifiers
properties.The rest of the files touched in this PR are formatting changes, sorting the imports.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
Enhanced the prettier configuration to sort imports using the '@trivago/prettier-plugin-sort-imports' plugin, resulting in reordering import statements across various files for improved readability and maintainability.
/scripts/prettier.config.js
: Added@trivago/prettier-plugin-sort-imports
and configuredimportOrder
,importOrderSeparation
, andimportOrderSortSpecifiers
./code/.eslintrc.js
: Expanded file patterns and addedimport/no-extraneous-dependencies
rule./code/.storybook/main.ts
: Added a blank line after import statements./code/.storybook/preview-head.html
: Removed file containing commented-out script tag./code/addons/a11y/src/a11yRunner.ts
: Reordered import statements to comply with new prettier configuration.