diff --git a/VERSION b/VERSION index 0d2415b73..44e889f01 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0-next.169 +2.0.0-beta.69 diff --git a/package.json b/package.json index a453d9260..c41fb8db4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/monorepo", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "private": true, "description": "Monorepo for eslint-plugin-react-[x, dom, web-api, hooks-extra, naming-convention].", "keywords": [ diff --git a/packages/core/package.json b/packages/core/package.json index 4efe607c0..e226cbdd6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/core", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/plugins/eslint-plugin-react-debug/package.json b/packages/plugins/eslint-plugin-react-debug/package.json index 33463c55e..985c92cbd 100644 --- a/packages/plugins/eslint-plugin-react-debug/package.json +++ b/packages/plugins/eslint-plugin-react-debug/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-debug", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint plugin for debugging related rules.", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-dom/package.json b/packages/plugins/eslint-plugin-react-dom/package.json index 1affd7917..e16369a2a 100644 --- a/packages/plugins/eslint-plugin-react-dom/package.json +++ b/packages/plugins/eslint-plugin-react-dom/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-dom", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint plugin for React DOM related rules.", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-hooks-extra/package.json b/packages/plugins/eslint-plugin-react-hooks-extra/package.json index d70811f08..99143169e 100644 --- a/packages/plugins/eslint-plugin-react-hooks-extra/package.json +++ b/packages/plugins/eslint-plugin-react-hooks-extra/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-hooks-extra", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint plugin for React Hooks related rules.", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-hooks-extra/src/rules-hooks/use-no-direct-set-state-in-use-effect.ts b/packages/plugins/eslint-plugin-react-hooks-extra/src/rules-hooks/use-no-direct-set-state-in-use-effect.ts index ddea15d1b..ffa03132a 100644 --- a/packages/plugins/eslint-plugin-react-hooks-extra/src/rules-hooks/use-no-direct-set-state-in-use-effect.ts +++ b/packages/plugins/eslint-plugin-react-hooks-extra/src/rules-hooks/use-no-direct-set-state-in-use-effect.ts @@ -6,6 +6,7 @@ import { getSettingsFromContext } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; +import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; import type { Scope } from "@typescript-eslint/utils/ts-eslint"; import { match } from "ts-pattern"; @@ -142,11 +143,7 @@ export function useNoDirectSetStateInUseEffect( return false; } const indexScope = context.sourceCode.getScope(node); - const indexValue = VAR.toStaticValue({ - kind: "lazy", - node: index, - initialScope: indexScope, - }).value; + const indexValue = getStaticValue(index, indexScope)?.value; return indexValue === 1 && isIdFromUseStateCall(callee.object); } // const [data, setData] = useState(); @@ -162,11 +159,7 @@ export function useNoDirectSetStateInUseEffect( } const property = node.callee.property; const propertyScope = context.sourceCode.getScope(node); - const propertyValue = VAR.toStaticValue({ - kind: "lazy", - node: property, - initialScope: propertyScope, - }).value; + const propertyValue = getStaticValue(property, propertyScope)?.value; return propertyValue === 1 && isIdFromUseStateCall(node.callee.object, 1); } default: { diff --git a/packages/plugins/eslint-plugin-react-naming-convention/package.json b/packages/plugins/eslint-plugin-react-naming-convention/package.json index 2ef2e56b7..6073d445b 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/package.json +++ b/packages/plugins/eslint-plugin-react-naming-convention/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-naming-convention", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint plugin for naming convention related rules.", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-web-api/package.json b/packages/plugins/eslint-plugin-react-web-api/package.json index 302d7552e..8db2d86b3 100644 --- a/packages/plugins/eslint-plugin-react-web-api/package.json +++ b/packages/plugins/eslint-plugin-react-web-api/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-web-api", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's ESLint plugin for interacting with Web APIs", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.ts b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.ts index 57133f5f3..54f03ab3f 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.ts @@ -9,6 +9,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/utils"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; import type { EventListenerEntry } from "../types"; +import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; import { isMatching, match, P } from "ts-pattern"; import { createRule, getPhaseKindOfFunction } from "../utils"; @@ -102,7 +103,7 @@ function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope): break; } default: { - v = VAR.toStaticValue({ kind: "lazy", node: value, initialScope }).value; + v = getStaticValue(value, initialScope)?.value; break; } } diff --git a/packages/plugins/eslint-plugin-react-x/package.json b/packages/plugins/eslint-plugin-react-x/package.json index 28ad0c8b0..46739bd95 100644 --- a/packages/plugins/eslint-plugin-react-x/package.json +++ b/packages/plugins/eslint-plugin-react-x/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-react-x", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.", "keywords": [ "react", diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts index 63a7eb48b..6ca4a0e24 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts @@ -14,6 +14,7 @@ import type { CamelCase } from "string-ts"; import { unionConstituents } from "ts-api-utils"; import { match, P } from "ts-pattern"; +import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; import { createRule } from "../utils"; export const RULE_NAME = "no-leaked-conditional-rendering"; @@ -82,9 +83,7 @@ export function create(context: RuleContext): RuleListener { } const initialScope = context.sourceCode.getScope(left); const isLeftNan = (left.type === T.Identifier && left.name === "NaN") - || VAR - .toStaticValue({ kind: "lazy", node: left, initialScope }) - .value === "NaN"; + || getStaticValue(left, initialScope)?.value === "NaN"; if (isLeftNan) { return { messageId: "noLeakedConditionalRendering", diff --git a/packages/plugins/eslint-plugin/package.json b/packages/plugins/eslint-plugin/package.json index ea94ac5ce..330ec4641 100644 --- a/packages/plugins/eslint-plugin/package.json +++ b/packages/plugins/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/eslint-plugin", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "A unified plugin that combines all individual plugins from the eslint-react monorepo into one.", "keywords": [ "react", diff --git a/packages/shared/package.json b/packages/shared/package.json index 7e671afd7..fcd2ad8d1 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/shared", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's Shared constants and functions.", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/utilities/ast/package.json b/packages/utilities/ast/package.json index 9fa0cdd43..9a86f3605 100644 --- a/packages/utilities/ast/package.json +++ b/packages/utilities/ast/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/ast", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's TSESTree AST utility module.", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/utilities/eff/package.json b/packages/utilities/eff/package.json index 62c969060..2be3c8a7e 100644 --- a/packages/utilities/eff/package.json +++ b/packages/utilities/eff/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/eff", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "JavaScript and TypeScript utilities (previously some re-exports of the effect library).", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/utilities/kit/package.json b/packages/utilities/kit/package.json index 0f2b167d5..cf86a2fdb 100644 --- a/packages/utilities/kit/package.json +++ b/packages/utilities/kit/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/kit", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's plugin kit for building plugins and rules.", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/utilities/var/package.json b/packages/utilities/var/package.json index 19563b215..d9515c8fe 100644 --- a/packages/utilities/var/package.json +++ b/packages/utilities/var/package.json @@ -1,6 +1,6 @@ { "name": "@eslint-react/var", - "version": "2.0.0-next.169", + "version": "2.0.0-beta.69", "description": "ESLint React's TSESTree AST utility module for static analysis of variables.", "homepage": "https://github.com/Rel1cx/eslint-react", "bugs": { diff --git a/packages/utilities/var/src/index.ts b/packages/utilities/var/src/index.ts index a257c7c00..2d6eaf363 100644 --- a/packages/utilities/var/src/index.ts +++ b/packages/utilities/var/src/index.ts @@ -1,7 +1,6 @@ export * from "./misc"; export * from "./value-construction"; export * from "./value-equal"; -export * from "./value-helper"; export * from "./variable-assignment"; export type * from "./variable-declaration"; export * from "./variable-extractor"; diff --git a/packages/utilities/var/src/value-equal.ts b/packages/utilities/var/src/value-equal.ts index a95d56f0d..4b32ce8af 100644 --- a/packages/utilities/var/src/value-equal.ts +++ b/packages/utilities/var/src/value-equal.ts @@ -3,7 +3,7 @@ import { unit } from "@eslint-react/eff"; import { DefinitionType, type Scope, type Variable } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { toStaticValue } from "./value-helper"; +import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; import { findVariable } from "./variable-extractor"; import { getVariableDefinitionNode } from "./variable-resolver"; @@ -99,9 +99,9 @@ export function isNodeValueEqual( return aFunction === bFunction; } default: { - const aStatic = toStaticValue({ kind: "lazy", node: a, initialScope: aScope }); - const bStatic = toStaticValue({ kind: "lazy", node: b, initialScope: bScope }); - return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value; + const aStatic = getStaticValue(a, aScope); + const bStatic = getStaticValue(b, bScope); + return aStatic != null && bStatic != null && aStatic.value === bStatic.value; } } } diff --git a/packages/utilities/var/src/value-helper.ts b/packages/utilities/var/src/value-helper.ts deleted file mode 100644 index 91fe73e26..000000000 --- a/packages/utilities/var/src/value-helper.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-disable perfectionist/sort-object-types */ - -import type { unit } from "@eslint-react/eff"; -import type { Scope } from "@typescript-eslint/scope-manager"; -import type { TSESTree } from "@typescript-eslint/types"; -import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; - -export type LazyValue = - | { - // Not resolved yet - kind: "lazy"; - node: TSESTree.Node; - initialScope: Scope | unit; - } - | { - // Resolved to nothing - kind: "none"; - node: TSESTree.Node; - initialScope: Scope | unit; - } - | { - // Resolved to something - kind: "some"; - node: TSESTree.Node; - value: unknown; - initialScope: Scope | unit; - }; - -export function toStaticValue(lazyValue: LazyValue) { - const { kind, node, initialScope } = lazyValue; - if (kind !== "lazy") { - return lazyValue; - } - const staticValue = initialScope == null - ? getStaticValue(node) - : getStaticValue(node, initialScope); - return staticValue == null - ? { kind: "none", node, initialScope } as const - : { kind: "some", node, initialScope, value: staticValue.value } as const; -}