diff --git a/packages/core/docs/-internal-/README.md b/packages/core/docs/-internal-/README.md index 8ccb13a4d8..b42dc95eab 100644 --- a/packages/core/docs/-internal-/README.md +++ b/packages/core/docs/-internal-/README.md @@ -165,12 +165,6 @@ *** -### ClassDeclaration - -> **ClassDeclaration**: `"ClassDeclaration"` - -*** - ### ClassExpression > **ClassExpression**: `"ClassExpression"` @@ -699,12 +693,6 @@ *** -### TSDeclareFunction - -> **TSDeclareFunction**: `"TSDeclareFunction"` - -*** - ### TSDeclareKeyword > **TSDeclareKeyword**: `"TSDeclareKeyword"` @@ -765,12 +753,6 @@ *** -### TSImportEqualsDeclaration - -> **TSImportEqualsDeclaration**: `"TSImportEqualsDeclaration"` - -*** - ### TSImportType > **TSImportType**: `"TSImportType"` @@ -831,12 +813,6 @@ *** -### TSModuleDeclaration - -> **TSModuleDeclaration**: `"TSModuleDeclaration"` - -*** - ### TSModuleName > **TSModuleName**: `"TSModuleName"` @@ -1083,12 +1059,6 @@ *** -### VariableDeclaration - -> **VariableDeclaration**: `"VariableDeclaration"` - -*** - ### WhileStatement > **WhileStatement**: `"WhileStatement"` diff --git a/packages/core/docs/-internal-/enumerations/AST_NODE_TYPES.md b/packages/core/docs/-internal-/enumerations/AST_NODE_TYPES.md index 54be07a46a..35f7b2a07f 100644 --- a/packages/core/docs/-internal-/enumerations/AST_NODE_TYPES.md +++ b/packages/core/docs/-internal-/enumerations/AST_NODE_TYPES.md @@ -116,12 +116,6 @@ *** -### Literal - -> **Literal**: `"Literal"` - -*** - ### MethodDefinition > **MethodDefinition**: `"MethodDefinition"` @@ -518,6 +512,12 @@ Re-exports [LabeledStatement](../README.md#labeledstatement) *** +### Literal + +Re-exports [Literal](../README.md#literal) + +*** + ### LogicalExpression Re-exports [LogicalExpression](../README.md#logicalexpression) diff --git a/packages/core/docs/-internal-/interfaces/BooleanLiteral.md b/packages/core/docs/-internal-/interfaces/BooleanLiteral.md index 76c6c04d24..27d484b69c 100644 --- a/packages/core/docs/-internal-/interfaces/BooleanLiteral.md +++ b/packages/core/docs/-internal-/interfaces/BooleanLiteral.md @@ -58,7 +58,7 @@ The loc property is defined as nullable by ESTree, but ESLint requires this prop ### type -> **type**: [`Literal`](../enumerations/AST_NODE_TYPES.md#literal) +> **type**: [`Literal`](../README.md#literal) #### Inherited from diff --git a/packages/core/docs/-internal-/interfaces/LiteralBase.md b/packages/core/docs/-internal-/interfaces/LiteralBase.md index ff0943cfed..7ab6d1b6ee 100644 --- a/packages/core/docs/-internal-/interfaces/LiteralBase.md +++ b/packages/core/docs/-internal-/interfaces/LiteralBase.md @@ -12,12 +12,12 @@ ## Extended by -- [`StringLiteral`](StringLiteral.md) - [`BigIntLiteral`](BigIntLiteral.md) - [`BooleanLiteral`](BooleanLiteral.md) - [`NullLiteral`](NullLiteral.md) - [`NumberLiteral`](NumberLiteral.md) - [`RegExpLiteral`](RegExpLiteral.md) +- [`StringLiteral`](StringLiteral.md) ## Properties @@ -63,7 +63,7 @@ The loc property is defined as nullable by ESTree, but ESLint requires this prop ### type -> **type**: [`Literal`](../enumerations/AST_NODE_TYPES.md#literal) +> **type**: [`Literal`](../README.md#literal) #### Overrides diff --git a/packages/core/docs/-internal-/interfaces/NumberLiteral.md b/packages/core/docs/-internal-/interfaces/NumberLiteral.md index b8a7fdeaa6..f3a1b1995c 100644 --- a/packages/core/docs/-internal-/interfaces/NumberLiteral.md +++ b/packages/core/docs/-internal-/interfaces/NumberLiteral.md @@ -58,7 +58,7 @@ The loc property is defined as nullable by ESTree, but ESLint requires this prop ### type -> **type**: [`Literal`](../enumerations/AST_NODE_TYPES.md#literal) +> **type**: [`Literal`](../README.md#literal) #### Inherited from diff --git a/packages/core/docs/-internal-/interfaces/RegExpLiteral.md b/packages/core/docs/-internal-/interfaces/RegExpLiteral.md index 7c3a56443b..0d083b2140 100644 --- a/packages/core/docs/-internal-/interfaces/RegExpLiteral.md +++ b/packages/core/docs/-internal-/interfaces/RegExpLiteral.md @@ -72,7 +72,7 @@ The loc property is defined as nullable by ESTree, but ESLint requires this prop ### type -> **type**: [`Literal`](../enumerations/AST_NODE_TYPES.md#literal) +> **type**: [`Literal`](../README.md#literal) #### Inherited from diff --git a/packages/core/docs/README.md b/packages/core/docs/README.md index 06de8ba236..443c0e19b5 100644 --- a/packages/core/docs/README.md +++ b/packages/core/docs/README.md @@ -10,8 +10,6 @@ ## Namespaces -- [isCallFromReact](namespaces/isCallFromReact/README.md) -- [isFromReact](namespaces/isFromReact/README.md) - [useComponentCollector](namespaces/useComponentCollector/README.md) - [useComponentCollectorLegacy](namespaces/useComponentCollectorLegacy/README.md) - [useHookCollector](namespaces/useHookCollector/README.md) @@ -52,9 +50,6 @@ - [getComponentNameFromIdentifier](functions/getComponentNameFromIdentifier.md) - [getFunctionComponentIdentifier](functions/getFunctionComponentIdentifier.md) - [hasNoneOrValidComponentName](functions/hasNoneOrValidComponentName.md) -- [hasValidHierarchy](functions/hasValidHierarchy.md) -- [isCallFromReact](functions/isCallFromReact.md) -- [isCallFromReactObject](functions/isCallFromReactObject.md) - [isChildrenCount](functions/isChildrenCount.md) - [isChildrenCountCall](functions/isChildrenCountCall.md) - [isChildrenForEach](functions/isChildrenForEach.md) @@ -81,10 +76,6 @@ - [isDeclaredInRenderPropLoose](functions/isDeclaredInRenderPropLoose.md) - [isForwardRef](functions/isForwardRef.md) - [isForwardRefCall](functions/isForwardRefCall.md) -- [isFromReact](functions/isFromReact.md) -- [isFromReactLoose](functions/isFromReactLoose.md) -- [isFromReactObject](functions/isFromReactObject.md) -- [isFromReactStrict](functions/isFromReactStrict.md) - [isFunctionOfComponentDidMount](functions/isFunctionOfComponentDidMount.md) - [isFunctionOfComponentWillUnmount](functions/isFunctionOfComponentWillUnmount.md) - [isFunctionOfRenderMethod](functions/isFunctionOfRenderMethod.md) diff --git a/packages/core/docs/functions/hasValidHierarchy.md b/packages/core/docs/functions/hasValidHierarchy.md deleted file mode 100644 index d27c4ef52a..0000000000 --- a/packages/core/docs/functions/hasValidHierarchy.md +++ /dev/null @@ -1,29 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / hasValidHierarchy - -# Function: hasValidHierarchy() - -> **hasValidHierarchy**(`context`, `node`, `hint`): `boolean` - -internal - -## Parameters - -### context - -[`Readonly`](../-internal-/type-aliases/Readonly.md) - -### node - -[`TSESTreeFunction`](../-internal-/type-aliases/TSESTreeFunction.md) - -### hint - -`bigint` - -## Returns - -`boolean` diff --git a/packages/core/docs/functions/isCallFromReact.md b/packages/core/docs/functions/isCallFromReact.md deleted file mode 100644 index 1bc1f6506f..0000000000 --- a/packages/core/docs/functions/isCallFromReact.md +++ /dev/null @@ -1,19 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isCallFromReact - -# Function: isCallFromReact() - -> **isCallFromReact**(`name`): [`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) - -## Parameters - -### name - -`string` - -## Returns - -[`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) diff --git a/packages/core/docs/functions/isCallFromReactObject.md b/packages/core/docs/functions/isCallFromReactObject.md deleted file mode 100644 index 096b06f3ef..0000000000 --- a/packages/core/docs/functions/isCallFromReactObject.md +++ /dev/null @@ -1,23 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isCallFromReactObject - -# Function: isCallFromReactObject() - -> **isCallFromReactObject**(`objectName`, `propertyName`): [`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) - -## Parameters - -### objectName - -`string` - -### propertyName - -`string` - -## Returns - -[`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) diff --git a/packages/core/docs/functions/isFromReact.md b/packages/core/docs/functions/isFromReact.md deleted file mode 100644 index 9cf09089fb..0000000000 --- a/packages/core/docs/functions/isFromReact.md +++ /dev/null @@ -1,19 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isFromReact - -# Function: isFromReact() - -> **isFromReact**(`name`): [`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) - -## Parameters - -### name - -`string` - -## Returns - -[`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) diff --git a/packages/core/docs/functions/isFromReactLoose.md b/packages/core/docs/functions/isFromReactLoose.md deleted file mode 100644 index ed374c000f..0000000000 --- a/packages/core/docs/functions/isFromReactLoose.md +++ /dev/null @@ -1,23 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isFromReactLoose - -# Function: isFromReactLoose() - -> **isFromReactLoose**(`node`, `name`): `boolean` - -## Parameters - -### node - -`undefined` | [`Node`](../-internal-/type-aliases/Node.md) - -### name - -`string` - -## Returns - -`boolean` diff --git a/packages/core/docs/functions/isFromReactObject.md b/packages/core/docs/functions/isFromReactObject.md deleted file mode 100644 index 393c3b9cf9..0000000000 --- a/packages/core/docs/functions/isFromReactObject.md +++ /dev/null @@ -1,23 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isFromReactObject - -# Function: isFromReactObject() - -> **isFromReactObject**(`objectName`, `propertyName`): [`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) - -## Parameters - -### objectName - -`string` - -### propertyName - -`string` - -## Returns - -[`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) diff --git a/packages/core/docs/functions/isFromReactStrict.md b/packages/core/docs/functions/isFromReactStrict.md deleted file mode 100644 index e828591195..0000000000 --- a/packages/core/docs/functions/isFromReactStrict.md +++ /dev/null @@ -1,31 +0,0 @@ -[**@eslint-react/core**](../README.md) - -*** - -[@eslint-react/core](../README.md) / isFromReactStrict - -# Function: isFromReactStrict() - -> **isFromReactStrict**(`node`, `name`, `importSource`, `initialScope`): `boolean` - -## Parameters - -### node - -`undefined` | [`Node`](../-internal-/type-aliases/Node.md) - -### name - -`string` - -### importSource - -`string` - -### initialScope - -[`Scope`](../-internal-/type-aliases/Scope.md) - -## Returns - -`boolean` diff --git a/packages/core/docs/functions/isReactAPI.md b/packages/core/docs/functions/isReactAPI.md index a05c072272..6f03f3dabc 100644 --- a/packages/core/docs/functions/isReactAPI.md +++ b/packages/core/docs/functions/isReactAPI.md @@ -8,7 +8,7 @@ ## Call Signature -> **isReactAPI**(`name`): [`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) +> **isReactAPI**(`name`): `ReturnType` ### Parameters @@ -18,11 +18,11 @@ ### Returns -[`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) +`ReturnType` ## Call Signature -> **isReactAPI**(`objectName`, `propertyName`): [`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) +> **isReactAPI**(`objectName`, `propertyName`): `ReturnType` ### Parameters @@ -36,4 +36,4 @@ ### Returns -[`ReturnType`](../namespaces/isFromReact/type-aliases/ReturnType.md) +`ReturnType` diff --git a/packages/core/docs/functions/isReactAPICall.md b/packages/core/docs/functions/isReactAPICall.md index 50cd8a8c01..0f70bc7817 100644 --- a/packages/core/docs/functions/isReactAPICall.md +++ b/packages/core/docs/functions/isReactAPICall.md @@ -8,7 +8,7 @@ ## Call Signature -> **isReactAPICall**(`name`): [`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) +> **isReactAPICall**(`name`): `ReturnType` ### Parameters @@ -18,11 +18,11 @@ ### Returns -[`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) +`ReturnType` ## Call Signature -> **isReactAPICall**(`objectName`, `propertyName`): [`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) +> **isReactAPICall**(`objectName`, `propertyName`): `ReturnType` ### Parameters @@ -36,4 +36,4 @@ ### Returns -[`ReturnType`](../namespaces/isCallFromReact/type-aliases/ReturnType.md) +`ReturnType` diff --git a/packages/core/docs/namespaces/isCallFromReact/README.md b/packages/core/docs/namespaces/isCallFromReact/README.md deleted file mode 100644 index d446cbf9a7..0000000000 --- a/packages/core/docs/namespaces/isCallFromReact/README.md +++ /dev/null @@ -1,11 +0,0 @@ -[**@eslint-react/core**](../../README.md) - -*** - -[@eslint-react/core](../../README.md) / isCallFromReact - -# isCallFromReact - -## Type Aliases - -- [ReturnType](type-aliases/ReturnType.md) diff --git a/packages/core/docs/namespaces/isCallFromReact/type-aliases/ReturnType.md b/packages/core/docs/namespaces/isCallFromReact/type-aliases/ReturnType.md deleted file mode 100644 index b921281f81..0000000000 --- a/packages/core/docs/namespaces/isCallFromReact/type-aliases/ReturnType.md +++ /dev/null @@ -1,43 +0,0 @@ -[**@eslint-react/core**](../../../README.md) - -*** - -[@eslint-react/core](../../../README.md) / [isCallFromReact](../README.md) / ReturnType - -# Type Alias: ReturnType() - -> **ReturnType**: (`context`) => (`node`) => `node is CallExpression`(`context`, `node`) => `node is CallExpression` - -## Parameters - -### context - -[`Readonly`](../../../-internal-/type-aliases/Readonly.md) - -## Returns - -`Function` - -### Parameters - -#### node - -[`Node`](../../../-internal-/type-aliases/Node.md) - -### Returns - -`node is CallExpression` - -## Parameters - -### context - -[`Readonly`](../../../-internal-/type-aliases/Readonly.md) - -### node - -[`Node`](../../../-internal-/type-aliases/Node.md) - -## Returns - -`node is CallExpression` diff --git a/packages/core/docs/namespaces/isFromReact/README.md b/packages/core/docs/namespaces/isFromReact/README.md deleted file mode 100644 index a42c38f84b..0000000000 --- a/packages/core/docs/namespaces/isFromReact/README.md +++ /dev/null @@ -1,11 +0,0 @@ -[**@eslint-react/core**](../../README.md) - -*** - -[@eslint-react/core](../../README.md) / isFromReact - -# isFromReact - -## Type Aliases - -- [ReturnType](type-aliases/ReturnType.md) diff --git a/packages/core/docs/namespaces/isFromReact/type-aliases/ReturnType.md b/packages/core/docs/namespaces/isFromReact/type-aliases/ReturnType.md deleted file mode 100644 index 4c7ae90978..0000000000 --- a/packages/core/docs/namespaces/isFromReact/type-aliases/ReturnType.md +++ /dev/null @@ -1,43 +0,0 @@ -[**@eslint-react/core**](../../../README.md) - -*** - -[@eslint-react/core](../../../README.md) / [isFromReact](../README.md) / ReturnType - -# Type Alias: ReturnType() - -> **ReturnType**: (`context`) => (`node`) => node is Identifier \| MemberExpression(`context`, `node`) => node is Identifier \| MemberExpression - -## Parameters - -### context - -[`Readonly`](../../../-internal-/type-aliases/Readonly.md) - -## Returns - -`Function` - -### Parameters - -#### node - -[`Node`](../../../-internal-/type-aliases/Node.md) - -### Returns - -node is Identifier \| MemberExpression - -## Parameters - -### context - -[`Readonly`](../../../-internal-/type-aliases/Readonly.md) - -### node - -[`Node`](../../../-internal-/type-aliases/Node.md) - -## Returns - -node is Identifier \| MemberExpression diff --git a/packages/core/src/component/hierarchy.ts b/packages/core/src/component/hierarchy.ts index 99844492ea..c67a30a61a 100644 --- a/packages/core/src/component/hierarchy.ts +++ b/packages/core/src/component/hierarchy.ts @@ -8,7 +8,7 @@ import { isCreateElementCall } from "../utils"; import { ERComponentHint } from "./component-collector-hint"; import { isFunctionOfRenderMethod } from "./component-lifecycle"; -/** internal */ +/** @internal */ export function hasValidHierarchy(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint) { if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) { return false; diff --git a/packages/utilities/var/src/get-variable-id.ts b/packages/core/src/utils/get-instance-id.ts similarity index 78% rename from packages/utilities/var/src/get-variable-id.ts rename to packages/core/src/utils/get-instance-id.ts index 20bdc363c5..c48e44d93e 100644 --- a/packages/utilities/var/src/get-variable-id.ts +++ b/packages/core/src/utils/get-instance-id.ts @@ -1,8 +1,10 @@ +/* eslint-disable jsdoc/require-param */ import { _ } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -export function getVariableId(node: TSESTree.Node, prev?: TSESTree.Node) { +/** @internal */ +export function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node) { switch (true) { case node.type === T.VariableDeclarator && node.init === prev: @@ -18,6 +20,6 @@ export function getVariableId(node: TSESTree.Node, prev?: TSESTree.Node) { || node.parent === node: return _; default: - return getVariableId(node.parent, node); + return getInstanceId(node.parent, node); } } diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 89f23d3b20..c491b9f6e1 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,3 +1,5 @@ +export * from "./get-instance-id"; export * from "./is-from-react"; export * from "./is-initialized-from-react"; +export * from "./is-instance-id-equal"; export * from "./is-react-api"; diff --git a/packages/core/src/utils/is-from-react.ts b/packages/core/src/utils/is-from-react.ts index 1fcb072233..144dbf6857 100644 --- a/packages/core/src/utils/is-from-react.ts +++ b/packages/core/src/utils/is-from-react.ts @@ -1,3 +1,4 @@ +/* eslint-disable jsdoc/require-param */ import { type _, dual } from "@eslint-react/eff"; import type { RuleContext } from "@eslint-react/shared"; import { DEFAULT_ESLINT_REACT_SETTINGS, unsafeDecodeSettings } from "@eslint-react/shared"; @@ -9,7 +10,7 @@ import { isInitializedFromReact } from "./is-initialized-from-react"; const defaultImportSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource; -/* @internal */ +/** @internal */ export function isFromReactLoose(node: TSESTree.Node | _, name: string) { switch (node?.type) { case T.Identifier: @@ -23,7 +24,7 @@ export function isFromReactLoose(node: TSESTree.Node | _, name: string) { } } -/* @internal */ +/** @internal */ export function isFromReactStrict( node: TSESTree.Node | _, name: string, @@ -43,7 +44,7 @@ export function isFromReactStrict( } } -/* @internal */ +/** @internal */ export declare namespace isFromReact { type ReturnType = { (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.Identifier | TSESTree.MemberExpression; @@ -51,7 +52,7 @@ export declare namespace isFromReact { }; } -/* @internal */ +/** @internal */ export function isFromReact(name: string): isFromReact.ReturnType { // dprint-ignore return dual(2, (context: RuleContext, node: TSESTree.Node | _): node is TSESTree.Identifier | TSESTree.MemberExpression => { @@ -62,7 +63,7 @@ export function isFromReact(name: string): isFromReact.ReturnType { }); } -/* @internal */ +/** @internal */ export function isFromReactObject(objectName: string, propertyName: string): isFromReact.ReturnType { // dprint-ignore return dual(2, (context: RuleContext, node: TSESTree.Node | _): node is TSESTree.Identifier | TSESTree.MemberExpression => { @@ -79,7 +80,7 @@ export function isFromReactObject(objectName: string, propertyName: string): isF }); } -/* @internal */ +/** @internal */ export declare namespace isCallFromReact { type ReturnType = { (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression; @@ -87,7 +88,7 @@ export declare namespace isCallFromReact { }; } -/* @internal */ +/** @internal */ export function isCallFromReact(name: string): isCallFromReact.ReturnType { return dual(2, (context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression => { if (node.type !== T.CallExpression) return false; @@ -95,7 +96,7 @@ export function isCallFromReact(name: string): isCallFromReact.ReturnType { }); } -/* @internal */ +/** @internal */ export function isCallFromReactObject(objectName: string, propertyName: string): isCallFromReact.ReturnType { return dual(2, (context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression => { if (node.type !== T.CallExpression) return false; diff --git a/packages/plugins/eslint-plugin-react-web-api/src/utils/is-instance-id-equal.ts b/packages/core/src/utils/is-instance-id-equal.ts similarity index 73% rename from packages/plugins/eslint-plugin-react-web-api/src/utils/is-instance-id-equal.ts rename to packages/core/src/utils/is-instance-id-equal.ts index 3689c3d101..40b8a8c4be 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/utils/is-instance-id-equal.ts +++ b/packages/core/src/utils/is-instance-id-equal.ts @@ -1,9 +1,11 @@ +import * as AST from "@eslint-react/ast"; import type { RuleContext } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; import type { TSESTree } from "@typescript-eslint/types"; +/** @internal */ export function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node) { - return VAR.isVariableIdEqual(a, b, [ + return AST.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [ context.sourceCode.getScope(a), context.sourceCode.getScope(b), ]); diff --git a/packages/plugins/eslint-plugin-react-naming-convention/package.json b/packages/plugins/eslint-plugin-react-naming-convention/package.json index 18304c6b1f..bbe1592eaf 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/package.json +++ b/packages/plugins/eslint-plugin-react-naming-convention/package.json @@ -53,7 +53,6 @@ "@eslint-react/core": "workspace:*", "@eslint-react/eff": "workspace:*", "@eslint-react/jsx": "workspace:*", - "@eslint-react/var": "workspace:*", "@eslint-react/shared": "workspace:*", "@typescript-eslint/scope-manager": "^8.25.0", "@typescript-eslint/type-utils": "^8.25.0", diff --git a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/use-state.ts b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/use-state.ts index 5b149e57f0..13d02a55e5 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/use-state.ts +++ b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/use-state.ts @@ -1,6 +1,6 @@ +import { getInstanceId } from "@eslint-react/core"; import { _ } from "@eslint-react/eff"; import type { RuleFeature } from "@eslint-react/shared"; -import * as VAR from "@eslint-react/var"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { snakeCase } from "string-ts"; @@ -35,7 +35,7 @@ export default createRule<[], MessageID>({ if (node.parent.type !== T.VariableDeclarator) { context.report({ messageId: "badValueOrSetterName", node }); } - const id = VAR.getVariableId(node); + const id = getInstanceId(node); if (id?.type !== T.ArrayPattern) { context.report({ messageId: "badValueOrSetterName", node }); return; diff --git a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-interval.ts b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-interval.ts index 4b59257dac..499d4423c4 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-interval.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-interval.ts @@ -1,6 +1,6 @@ import type * as AST from "@eslint-react/ast"; import type { ERPhaseKind } from "@eslint-react/core"; -import { ERPhaseRelevance } from "@eslint-react/core"; +import { ERPhaseRelevance, isInstanceIdEqual } from "@eslint-react/core"; import type { RuleFeature } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; import type { TSESTree } from "@typescript-eslint/utils"; @@ -8,7 +8,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/utils"; import { isMatching, P } from "ts-pattern"; import type { TimerEntry } from "../models"; -import { createRule, getPhaseKindOfFunction, isInstanceIdEqual } from "../utils"; +import { createRule, getPhaseKindOfFunction } from "../utils"; // #region Rule Metadata diff --git a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts index dd6d31462c..7087b4e1ec 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts @@ -1,6 +1,6 @@ import * as AST from "@eslint-react/ast"; import type { ERPhaseKind } from "@eslint-react/core"; -import { ERPhaseRelevance } from "@eslint-react/core"; +import { ERPhaseRelevance, getInstanceId, isInstanceIdEqual } from "@eslint-react/core"; import { _, or } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; @@ -8,7 +8,7 @@ import type { TSESTree } from "@typescript-eslint/utils"; import { AST_NODE_TYPES as T } from "@typescript-eslint/utils"; import { isMatching, match, P } from "ts-pattern"; -import { createRule, getPhaseKindOfFunction, isInstanceIdEqual } from "../utils"; +import { createRule, getPhaseKindOfFunction } from "../utils"; import type { ObserverEntry, ObserverMethod } from "./../models"; // #region Rule Metadata @@ -185,7 +185,7 @@ export default createRule<[], MessageID>({ if (!isNewResizeObserver(node)) { return; } - const id = VAR.getVariableId(node); + const id = getInstanceId(node); if (id == null) { context.report({ messageId: "unexpectedFloatingInstance", diff --git a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-timeout.ts b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-timeout.ts index 5bca5a232f..5590d6e0d7 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-timeout.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-timeout.ts @@ -1,6 +1,6 @@ import type * as AST from "@eslint-react/ast"; import type { ERPhaseKind } from "@eslint-react/core"; -import { ERPhaseRelevance } from "@eslint-react/core"; +import { ERPhaseRelevance, isInstanceIdEqual } from "@eslint-react/core"; import type { RuleFeature } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; import type { TSESTree } from "@typescript-eslint/utils"; @@ -8,7 +8,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/utils"; import { isMatching, P } from "ts-pattern"; import type { TimerEntry } from "../models"; -import { createRule, getPhaseKindOfFunction, isInstanceIdEqual } from "../utils"; +import { createRule, getPhaseKindOfFunction } from "../utils"; // #region Rule Metadata diff --git a/packages/plugins/eslint-plugin-react-web-api/src/utils/index.ts b/packages/plugins/eslint-plugin-react-web-api/src/utils/index.ts index 56a2379dfa..a298edfbfc 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/utils/index.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/utils/index.ts @@ -1,3 +1,2 @@ export * from "./create-rule"; export * from "./get-phase-kind-of-function"; -export * from "./is-instance-id-equal"; diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-context-display-name.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-context-display-name.ts index 66478d8a37..f8112a9a4b 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-context-display-name.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-context-display-name.ts @@ -1,6 +1,10 @@ -import { DISPLAY_NAME_ASSIGNMENT_SELECTOR, isCreateContextCall } from "@eslint-react/core"; +import { + DISPLAY_NAME_ASSIGNMENT_SELECTOR, + getInstanceId, + isCreateContextCall, + isInstanceIdEqual, +} from "@eslint-react/core"; import type { RuleFeature } from "@eslint-react/shared"; -import * as VAR from "@eslint-react/var"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import type { CamelCase } from "string-ts"; @@ -44,7 +48,7 @@ export default createRule<[], MessageID>({ }, "Program:exit"() { for (const call of createCalls) { - const id = VAR.getVariableId(call); + const id = getInstanceId(call); if (id == null) { context.report({ messageId: "noMissingContextDisplayName", @@ -57,10 +61,7 @@ export default createRule<[], MessageID>({ const left = node.left; if (left.type !== T.MemberExpression) return false; const object = left.object; - return VAR.isVariableIdEqual(id, object, [ - context.sourceCode.getScope(id), - context.sourceCode.getScope(object), - ]); + return isInstanceIdEqual(context, id, object); }); if (!hasDisplayNameAssignment) { context.report({ diff --git a/packages/utilities/var/src/index.ts b/packages/utilities/var/src/index.ts index 47119c235a..3f11eae5e7 100644 --- a/packages/utilities/var/src/index.ts +++ b/packages/utilities/var/src/index.ts @@ -2,10 +2,8 @@ export * from "./find-property-in-properties"; export * from "./find-variable"; export * from "./get-child-scopes"; export * from "./get-variable-declarator-id"; -export * from "./get-variable-id"; export * from "./get-variable-node"; export * from "./get-variables"; export * from "./is-node-value-equal"; -export * from "./is-variable-id-equal"; export * from "./lazy-value"; export * from "./value-construction"; diff --git a/packages/utilities/var/src/is-variable-id-equal.ts b/packages/utilities/var/src/is-variable-id-equal.ts deleted file mode 100644 index 4ba657d133..0000000000 --- a/packages/utilities/var/src/is-variable-id-equal.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as AST from "@eslint-react/ast"; -import type { Scope } from "@typescript-eslint/scope-manager"; -import type { TSESTree } from "@typescript-eslint/types"; - -import { isNodeValueEqual } from "./is-node-value-equal"; - -export function isVariableIdEqual( - a: TSESTree.Node, - b: TSESTree.Node, - initialScopes: [ - aScope: Scope, - bScope: Scope, - ], -) { - return AST.isNodeEqual(a, b) || isNodeValueEqual(a, b, initialScopes); -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f7c35ba00..fb11641120 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -998,9 +998,6 @@ importers: '@eslint-react/shared': specifier: workspace:* version: link:../../shared - '@eslint-react/var': - specifier: workspace:* - version: link:../../utilities/var '@typescript-eslint/scope-manager': specifier: ^8.25.0 version: 8.25.0