eslint-plugin-ssr-friendly
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"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" |
# 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, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10257
4
202
2