@arthurgeron/eslint-plugin-react-usememo
Advanced tools
Comparing version 1.1.0--beta0 to 1.1.0
@@ -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", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
36192
1