Socket
Socket
Sign inDemoInstall

eslint-plugin-no-typeof-window-undefined

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-typeof-window-undefined

ESLint rule to avoid typeof window === 'undefined' for SSR check


Version published
Weekly downloads
15K
increased by0.56%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-no-typeof-window-undefined

ESLint rule that helps avoid typeof window === "undefined" check and fix it to typeof document === "undefined" instead. It's recommended to use document over window because server runtimes like Deno have a global window available.

npm version

Installation

You'll first need to install ESLint:

$ pnpm add eslint --D
$ npm i eslint --save-dev

Next, install eslint-plugin-no-typeof-window-undefined:

$ pnpm add -D eslint-plugin-no-typeof-window-undefined
$ npm install eslint-plugin-no-typeof-window-undefined --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-no-typeof-window-undefined globally.

Usage

Add no-typeof-window-undefined to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": [
    "no-typeof-window-undefined"
  ]
}

Then configure the rule under the rules section.

{
  "rules": {
    "no-typeof-window-undefined/no-typeof-window-undefined": "warn"
  }
}

Or enable it with defaults

{
  "extends": [
    "plugin:no-typeof-window-undefined/recommended"
  ]
}

Often it makes sense to enable no-typeof-window-undefined only for certain files/directories. For cases like that, use override key of eslint config:

{
  "plugins": ["no-typeof-window-undefined"],
  "rules": {
    "no-typeof-window-undefined/no-typeof-window-undefined": "off"
  },
  "overrides": [
    {
      "files": ["src/**/index.{ts,js}"],
      "rules": {
        "no-typeof-window-undefined/no-typeof-window-undefined": "error
      }
    }
  ]
}

Credits

Keywords

FAQs

Package last updated on 02 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc