-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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: fix CSS import order ESLint rule #7852
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
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—can you fix existing files so we can take a look at the effect?
Try running
|
After I posted that command, I found there are some missing scenario, I do find one problem in |
laugh, I guess I have did |
There are 3 warnings reported by |
The 3 warnings haved been fixed in my local env, and I am thinking about the problem in |
see d4ed946, all the problems should have been resolved, with an extra fix of copyright header problems involved with css files. |
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.
Thank you! This looks much greater than before :D
enhance: added ESLint ruler for CSS import
Pre-flight checklist
Motivation
In previous PR #7849, I found there is a bug when importing a
CSS
file after importing a type from@docusaurus/type
.At first, we (with the maintainer) are guessing the problem is caused by my system environment. But later I did a lot of checks, and came to realize that it's not.
Best Solution (potential)
Just adding one extra ruler in order to force CSS to be imported at last:
Other Solutions
I'd think it unnecessary although it may work well using an extra plugin of
eslint-plugin-css-import-order
.Test (tested both in WebStorm and VSCode)
As mentioned from #7849, we can do a simple test.
TIPS:
grep -irE "import.*\.css" packages | cut -d ':' -f 1 | uniq
can list all the files with css files imported.packages/docusaurus-types/src/index.d.ts
Take the
packages/docusaurus-theme-common/src/components/Details/index.tsx
as an example, we can easily get the warning if we import types from@docusaurus/types
before css file.However, if we omitted the imported default variable, then the warning would go away immediately (but would cause the later reference problems):
Essential
The plugin of
eslint-plugin-import
has no default type check for file extensions, so:import css from 'xx.css'
internal
import css from './xx.css'
sibling
import css from '../xx.css'
parent
import '../xx.css'
unknown
(maybe)Hence, in normal situation, those
internal | sibling | parent
would be ranked in front oftype
, except we explictly declaring the module order, just like what the former work has been done:All those variables, as well as types, would be intepreted before any css-like imports.
But then, not so lucky for those types imported from
@docusaurus/types
.Other Problems
Also, if we do not rectify this problem, each time when we commited, the eslint fix would force the local files changed into like this, which is not expected:
Related issues/PRs
#7849
References
You can get more info from the following references:
eslint-plugin-import
: https://github.com/import-js/eslint-plugin-import/blob/v2.26.0/docs/rules/order.md