Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-ssr-friendly

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-ssr-friendly - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

LICENSE

14

package.json
{
"name": "eslint-plugin-ssr-friendly",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -9,2 +9,11 @@ "main": "./src/index.js",

],
"keywords": [
"eslint",
"eslintplugin",
"ssr",
"server-side-rendering",
"globals",
"react",
"nodejs"
],
"scripts": {

@@ -21,2 +30,5 @@ "test": "node ./test"

},
"peerDependencies": {
"eslint": ">=0.8.0"
},
"dependencies": {

@@ -23,0 +35,0 @@ "globals": "^13.2.0"

6

README.md
# eslint-plugin-ssr-friendly
[![npm version](https://badge.fury.io/js/eslint-plugin-ssr-friendly.svg)](https://badge.fury.io/js/eslint-plugin-ssr-friendly)
ESLint plugin that detects incorrect use of DOM globals properties in your code in

@@ -17,5 +19,3 @@ order to properly do Server-Side-Rendering.

"plugins": ["ssr-friendly"],
"rules": {
"ssr-friendly/recommended": "error"
}
"extends": ["plugin:ssr-friendly/recommended"]
}

@@ -22,0 +22,0 @@ ```

@@ -1,20 +0,24 @@

const { browser } = require("globals");
const { browser, node } = require("globals");
const pkg = require("../package.json");
const pluginName = pkg.name.replace("eslint-plugin-", "");
const isDOMGlobalName = (name) => {
return name in browser;
return name in browser && !(name in node);
};
const isReturnValueJSX = (scope) => {
return (
scope.type === "function" &&
scope.block.body &&
scope.block.body.body &&
scope.block.body.body.find(
(e) =>
e &&
e.type === "ReturnStatement" &&
e.argument &&
e.argument.type === "JSXElement"
)
);
if (scope.block && scope.block.body && scope.block.body.body) {
return (
scope.type === "function" &&
scope.block.body.body.find(
(e) =>
e &&
e.type === "ReturnStatement" &&
e.argument &&
e.argument.type === "JSXElement"
)
);
}
return false;
};

@@ -27,14 +31,20 @@

const isConstructorInClass = (scope) => {
const { type, kind } = scope.block.parent;
return type === "MethodDefinition" && kind === "constructor";
if (scope.block && scope.block.parent) {
const { type, kind } = scope.block.parent;
return type === "MethodDefinition" && kind === "constructor";
}
return false;
};
const isRenderMethodInReactCC = (scope) => {
const { type, kind, key } = scope.block.parent;
return (
type === "MethodDefinition" &&
kind === "method" &&
key.name === "render" &&
isReturnValueJSX(scope)
);
if (scope.block && scope.block.parent) {
const { type, kind, key } = scope.block.parent;
return (
type === "MethodDefinition" &&
kind === "method" &&
key.name === "render" &&
isReturnValueJSX(scope)
);
}
return false;
};

@@ -133,3 +143,3 @@

module.exports.rules = {
const rules = {
"no-dom-globals-in-module-scope": {

@@ -194,1 +204,20 @@ meta: {

};
module.exports = {
configs: {
recommended: {
plugins: [pluginName],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
rules: Object.keys(rules).reduce((carry, key) => {
// eslint-disable-next-line no-param-reassign
carry[`${pluginName}/${key}`] = "error";
return carry;
}, {}),
},
},
rules,
};
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