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

@arthurgeron/eslint-plugin-react-usememo

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arthurgeron/eslint-plugin-react-usememo - npm Package Compare versions

Comparing version 1.1.0--beta0 to 1.1.0

65

dist/index.js

@@ -27,10 +27,2 @@ 'use strict';

var componentNameRegex = /^[^a-z]/;
function isComplexComponent(node) {
if (node.type !== "JSXOpeningElement")
return false;
if (node.name.type !== "JSXIdentifier")
return false;
return componentNameRegex.test(node.name.name);
}
var MemoStatus;

@@ -48,2 +40,11 @@ (function (MemoStatus) {

})(MemoStatus || (MemoStatus = {}));
var componentNameRegex = /^[^a-z]/;
function isComplexComponent(node) {
if (node.type !== "JSXOpeningElement")
return false;
if (node.name.type !== "JSXIdentifier")
return false;
return componentNameRegex.test(node.name.name);
}
function isComponentName(name) {

@@ -73,10 +74,10 @@ var _a;

if (variable === undefined)
return MemoStatus.Memoized;
return { status: MemoStatus.Memoized };
var node = variable.defs[0].node;
if (node.type === "FunctionDeclaration")
return MemoStatus.UnmemoizedFunction;
return { node: node, status: MemoStatus.UnmemoizedFunction };
if (node.type !== "VariableDeclarator")
return MemoStatus.Memoized;
return { node: node, status: MemoStatus.Memoized };
if (node.parent.kind === "let") {
return MemoStatus.UnsafeLet;
return { node: node.parent, status: MemoStatus.UnsafeLet };
}

@@ -88,24 +89,23 @@ return getExpressionMemoStatus(context, node.init);

case "ObjectExpression":
return MemoStatus.UnmemoizedObject;
return { node: expression, status: MemoStatus.UnmemoizedObject };
case "ArrayExpression":
return MemoStatus.UnmemoizedArray;
return { node: expression, status: MemoStatus.UnmemoizedArray };
case "NewExpression":
return MemoStatus.UnmemoizedNew;
return { node: expression, status: MemoStatus.UnmemoizedNew };
case "FunctionExpression":
case "ArrowFunctionExpression":
return MemoStatus.UnmemoizedFunction;
return { node: expression, status: MemoStatus.UnmemoizedFunction };
case "JSXElement":
return MemoStatus.UnmemoizedJSX;
case "CallExpression":
if (isCallExpression(expression, "useMemo") ||
isCallExpression(expression, "useCallback")) {
return MemoStatus.Memoized;
}
return MemoStatus.UnmemoizedFunctionCall;
return { node: expression, status: MemoStatus.UnmemoizedJSX };
case "CallExpression": {
var validCallExpression = isCallExpression(expression, "useMemo") ||
isCallExpression(expression, "useCallback");
return { node: expression, status: validCallExpression ? MemoStatus.Memoized : MemoStatus.UnmemoizedFunctionCall };
}
case "Identifier":
return getIdentifierMemoStatus(context, expression);
case "BinaryExpression":
return MemoStatus.Memoized;
return { node: expression, status: MemoStatus.Memoized };
default:
return MemoStatus.UnmemoizedOther;
return { node: expression, status: MemoStatus.UnmemoizedOther };
}

@@ -271,4 +271,4 @@ }

"object-usememo-props": "Object literal should be wrapped in useMemo() or be static when used as a prop",
"object-class-memo-props": "Object literal should com from state or be static when used as a prop",
"object-usememo-hook": "Object literal should com from state or be static when returned from a hook",
"object-class-memo-props": "Object literal should come from state or be static when used as a prop",
"object-usememo-hook": "Object literal should come from state or be static when returned from a hook",
"object-usememo-deps": "Object literal should be wrapped in useMemo() or be static when used as a hook dependency",

@@ -312,9 +312,9 @@ "array-usememo-props": "Array literal should be wrapped in useMemo() or be static when used as a prop",

}
function checkForErrors(data, expressionType, context, node, report) {
var _a, _b;
var errorName = data === null || data === void 0 ? void 0 : data[expressionType.toString()];
function checkForErrors(data, statusData, context, node, report) {
var _a, _b, _c;
var errorName = data === null || data === void 0 ? void 0 : data[statusData.status.toString()];
if (errorName) {
var strict = errorName.includes('unknown');
if (!strict || (strict && ((_b = (_a = context.options) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.strict))) {
report(node, errorName);
report(((_c = statusData.node) !== null && _c !== void 0 ? _c : node), errorName);
}

@@ -464,3 +464,4 @@ }

if (expression.type !== "JSXEmptyExpression") {
switch (getExpressionMemoStatus(context, expression)) {
var statusData = getExpressionMemoStatus(context, expression);
switch (statusData.status) {
case MemoStatus.UnmemoizedObject:

@@ -467,0 +468,0 @@ report(node, "object-usememo-children");

{
"name": "@arthurgeron/eslint-plugin-react-usememo",
"version": "1.1.0--beta0",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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