Feat/adds the no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.#11858
Feat/adds the no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.#11858webdevpraveen wants to merge 4 commits intofacebook:mainfrom
no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.#11858Conversation
|
Hi @webdevpraveen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thanks, but I don't think we need this, at least not in the form it is currently designed Please respect my comment here, you clearly saw it and still sent a PR anyway: #6472 (comment) Also, please disclose AI usage as requested in our contribution guidelines |
Summary
Adds the
no-window-eq-undefinedESLint rule to@docusaurus/eslint-plugin.Closes #6472
Motivation
Using
typeof window !== 'undefined'is a common pattern for SSR escape hatching in React apps, but it is the wrong approach in Docusaurus. Docusaurus provides purpose-built APIs —useIsBrowser()andExecutionEnvironment.canUseDOM— which integrate correctly with its SSR/pre-rendering pipeline.This implements the
no-window-eq-undefinedrule originally proposed in #6472. (Thestring-literal-i18n-messagesrule from the same issue was implemented in #7206, but this rule was never added.)Changes
packages/eslint-plugin/src/rules/no-window-eq-undefined.ts— new rule implementationpackages/eslint-plugin/src/rules/__tests__/no-window-eq-undefined.test.ts— rule testspackages/eslint-plugin/src/index.ts— register rule + add toallconfigwebsite/docs/api/misc/eslint-plugin/no-window-eq-undefined.mdx— documentation pagewebsite/docs/api/misc/eslint-plugin/README.mdx— add to supported rules tableTest Plan
yarn jest packages/eslint-plugin— all tests pass including new rule tests.Rule Behavior
Flagged (incorrect pattern)
Not flagged (correct Docusaurus patterns)