eslint-plugin-ssr-friendly
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "eslint-plugin-ssr-friendly", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -10,2 +10,10 @@ const { browser: browserGlobals, node: nodeGlobals } = require("globals"); | ||
const isJSXElementOrFragment = (argumentType) => { | ||
return argumentType === "JSXElement" || argumentType === "JSXFragment"; | ||
}; | ||
const isReturnValueNull = (argument) => { | ||
return argument.type === "Literal" && argument.value === null; | ||
}; | ||
const isReturnValueJSXOrNull = (scope) => { | ||
@@ -20,11 +28,23 @@ if ( | ||
scope.type === "function" && | ||
scope.block.body.body.find( | ||
(e) => | ||
e && | ||
e.type === "ReturnStatement" && | ||
e.argument && | ||
(e.argument.type === "JSXElement" || | ||
e.argument.type === "JSXFragment" || | ||
(e.argument.type === "Literal" && e.argument.value === null)) | ||
) | ||
scope.block.body.body.find((e) => { | ||
if (!(e && e.type === "ReturnStatement" && e.argument)) { | ||
return false; | ||
} | ||
if ( | ||
isJSXElementOrFragment(e.argument.type) || | ||
isReturnValueNull(e.argument) | ||
) { | ||
return true; | ||
} | ||
if ( | ||
e.argument.type === "ConditionalExpression" && | ||
(isJSXElementOrFragment(e.argument.consequent.type) || | ||
isReturnValueNull(e.argument.consequent)) && | ||
(isJSXElementOrFragment(e.argument.alternate.type) || | ||
isReturnValueNull(e.argument.alternate)) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
}) | ||
); | ||
@@ -39,2 +59,11 @@ } | ||
function isReactFunction(node, functionName) { | ||
return ( | ||
node.name === functionName || | ||
(node.type === "MemberExpression" && | ||
node.object.name === "React" && | ||
node.property.name === functionName) | ||
); | ||
} | ||
const isReactFunctionComponent = (scope) => { | ||
@@ -56,2 +85,8 @@ // eslint-disable-next-line default-case | ||
} | ||
if ( | ||
scope.block.parent.type === "CallExpression" && | ||
isReactFunction(scope.block.parent.callee, "forwardRef") | ||
) { | ||
return true; | ||
} | ||
} | ||
@@ -58,0 +93,0 @@ return false; |
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
12356
246