From d2f088d93d1c2b05126b5051d33f7ddd9d1d9b40 Mon Sep 17 00:00:00 2001 From: Rel1cx Date: Sat, 14 Jun 2025 16:31:37 +0800 Subject: [PATCH] refactor: rename '_' to unit --- .pkgs/eslint-plugin-local/dist/index.js | 4 +-- .../src/utils/is-initialized-from-source.ts | 6 ++--- .../type-aliases/ReturnType.md | 4 +-- .../component/component-collector-legacy.ts | 4 +-- .../core/src/component/component-collector.ts | 10 +++---- packages/core/src/component/component-id.ts | 6 ++--- packages/core/src/component/component-name.ts | 6 ++--- .../src/component/component-semantic-node.ts | 12 ++++----- packages/core/src/hook/hook-hierarchy.ts | 6 ++--- packages/core/src/hook/hook-is.ts | 14 +++++----- packages/core/src/hook/hook-semantic-node.ts | 4 +-- packages/core/src/jsx/jsx-attribute.ts | 4 +-- packages/core/src/jsx/jsx-detection.ts | 6 ++--- packages/core/src/jsx/jsx-hierarchy.ts | 4 +-- packages/core/src/jsx/jsx-is.ts | 8 +++--- packages/core/src/semantic/semantic-node.ts | 6 ++--- packages/core/src/utils/get-instance-id.ts | 4 +-- packages/core/src/utils/is-react-api.ts | 16 +++++++----- .../src/rules/no-unsafe-target-blank.ts | 8 +++--- .../src/rules/component-name.ts | 6 ++--- .../src/rules/filename-extension.ts | 4 +-- .../src/rules/filename.ts | 4 +-- .../src/rules/no-leaked-event-listener.ts | 26 +++++++++---------- .../src/rules/no-leaked-resize-observer.ts | 8 +++--- .../types/EventListener/EventListenerEntry.ts | 8 +++--- .../src/rules/no-array-index-key.ts | 20 +++++++------- .../rules/no-leaked-conditional-rendering.ts | 16 ++++++------ .../src/rules/no-unused-state.ts | 4 +-- packages/shared/src/settings.ts | 10 +++---- packages/utilities/ast/src/ast-class-id.ts | 6 ++--- packages/utilities/ast/src/ast-function-id.ts | 6 ++--- .../ast/src/ast-function-init-path.ts | 6 ++--- packages/utilities/ast/src/ast-hierarchy.ts | 17 +++++++----- .../ast/src/ast-process-env-node-env.ts | 6 ++--- .../utilities/ast/src/ast-property-name.ts | 6 ++--- packages/utilities/eff/docs/README.md | 4 +-- packages/utilities/eff/docs/type-aliases.md | 11 -------- .../utilities/eff/docs/type-aliases/unit.md | 11 ++++++++ packages/utilities/eff/docs/variables.md | 11 -------- packages/utilities/eff/docs/variables/unit.md | 11 ++++++++ packages/utilities/eff/src/index.ts | 8 +++--- packages/utilities/kit/src/Reporter.ts | 18 ++++++------- packages/utilities/var/src/var-collect.ts | 14 +++++----- .../utilities/var/src/var-construction.ts | 24 ++++++++--------- .../utilities/var/src/var-declarator-id.ts | 10 +++---- packages/utilities/var/src/var-init-node.ts | 12 ++++----- packages/utilities/var/src/var-value-equal.ts | 8 +++--- packages/utilities/var/src/var-value.ts | 8 +++--- 48 files changed, 220 insertions(+), 215 deletions(-) delete mode 100644 packages/utilities/eff/docs/type-aliases.md create mode 100644 packages/utilities/eff/docs/type-aliases/unit.md delete mode 100644 packages/utilities/eff/docs/variables.md create mode 100644 packages/utilities/eff/docs/variables/unit.md diff --git a/.pkgs/eslint-plugin-local/dist/index.js b/.pkgs/eslint-plugin-local/dist/index.js index c7b8bb0b13..1a817e5807 100644 --- a/.pkgs/eslint-plugin-local/dist/index.js +++ b/.pkgs/eslint-plugin-local/dist/index.js @@ -1,6 +1,6 @@ import * as AST from '@eslint-react/ast'; import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils'; -import { _ } from '@eslint-react/eff'; +import { unit } from '@eslint-react/eff'; import { findVariable } from '@eslint-react/var'; import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types'; import { nullThrows, NullThrowsReasons } from '@typescript-eslint/utils/eslint-utils'; @@ -44,7 +44,7 @@ function getRequireExpressionArguments(node) { return getRequireExpressionArguments(node.object); } } - return _; + return unit; } // src/rules/avoid-multiline-template-expression.ts diff --git a/.pkgs/eslint-plugin-local/src/utils/is-initialized-from-source.ts b/.pkgs/eslint-plugin-local/src/utils/is-initialized-from-source.ts index 3d7eb69c26..053e6e59ca 100644 --- a/.pkgs/eslint-plugin-local/src/utils/is-initialized-from-source.ts +++ b/.pkgs/eslint-plugin-local/src/utils/is-initialized-from-source.ts @@ -1,7 +1,7 @@ import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { findVariable } from "@eslint-react/var"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -46,7 +46,7 @@ export function isInitializedFromSource( return parent?.type === T.ImportDeclaration && parent.source.value === source; } -function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpressionArgument[] | _ { +function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpressionArgument[] | unit { switch (true) { // require('source') case node.type === T.CallExpression @@ -59,5 +59,5 @@ function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpres return getRequireExpressionArguments(node.object); } } - return _; + return unit; } diff --git a/packages/core/docs/@eslint-react/namespaces/useComponentCollector/type-aliases/ReturnType.md b/packages/core/docs/@eslint-react/namespaces/useComponentCollector/type-aliases/ReturnType.md index 8bfc9c78dc..7ea4606e56 100644 --- a/packages/core/docs/@eslint-react/namespaces/useComponentCollector/type-aliases/ReturnType.md +++ b/packages/core/docs/@eslint-react/namespaces/useComponentCollector/type-aliases/ReturnType.md @@ -38,11 +38,11 @@ #### getCurrentEntry() -> **getCurrentEntry**: () => `FunctionEntry` \| `_` +> **getCurrentEntry**: () => `FunctionEntry` \| `unit` ##### Returns -`FunctionEntry` \| `_` +`FunctionEntry` \| `unit` *** diff --git a/packages/core/src/component/component-collector-legacy.ts b/packages/core/src/component/component-collector-legacy.ts index 366615ab3d..6eeb7a9657 100644 --- a/packages/core/src/component/component-collector-legacy.ts +++ b/packages/core/src/component/component-collector-legacy.ts @@ -1,7 +1,7 @@ import type { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; import type { ClassComponent } from "./component-semantic-node"; import * as AST from "@eslint-react/ast"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { getId } from "@eslint-react/shared"; import { ComponentFlag } from "./component-flag"; @@ -48,7 +48,7 @@ export function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retur name: id?.name, node, // TODO: Get displayName of class component - displayName: _, + displayName: unit, flag, hint: 0n, // TODO: Get methods of class component diff --git a/packages/core/src/component/component-collector.ts b/packages/core/src/component/component-collector.ts index a8d1fe5d18..cddc8d6c65 100644 --- a/packages/core/src/component/component-collector.ts +++ b/packages/core/src/component/component-collector.ts @@ -3,7 +3,7 @@ import type { ESLintUtils } from "@typescript-eslint/utils"; import type { ComponentDetectionHint } from "./component-detection-hint"; import type { FunctionComponent } from "./component-semantic-node"; import * as AST from "@eslint-react/ast"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { type RuleContext, Selector as SEL } from "@eslint-react/kit"; import { getId } from "@eslint-react/shared"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -33,7 +33,7 @@ export declare namespace useComponentCollector { ctx: { getAllComponents: (node: TSESTree.Program) => Map; getCurrentEntries: () => FunctionEntry[]; - getCurrentEntry: () => FunctionEntry | _; + getCurrentEntry: () => FunctionEntry | unit; }; listeners: ESLintUtils.RuleListener; }; @@ -114,7 +114,7 @@ export function useComponentCollector( kind: "function", name, node: entry.node, - displayName: _, + displayName: unit, flag: getComponentFlagFromInitPath(initPath), hint, hookCalls: entry.hookCalls, @@ -128,7 +128,7 @@ export function useComponentCollector( if (left.type !== T.MemberExpression) return; const componentName = left.object.type === T.Identifier ? left.object.name - : _; + : unit; const component = [...components.values()] .findLast(({ name }) => name != null && name === componentName); if (component == null) return; @@ -163,7 +163,7 @@ export function useComponentCollector( kind: "function", name, node: entry.node, - displayName: _, + displayName: unit, flag: getComponentFlagFromInitPath(initPath), hint, hookCalls: entry.hookCalls, diff --git a/packages/core/src/component/component-id.ts b/packages/core/src/component/component-id.ts index 07b7b351d6..6fac83d674 100644 --- a/packages/core/src/component/component-id.ts +++ b/packages/core/src/component/component-id.ts @@ -1,14 +1,14 @@ import type { RuleContext } from "@eslint-react/kit"; import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { isComponentWrapperCallLoose } from "./component-wrapper"; export function getFunctionComponentId( context: RuleContext, node: AST.TSESTreeFunction, -): TSESTree.Identifier | TSESTree.Identifier[] | _ { +): TSESTree.Identifier | TSESTree.Identifier[] | unit { const functionId = AST.getFunctionId(node); if (functionId != null) { return functionId; @@ -34,5 +34,5 @@ export function getFunctionComponentId( ) { return parent.parent.parent.id; } - return _; + return unit; } diff --git a/packages/core/src/component/component-name.ts b/packages/core/src/component/component-name.ts index 61c9e47104..62953cac7f 100644 --- a/packages/core/src/component/component-name.ts +++ b/packages/core/src/component/component-name.ts @@ -1,7 +1,7 @@ import type * as AST from "@eslint-react/ast"; import type { RuleContext } from "@eslint-react/kit"; import type { TSESTree } from "@typescript-eslint/types"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { RegExp as RE } from "@eslint-react/kit"; import { getFunctionComponentId } from "./component-id"; @@ -14,8 +14,8 @@ export function isComponentNameLoose(name: string) { return RE.COMPONENT_NAME_LOOSE.test(name); } -export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | _) { - if (id == null) return _; +export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit) { + if (id == null) return unit; return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name; diff --git a/packages/core/src/component/component-semantic-node.ts b/packages/core/src/component/component-semantic-node.ts index 72eeec40b4..f81400a501 100644 --- a/packages/core/src/component/component-semantic-node.ts +++ b/packages/core/src/component/component-semantic-node.ts @@ -1,5 +1,5 @@ import type * as AST from "@eslint-react/ast"; -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import type { SemanticNode } from "../semantic"; @@ -9,7 +9,7 @@ import type { ComponentFlag } from "./component-flag"; /* eslint-disable perfectionist/sort-interfaces */ export interface FunctionComponent extends SemanticNode { id: - | _ + | unit | TSESTree.Identifier | TSESTree.Identifier[]; kind: "function"; @@ -17,17 +17,17 @@ export interface FunctionComponent extends SemanticNode { flag: ComponentFlag; hint: ComponentDetectionHint; initPath: - | _ + | unit | AST.FunctionInitPath; hookCalls: TSESTree.CallExpression[]; displayName: - | _ + | unit | TSESTree.Expression; } export interface ClassComponent extends SemanticNode { id: - | _ + | unit | TSESTree.Identifier; kind: "class"; node: AST.TSESTreeClass; @@ -35,7 +35,7 @@ export interface ClassComponent extends SemanticNode { hint: ComponentDetectionHint; methods: AST.TSESTreeMethodOrProperty[]; displayName: - | _ + | unit | TSESTree.Expression; } /* eslint-enable perfectionist/sort-interfaces */ diff --git a/packages/core/src/hook/hook-hierarchy.ts b/packages/core/src/hook/hook-hierarchy.ts index 7109ae71be..356900bc8f 100644 --- a/packages/core/src/hook/hook-hierarchy.ts +++ b/packages/core/src/hook/hook-hierarchy.ts @@ -1,10 +1,10 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { isUseEffectCallLoose } from "./hook-is"; -export function isFunctionOfUseEffectSetup(node: TSESTree.Node | _) { +export function isFunctionOfUseEffectSetup(node: TSESTree.Node | unit) { if (node == null) return false; return node.parent?.type === T.CallExpression && node.parent.callee !== node @@ -13,7 +13,7 @@ export function isFunctionOfUseEffectSetup(node: TSESTree.Node | _) { && isUseEffectCallLoose(node.parent); } -export function isFunctionOfUseEffectCleanup(node: TSESTree.Node | _) { +export function isFunctionOfUseEffectCleanup(node: TSESTree.Node | unit) { if (node == null) return false; const pReturn = AST.findParentNode(node, AST.is(T.ReturnStatement)); const pFunction = AST.findParentNode(node, AST.isFunction); // Correctly named variable diff --git a/packages/core/src/hook/hook-is.ts b/packages/core/src/hook/hook-is.ts index 6185160cbd..965af56a76 100644 --- a/packages/core/src/hook/hook-is.ts +++ b/packages/core/src/hook/hook-is.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext } from "@eslint-react/kit"; import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; @@ -9,7 +9,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { isInitializedFromReact } from "../utils"; import { isReactHookName } from "./hook-name"; -export function isReactHook(node: AST.TSESTreeFunction | _) { +export function isReactHook(node: AST.TSESTreeFunction | unit) { if (node == null) return false; const id = AST.getFunctionId(node); return id?.name != null && isReactHookName(id.name); @@ -20,7 +20,7 @@ export function isReactHook(node: AST.TSESTreeFunction | _) { * @param node The node to check. * @returns `true` if the node is a React Hook call, `false` otherwise. */ -export function isReactHookCall(node: TSESTree.Node | _) { +export function isReactHookCall(node: TSESTree.Node | unit) { if (node == null) return false; if (node.type !== T.CallExpression) { return false; @@ -35,7 +35,7 @@ export function isReactHookCall(node: TSESTree.Node | _) { } /* eslint-disable function/function-return-boolean */ -export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Node | _) { +export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Node | unit) { if (node == null || node.type !== T.CallExpression) return constFalse; const { importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource, @@ -58,7 +58,7 @@ export function isReactHookCallWithName(context: RuleContext, node: TSESTree.Nod }; } -export function isReactHookCallWithNameLoose(node: TSESTree.Node | _) { +export function isReactHookCallWithNameLoose(node: TSESTree.Node | unit) { if (node == null || node.type !== T.CallExpression) return constFalse; return (name: string) => { switch (node.callee.type) { @@ -72,7 +72,7 @@ export function isReactHookCallWithNameLoose(node: TSESTree.Node | _) { }; } -export function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: _ | string[] = []) { +export function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: unit | string[] = []) { const { importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource, skipImportCheck = true, @@ -95,7 +95,7 @@ export function isReactHookCallWithNameAlias(context: RuleContext, name: string, } /* eslint-enable function/function-return-boolean */ -export function isUseEffectCallLoose(node: TSESTree.Node | _) { +export function isUseEffectCallLoose(node: TSESTree.Node | unit) { if (node == null) return false; if (node.type !== T.CallExpression) { return false; diff --git a/packages/core/src/hook/hook-semantic-node.ts b/packages/core/src/hook/hook-semantic-node.ts index 7cefc712d9..499bb73920 100644 --- a/packages/core/src/hook/hook-semantic-node.ts +++ b/packages/core/src/hook/hook-semantic-node.ts @@ -1,5 +1,5 @@ import type * as AST from "@eslint-react/ast"; -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import type { SemanticNode } from "../semantic"; @@ -7,7 +7,7 @@ import type { SemanticNode } from "../semantic"; /* eslint-disable perfectionist/sort-interfaces */ export interface Hook extends SemanticNode { // The identifier of the hook - id: TSESTree.Identifier | _; + id: TSESTree.Identifier | unit; // The AST node of the hook node: AST.TSESTreeFunction; // The name of the hook diff --git a/packages/core/src/jsx/jsx-attribute.ts b/packages/core/src/jsx/jsx-attribute.ts index 14b521a929..ca9d3a678f 100644 --- a/packages/core/src/jsx/jsx-attribute.ts +++ b/packages/core/src/jsx/jsx-attribute.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext } from "@eslint-react/kit"; import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/utils"; @@ -20,7 +20,7 @@ export function getAttribute( name: string, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], initialScope?: Scope, -): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _ { +): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | unit { return attributes.findLast((attr) => { if (attr.type === T.JSXAttribute) { return getAttributeName(context, attr) === name; diff --git a/packages/core/src/jsx/jsx-detection.ts b/packages/core/src/jsx/jsx-detection.ts index d4cff87a73..df4b8dda65 100644 --- a/packages/core/src/jsx/jsx-detection.ts +++ b/packages/core/src/jsx/jsx-detection.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/utils"; import * as AST from "@eslint-react/ast"; @@ -12,7 +12,7 @@ import { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint } from "./jsx-detection-hi * @param node The AST node to check * @returns `true` if the node is a `JSXText` or a `Literal` node */ -export function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal { +export function isJsxText(node: TSESTree.Node | null | unit): node is TSESTree.JSXText | TSESTree.Literal { if (node == null) return false; return node.type === T.JSXText || node.type === T.Literal; } @@ -27,7 +27,7 @@ export function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXT */ export function isJsxLike( code: { getScope: (node: TSESTree.Node) => Scope }, - node: TSESTree.Node | _ | null, + node: TSESTree.Node | unit | null, hint: JSXDetectionHint = DEFAULT_JSX_DETECTION_HINT, ): boolean { if (node == null) return false; diff --git a/packages/core/src/jsx/jsx-hierarchy.ts b/packages/core/src/jsx/jsx-hierarchy.ts index 7b295fd094..2cbac0779c 100644 --- a/packages/core/src/jsx/jsx-hierarchy.ts +++ b/packages/core/src/jsx/jsx-hierarchy.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; import { constTrue } from "@eslint-react/eff"; @@ -13,7 +13,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; export function findParentAttribute( node: TSESTree.Node, test: (node: TSESTree.JSXAttribute) => boolean = constTrue, -): TSESTree.JSXAttribute | _ { +): TSESTree.JSXAttribute | unit { const guard = (node: TSESTree.Node): node is TSESTree.JSXAttribute => { return node.type === T.JSXAttribute && test(node); }; diff --git a/packages/core/src/jsx/jsx-is.ts b/packages/core/src/jsx/jsx-is.ts index 9bed93f212..0ce0d5c02c 100644 --- a/packages/core/src/jsx/jsx-is.ts +++ b/packages/core/src/jsx/jsx-is.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext } from "@eslint-react/kit"; import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; @@ -19,17 +19,17 @@ export function isKeyedElement(context: RuleContext, node: TSESTree.Node, initia export function isFragmentElement( context: RuleContext, - node: TSESTree.Node | null | _, + node: TSESTree.Node | null | unit, allowJSXFragment?: false, ): node is TSESTree.JSXElement; export function isFragmentElement( context: RuleContext, - node: TSESTree.Node | null | _, + node: TSESTree.Node | null | unit, allowJSXFragment?: true, ): node is TSESTree.JSXElement | TSESTree.JSXFragment; export function isFragmentElement( context: RuleContext, - node: TSESTree.Node | null | _, + node: TSESTree.Node | null | unit, allowJSXFragment = false, ): node is TSESTree.JSXElement | TSESTree.JSXFragment { if (node == null) return false; diff --git a/packages/core/src/semantic/semantic-node.ts b/packages/core/src/semantic/semantic-node.ts index 01139f1f92..cadbeb332b 100644 --- a/packages/core/src/semantic/semantic-node.ts +++ b/packages/core/src/semantic/semantic-node.ts @@ -1,15 +1,15 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; export interface SemanticNode { id: - | _ + | unit | TSESTree.Identifier | TSESTree.Identifier[]; key: string; kind: string; name: - | _ + | unit | string; node: TSESTree.Node; flag: bigint; diff --git a/packages/core/src/utils/get-instance-id.ts b/packages/core/src/utils/get-instance-id.ts index 56de0a2b4d..f0f575821e 100644 --- a/packages/core/src/utils/get-instance-id.ts +++ b/packages/core/src/utils/get-instance-id.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/require-param */ import type { TSESTree } from "@typescript-eslint/types"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; /** @internal */ @@ -18,7 +18,7 @@ export function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node) { case node.type === T.BlockStatement || node.type === T.Program || node.parent === node: - return _; + return unit; default: return getInstanceId(node.parent, node); } diff --git a/packages/core/src/utils/is-react-api.ts b/packages/core/src/utils/is-react-api.ts index ec4776de2c..fa1637f800 100644 --- a/packages/core/src/utils/is-react-api.ts +++ b/packages/core/src/utils/is-react-api.ts @@ -1,18 +1,20 @@ /* eslint-disable function/function-return-boolean */ import type { RuleContext } from "@eslint-react/kit"; import * as AST from "@eslint-react/ast"; -import { type _, dual } from "@eslint-react/eff"; +import { dual, type unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T, type TSESTree } from "@typescript-eslint/types"; export declare namespace isReactAPI { type ReturnType = { - (context: RuleContext, node: _ | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression; - (context: RuleContext): (node: _ | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier; + (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression; + ( + context: RuleContext, + ): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier; }; } export function isReactAPI(api: string): isReactAPI.ReturnType { - const func = (context: RuleContext, node: _ | null | TSESTree.Node): node is + const func = (context: RuleContext, node: unit | null | TSESTree.Node): node is | TSESTree.Identifier | TSESTree.MemberExpression => { @@ -28,13 +30,13 @@ export function isReactAPI(api: string): isReactAPI.ReturnType { export declare namespace isReactAPICall { type ReturnType = { - (context: RuleContext, node: _ | null | TSESTree.Node): node is TSESTree.CallExpression; - (context: RuleContext): (node: _ | null | TSESTree.Node) => node is TSESTree.CallExpression; + (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression; + (context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression; }; } export function isReactAPICall(api: string): isReactAPICall.ReturnType { - const func = (context: RuleContext, node: _ | null | TSESTree.Node): node is TSESTree.CallExpression => { + const func = (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression => { if (node == null) return false; if (node.type !== T.CallExpression) return false; return isReactAPI(api)(context, node.callee); diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-target-blank.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-target-blank.ts index 8376b5a276..c4bb2d7e24 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-target-blank.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-target-blank.ts @@ -4,7 +4,7 @@ import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; import type { CamelCase } from "string-ts"; import * as ER from "@eslint-react/core"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { createJsxElementResolver, createRule, findCustomComponentProp } from "../utils"; @@ -14,13 +14,13 @@ export const RULE_FEATURES = [] as const satisfies RuleFeature[]; export type MessageID = CamelCase; -function isExternalLinkLike(value: string | _) { +function isExternalLinkLike(value: string | unit) { if (value == null) return false; return value.startsWith("https://") || /^(?:\w+:|\/\/)/u.test(value); } -function isSafeRel(value: string | _) { +function isSafeRel(value: string | unit) { if (value == null) return false; return value === "noreferrer" || /\bnoreferrer\b/u.test(value); @@ -66,7 +66,7 @@ export function create(context: RuleContext): RuleListener { if (attributeValue.kind === "some" && typeof attributeValue.value === "string") { return attributeValue.value; } - return _; + return unit; }; if (getAttributeStringValue("target") !== "_blank") { diff --git a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/component-name.ts b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/component-name.ts index d6249b93be..cf293a77f2 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/component-name.ts +++ b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/component-name.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/kit"; import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; @@ -11,7 +11,7 @@ import { createRule } from "../utils"; type Case = "CONSTANT_CASE" | "PascalCase"; type Options = readonly [ - | _ + | unit | Case | { allowAllCaps?: boolean; @@ -152,7 +152,7 @@ function normalizeOptions(options: Options) { } as const; } -function isValidName(name: string | _, options: ReturnType) { +function isValidName(name: string | unit, options: ReturnType) { if (name == null) return true; if (options.excepts.some((regex) => regex.test(name))) return true; const normalized = name.split(".").at(-1) ?? name; diff --git a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename-extension.ts b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename-extension.ts index 29c8433994..700317bbf5 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename-extension.ts +++ b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename-extension.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/kit"; import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; @@ -19,7 +19,7 @@ export type MessageID = type Allow = "always" | "as-needed"; type Options = readonly [ - | _ + | unit | Allow | { allow?: Allow; diff --git a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename.ts b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename.ts index 53c40089dd..d273a7d089 100644 --- a/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename.ts +++ b/packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/kit"; import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; @@ -22,7 +22,7 @@ export type MessageID = type Case = "camelCase" | "kebab-case" | "PascalCase" | "snake_case"; type Options = readonly [ - | _ + | unit | Case | { /** 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 fbd7e2f430..41a5a47d77 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 @@ -5,7 +5,7 @@ import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; import type { EventListenerEntry } from "../types"; import * as AST from "@eslint-react/ast"; import * as ER from "@eslint-react/core"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import * as VAR from "@eslint-react/var"; import { AST_NODE_TYPES as T } from "@typescript-eslint/utils"; @@ -42,13 +42,13 @@ export type REntry = EventListenerEntry & { kind: "removeEventListener" }; // #region Helpers const defaultOptions: { - capture: boolean | _; - // once: boolean | _; - signal: TSESTree.Node | _; + capture: boolean | unit; + // once: boolean | unit; + signal: TSESTree.Node | unit; } = { capture: false, // once: false, - signal: _, + signal: unit, }; function getCallKind(node: TSESTree.CallExpression): CallKind { @@ -69,8 +69,8 @@ function getFunctionKind(node: AST.TSESTreeFunction): FunctionKind { return getPhaseKindOfFunction(node) ?? "other"; } -function getSignalValueExpression(node: TSESTree.Node | _, initialScope: Scope): TSESTree.Node | _ { - if (node == null) return _; +function getSignalValueExpression(node: TSESTree.Node | unit, initialScope: Scope): TSESTree.Node | unit { + if (node == null) return unit; switch (node.type) { case T.Identifier: { return getSignalValueExpression(VAR.getVariableInitNode(VAR.findVariable(node, initialScope), 0), initialScope); @@ -78,7 +78,7 @@ function getSignalValueExpression(node: TSESTree.Node | _, initialScope: Scope): case T.MemberExpression: return node; default: - return _; + return unit; } } @@ -87,10 +87,10 @@ function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope): return VAR.findPropertyInProperties(propName, properties, initialScope); } function getPropValue( - prop: TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement | _, + prop: TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement | unit, filter: (value: unknown) => value is A = (a): a is A => true, - ): A | _ { - if (prop?.type !== T.Property) return _; + ): A | unit { + if (prop?.type !== T.Property) return unit; const { value } = prop; let v: unknown = value; switch (value.type) { @@ -103,7 +103,7 @@ function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope): break; } } - return filter(v) ? v : _; + return filter(v) ? v : unit; } function getOpts(node: TSESTree.Node): typeof defaultOptions { switch (node.type) { @@ -127,7 +127,7 @@ function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope): const pSignal = findProp(node.properties, "signal"); const vSignal = pSignal?.type === T.Property ? getSignalValueExpression(pSignal.value, initialScope) - : _; + : unit; return { capture: vCapture, signal: vSignal }; } default: { 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 ac538750bc..e8065699b8 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,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/kit"; import type { TSESTree } from "@typescript-eslint/utils"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; @@ -39,7 +39,7 @@ export type DEntry = ObserverEntry & { kind: "disconnect" }; // #region Helpers -function isNewResizeObserver(node: TSESTree.Node | _) { +function isNewResizeObserver(node: TSESTree.Node | unit) { return node?.type === T.NewExpression && node.callee.type === T.Identifier && node.callee.name === "ResizeObserver"; @@ -210,8 +210,8 @@ export function create(context: RuleContext): RuleListener { } const oentries = oEntries.filter((e) => ER.isInstanceIdEqual(context, e.observer, id)); const uentries = uEntries.filter((e) => ER.isInstanceIdEqual(context, e.observer, id)); - const isDynamic = (node: TSESTree.Node | _) => node?.type === T.CallExpression || AST.isConditional(node); - const isPhaseNode = (node: TSESTree.Node | _) => node === phaseNode; + const isDynamic = (node: TSESTree.Node | unit) => node?.type === T.CallExpression || AST.isConditional(node); + const isPhaseNode = (node: TSESTree.Node | unit) => node === phaseNode; const hasDynamicallyAdded = oentries .some((e) => !isPhaseNode(AST.findParentNode(e.node, or(isDynamic, isPhaseNode)))); if (hasDynamicallyAdded) { diff --git a/packages/plugins/eslint-plugin-react-web-api/src/types/EventListener/EventListenerEntry.ts b/packages/plugins/eslint-plugin-react-web-api/src/types/EventListener/EventListenerEntry.ts index eaee30e4a0..f33d965f9f 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/types/EventListener/EventListenerEntry.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/types/EventListener/EventListenerEntry.ts @@ -1,5 +1,5 @@ import type * as ER from "@eslint-react/core"; -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; export type EventListenerEntry = @@ -8,15 +8,15 @@ export type EventListenerEntry = type: TSESTree.Node; node: TSESTree.CallExpression | TSESTree.Identifier; callee: TSESTree.Node; - capture: boolean | _; + capture: boolean | unit; listener: TSESTree.Node; - signal: TSESTree.Node | _; + signal: TSESTree.Node | unit; } & ER.SemanticEntry | { kind: "removeEventListener"; type: TSESTree.Node; node: TSESTree.CallExpression | TSESTree.Identifier; callee: TSESTree.Node; - capture: boolean | _; + capture: boolean | unit; listener: TSESTree.Node; } & ER.SemanticEntry; diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.ts index 2ab622f4da..a437b3f622 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.ts @@ -3,7 +3,7 @@ import type { ReportDescriptor, RuleListener } from "@typescript-eslint/utils/ts import type { CamelCase } from "string-ts"; import * as AST from "@eslint-react/ast"; import * as ER from "@eslint-react/core"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { Reporter as RPT, type RuleContext, type RuleFeature } from "@eslint-react/kit"; import { coerceSettings } from "@eslint-react/shared"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -42,35 +42,35 @@ function isUsingReactChildren(context: RuleContext, node: TSESTree.CallExpressio return false; } -function getMapIndexParamName(context: RuleContext, node: TSESTree.CallExpression): string | _ { +function getMapIndexParamName(context: RuleContext, node: TSESTree.CallExpression): string | unit { const { callee } = node; if (callee.type !== T.MemberExpression) { - return _; + return unit; } if (callee.property.type !== T.Identifier) { - return _; + return unit; } const { name } = callee.property; const indexPosition = AST.getArrayMethodCallbackIndexParamPosition(name); if (indexPosition === -1) { - return _; + return unit; } const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0]; if (callbackArg == null) { - return _; + return unit; } if (!AST.isOneOf([T.ArrowFunctionExpression, T.FunctionExpression])(callbackArg)) { - return _; + return unit; } const { params } = callbackArg; if (params.length < indexPosition + 1) { - return _; + return unit; } const param = params.at(indexPosition); return param != null && "name" in param ? param.name - : _; + : unit; } function getIdentifiersFromBinaryExpression( @@ -110,7 +110,7 @@ export default createRule<[], MessageID>({ export function create(context: RuleContext): RuleListener { const report = RPT.make(context); - const indexParamNames: Array = []; + const indexParamNames: Array = []; function isArrayIndex(node: TSESTree.Node): node is TSESTree.Identifier { return node.type === T.Identifier 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 2a275abfd5..73c4640633 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 @@ -2,7 +2,7 @@ import type { TSESTree } from "@typescript-eslint/types"; import type { ReportDescriptor, RuleListener } from "@typescript-eslint/utils/ts-eslint"; import type { CamelCase } from "string-ts"; import * as AST from "@eslint-react/ast"; -import { _, flow } from "@eslint-react/eff"; +import { flow, unit } from "@eslint-react/eff"; import { Reporter as RPT, type RuleContext, type RuleFeature } from "@eslint-react/kit"; import { getSettingsFromContext } from "@eslint-react/shared"; import * as VAR from "@eslint-react/var"; @@ -214,16 +214,16 @@ export function create(context: RuleContext): RuleListener { const services = ESLintUtils.getParserServices(context, false); function getReportDescriptor( node: - | _ + | unit | TSESTree.Expression | TSESTree.JSXExpressionContainer | TSESTree.JSXExpressionContainer["expression"], - ): ReportDescriptor | _ { - if (node == null) return _; + ): ReportDescriptor | unit { + if (node == null) return unit; if (AST.is(T.JSXExpressionContainer)(node)) return getReportDescriptor(node.expression); - if (AST.isJSX(node)) return _; + if (AST.isJSX(node)) return unit; if (AST.isTypeExpression(node)) return getReportDescriptor(node.expression); - return match | _>(node) + return match | unit>(node) .with({ type: T.LogicalExpression, operator: "&&" }, ({ left, right }) => { const isLeftUnaryNot = left.type === T.UnaryExpression && left.operator === "!"; if (isLeftUnaryNot) { @@ -263,9 +263,9 @@ export function create(context: RuleContext): RuleListener { const variableDefNode = variable?.defs.at(0)?.node; return match(variableDefNode) .with({ init: P.select({ type: P.not(T.VariableDeclaration) }) }, getReportDescriptor) - .otherwise(() => _); + .otherwise(() => unit); }) - .otherwise(() => _); + .otherwise(() => unit); } return { JSXExpressionContainer: flow(getReportDescriptor, RPT.make(context).send), diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-state.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-state.ts index df9832209d..e33d15c356 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-state.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-unused-state.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { RuleContext, RuleFeature } from "@eslint-react/kit"; import type { TSESTree } from "@typescript-eslint/utils"; import type { RuleListener } from "@typescript-eslint/utils/ts-eslint"; @@ -53,7 +53,7 @@ export function create(context: RuleContext): RuleListener { const classEntries: AST.TSESTreeClass[] = []; const methodEntries: AST.TSESTreeMethodOrProperty[] = []; const constructorEntries: TSESTree.MethodDefinition[] = []; - const stateDefs = new WeakMap(); + const stateDefs = new WeakMap(); function classEnter(node: AST.TSESTreeClass) { classEntries.push(node); } diff --git a/packages/shared/src/settings.ts b/packages/shared/src/settings.ts index 84e9527b45..39dcf7c791 100644 --- a/packages/shared/src/settings.ts +++ b/packages/shared/src/settings.ts @@ -1,5 +1,5 @@ /* eslint-disable perfectionist/sort-objects */ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { ESLint, SharedConfigurationSettings } from "@typescript-eslint/utils/ts-eslint"; // eslint-disable-line @typescript-eslint/no-unused-vars import type { PartialDeep } from "type-fest"; import { getOrElseUpdate, identity } from "@eslint-react/eff"; @@ -206,8 +206,8 @@ export const DEFAULT_ESLINT_SETTINGS = { export interface CustomComponentPropNormalized { name: string; as: string; - // controlled?: boolean | _; - defaultValue?: string | _; + // controlled?: boolean | unit; + defaultValue?: string | unit; } export interface CustomComponentNormalized { @@ -215,14 +215,14 @@ export interface CustomComponentNormalized { as: string; attributes: CustomComponentPropNormalized[]; re: { test(s: string): boolean }; - // selector?: string | _; + // selector?: string | unit; } export interface ESLintReactSettingsNormalized { additionalHooks: CustomHooks; components: CustomComponentNormalized[]; importSource: string; - polymorphicPropName: string | _; + polymorphicPropName: string | unit; skipImportCheck: boolean; strict: boolean; version: string; diff --git a/packages/utilities/ast/src/ast-class-id.ts b/packages/utilities/ast/src/ast-class-id.ts index e32b4e82b7..fc047766da 100644 --- a/packages/utilities/ast/src/ast-class-id.ts +++ b/packages/utilities/ast/src/ast-class-id.ts @@ -1,6 +1,6 @@ import type { TSESTree } from "@typescript-eslint/types"; import type { TSESTreeClass } from "./ast-node"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -9,10 +9,10 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; * @param node The AST node to check * @returns class identifier or null */ -export function getClassId(node: TSESTreeClass): TSESTree.Identifier | _ { +export function getClassId(node: TSESTreeClass): unit | TSESTree.Identifier { if (node.id != null) return node.id; if (node.parent.type === T.VariableDeclarator && node.parent.id.type === T.Identifier) { return node.parent.id; } - return _; + return unit; } diff --git a/packages/utilities/ast/src/ast-function-id.ts b/packages/utilities/ast/src/ast-function-id.ts index 673205a320..89937bbb0c 100644 --- a/packages/utilities/ast/src/ast-function-id.ts +++ b/packages/utilities/ast/src/ast-function-id.ts @@ -9,12 +9,12 @@ import type { TSESTree } from "@typescript-eslint/types"; import type { TSESTreeFunction } from "./ast-node"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { isMethodOrProperty, isTypeAssertionExpression } from "./ast-is"; -export function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _ { +export function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): unit | TSESTree.Identifier { switch (true) { // function MaybeComponent() {} case "id" in node @@ -58,5 +58,5 @@ export function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSE case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent); } - return _; + return unit; } diff --git a/packages/utilities/ast/src/ast-function-init-path.ts b/packages/utilities/ast/src/ast-function-init-path.ts index 53c98afd1c..c658c050bc 100644 --- a/packages/utilities/ast/src/ast-function-init-path.ts +++ b/packages/utilities/ast/src/ast-function-init-path.ts @@ -1,6 +1,6 @@ import type { TSESTree } from "@typescript-eslint/types"; import type { TSESTreeFunction } from "./ast-node"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -103,7 +103,7 @@ export type FunctionInitPath = TSESTreeFunction, ]; -export function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _ { +export function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath { if (node.type === T.FunctionDeclaration) { return [node] as const; } @@ -129,7 +129,7 @@ export function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | && parent.parent.parent.type === T.ClassDeclaration: return [parent.parent.parent, parent.parent, parent, node] as const; } - return _; + return unit; } export function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath) { diff --git a/packages/utilities/ast/src/ast-hierarchy.ts b/packages/utilities/ast/src/ast-hierarchy.ts index 0a4820908a..e512d5f834 100644 --- a/packages/utilities/ast/src/ast-hierarchy.ts +++ b/packages/utilities/ast/src/ast-hierarchy.ts @@ -1,4 +1,4 @@ -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T, type TSESTree } from "@typescript-eslint/types"; import { simpleTraverse } from "@typescript-eslint/typescript-estree"; import { is, isFunction } from "./ast-is"; @@ -9,19 +9,22 @@ import { is, isFunction } from "./ast-is"; * @param test The test function * @returns The parent node that satisfies the test function or `_` if not found */ -function findParentNode(node: TSESTree.Node | _, test: (n: TSESTree.Node) => n is A): A | _; +function findParentNode( + node: TSESTree.Node | unit, + test: (n: TSESTree.Node) => n is A, +): A | unit; /** * Find the parent node that satisfies the test function or `_` if not found * @param node The AST node * @param test The test function * @returns The parent node that satisfies the test function */ -function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _; +function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit; function findParentNode( - node: TSESTree.Node | _, + node: TSESTree.Node | unit, test: ((node: TSESTree.Node) => boolean) | ((n: TSESTree.Node) => n is A), -): TSESTree.Node | A | _ { - if (node == null) return _; +): TSESTree.Node | A | unit { + if (node == null) return unit; let parent = node.parent; while (parent != null && parent.type !== T.Program) { if (test(parent)) { @@ -29,7 +32,7 @@ function findParentNode( } parent = parent.parent; } - return _; + return unit; } export { findParentNode }; diff --git a/packages/utilities/ast/src/ast-process-env-node-env.ts b/packages/utilities/ast/src/ast-process-env-node-env.ts index d376ac519a..eaaeb77c81 100644 --- a/packages/utilities/ast/src/ast-process-env-node-env.ts +++ b/packages/utilities/ast/src/ast-process-env-node-env.ts @@ -1,4 +1,4 @@ -import type { _ } from "@eslint-react/eff"; +import type { unit } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { isLiteral } from "./ast-literal-is"; @@ -8,7 +8,7 @@ import { isLiteral } from "./ast-literal-is"; * @param node The AST node * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise */ -export function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TSESTree.MemberExpression { +export function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression { return node != null && node.type === T.MemberExpression && node.object.type === T.MemberExpression @@ -28,7 +28,7 @@ export function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TSE * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise */ export function isProcessEnvNodeEnvCompare( - node: TSESTree.Node | null | _, + node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production", ): node is TSESTree.BinaryExpression { diff --git a/packages/utilities/ast/src/ast-property-name.ts b/packages/utilities/ast/src/ast-property-name.ts index f7f47d8b95..044b2494c7 100644 --- a/packages/utilities/ast/src/ast-property-name.ts +++ b/packages/utilities/ast/src/ast-property-name.ts @@ -1,10 +1,10 @@ -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T, type TSESTree } from "@typescript-eslint/types"; import { getJSExpression } from "./ast-expression"; import { isTypeExpression } from "./ast-is"; -export function getPropertyName(node: TSESTree.Node): string | _ { +export function getPropertyName(node: TSESTree.Node): string | unit { if (isTypeExpression(node)) { return getPropertyName(getJSExpression(node)); } @@ -17,5 +17,5 @@ export function getPropertyName(node: TSESTree.Node): string | _ { if (node.type === T.TemplateLiteral && node.expressions.length === 0) { return node.quasis[0]?.value.raw; } - return _; + return unit; } diff --git a/packages/utilities/eff/docs/README.md b/packages/utilities/eff/docs/README.md index 3d86a673be..e5d73e3e1c 100644 --- a/packages/utilities/eff/docs/README.md +++ b/packages/utilities/eff/docs/README.md @@ -6,15 +6,15 @@ ## Type Aliases -- [\_](type-aliases.md) - [NarrowedTo](type-aliases/NarrowedTo.md) - [Pretty](type-aliases/Pretty.md) +- [unit](type-aliases/unit.md) ## Variables -- [\_](variables.md) - [compose](variables/compose.md) - [dual](variables/dual.md) +- [unit](variables/unit.md) ## Functions diff --git a/packages/utilities/eff/docs/type-aliases.md b/packages/utilities/eff/docs/type-aliases.md deleted file mode 100644 index 7987b4b593..0000000000 --- a/packages/utilities/eff/docs/type-aliases.md +++ /dev/null @@ -1,11 +0,0 @@ -[**@eslint-react/eff**](README.md) - -*** - -[@eslint-react/eff](README.md) / \_ - -# Type Alias: \_ - -> **\_** = `undefined` - -1-byte version `undefined`, produces fewer bytes than `undefined` or `void 0` in output files. diff --git a/packages/utilities/eff/docs/type-aliases/unit.md b/packages/utilities/eff/docs/type-aliases/unit.md new file mode 100644 index 0000000000..e25b163442 --- /dev/null +++ b/packages/utilities/eff/docs/type-aliases/unit.md @@ -0,0 +1,11 @@ +[**@eslint-react/eff**](../README.md) + +*** + +[@eslint-react/eff](../README.md) / unit + +# Type Alias: unit + +> **unit** = `undefined` + +alias for `undefined` diff --git a/packages/utilities/eff/docs/variables.md b/packages/utilities/eff/docs/variables.md deleted file mode 100644 index 5ba787c64a..0000000000 --- a/packages/utilities/eff/docs/variables.md +++ /dev/null @@ -1,11 +0,0 @@ -[**@eslint-react/eff**](README.md) - -*** - -[@eslint-react/eff](README.md) / \_ - -# Variable: \_ - -> **\_**: `undefined` - -1-byte version `undefined`, produces fewer bytes than `undefined` or `void 0` in output files. diff --git a/packages/utilities/eff/docs/variables/unit.md b/packages/utilities/eff/docs/variables/unit.md new file mode 100644 index 0000000000..3655dc8ac0 --- /dev/null +++ b/packages/utilities/eff/docs/variables/unit.md @@ -0,0 +1,11 @@ +[**@eslint-react/eff**](../README.md) + +*** + +[@eslint-react/eff](../README.md) / unit + +# Variable: unit + +> **unit**: `undefined` + +alias for `undefined` diff --git a/packages/utilities/eff/src/index.ts b/packages/utilities/eff/src/index.ts index 69da6c0fb5..66e8cf28a8 100644 --- a/packages/utilities/eff/src/index.ts +++ b/packages/utilities/eff/src/index.ts @@ -17,14 +17,14 @@ // #region Helper /** - * 1-byte version `undefined`, produces fewer bytes than `undefined` or `void 0` in output files. + * alias for `undefined` */ -export type _ = undefined; +export type unit = undefined; /** - * 1-byte version `undefined`, produces fewer bytes than `undefined` or `void 0` in output files. + * alias for `undefined` */ -export const _ = undefined; +export const unit = undefined; export type Pretty = & { diff --git a/packages/utilities/kit/src/Reporter.ts b/packages/utilities/kit/src/Reporter.ts index cb72768248..8b4e857194 100644 --- a/packages/utilities/kit/src/Reporter.ts +++ b/packages/utilities/kit/src/Reporter.ts @@ -1,27 +1,27 @@ import type { ReportDescriptor } from "@typescript-eslint/utils/ts-eslint"; import type { RuleContext } from "./types"; -import { type _, dual } from "@eslint-react/eff"; +import { dual, type unit } from "@eslint-react/eff"; export interface Reporter { - send: (descriptor: _ | null | ReportDescriptor) => void; + send: (descriptor: unit | null | ReportDescriptor) => void; // dprint-ignore - sendOrElse: (descriptor: _ | null | ReportDescriptor, cb: () => TElse) => _ | TElse; + sendOrElse: (descriptor: unit | null | ReportDescriptor, cb: () => TElse) => unit | TElse; } export const send: { - (context: RuleContext, descriptor: _ | null | ReportDescriptor): void; - (context: RuleContext): (descriptor: _ | null | ReportDescriptor) => void; -} = dual(2, (context: RuleContext, descriptor: _ | null | ReportDescriptor) => { + (context: RuleContext, descriptor: unit | null | ReportDescriptor): void; + (context: RuleContext): (descriptor: unit | null | ReportDescriptor) => void; +} = dual(2, (context: RuleContext, descriptor: unit | null | ReportDescriptor) => { if (descriptor == null) return; return context.report(descriptor); }); export const sendOrElse: { // dprint-ignore - (context: RuleContext, descriptor: _ | null | ReportDescriptor, cb: () => TElse): _ | TElse; + (context: RuleContext, descriptor: unit | null | ReportDescriptor, cb: () => TElse): unit| TElse; // dprint-ignore - (context: RuleContext): (descriptor: _ | null | ReportDescriptor) => (cb: () => TElse) => _ | TElse; -} = dual(3, (context: RuleContext, descriptor: _ | null | ReportDescriptor, cb: () => unknown) => { + (context: RuleContext): (descriptor: unit | null | ReportDescriptor) => (cb: () => TElse) => unit | TElse; +} = dual(3, (context: RuleContext, descriptor: unit | null | ReportDescriptor, cb: () => unknown) => { if (descriptor == null) return cb(); return context.report(descriptor); }); diff --git a/packages/utilities/var/src/var-collect.ts b/packages/utilities/var/src/var-collect.ts index 0f4eaf3737..c4bb1a246f 100644 --- a/packages/utilities/var/src/var-collect.ts +++ b/packages/utilities/var/src/var-collect.ts @@ -1,6 +1,6 @@ import type { Scope, Variable } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; -import { _, dual } from "@eslint-react/eff"; +import { dual, unit } from "@eslint-react/eff"; import { ScopeType } from "@typescript-eslint/scope-manager"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import * as ASTUtils from "@typescript-eslint/utils/ast-utils"; @@ -22,11 +22,11 @@ export function getVariables(initialScope: Scope): Variable[] { } export const findVariable: { - (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _; - (nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _; -} = dual(2, (nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope) => { - if (nameOrNode == null) return _; - return ASTUtils.findVariable(initialScope, nameOrNode) ?? _; + (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | unit) => Variable | unit; + (nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope): Variable | unit; +} = dual(2, (nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope) => { + if (nameOrNode == null) return unit; + return ASTUtils.findVariable(initialScope, nameOrNode) ?? unit; }); export function findPropertyInProperties( @@ -34,7 +34,7 @@ export function findPropertyInProperties( properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen = new Set(), -): (typeof properties)[number] | _ { +): (typeof properties)[number] | unit { return properties.findLast((prop) => { if (prop.type === T.Property) { return "name" in prop.key diff --git a/packages/utilities/var/src/var-construction.ts b/packages/utilities/var/src/var-construction.ts index 37cba6b987..bbd8d28482 100644 --- a/packages/utilities/var/src/var-construction.ts +++ b/packages/utilities/var/src/var-construction.ts @@ -1,6 +1,6 @@ import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { getVariableInitNode } from "./var-init-node"; @@ -29,11 +29,11 @@ export type Construction = * @returns The construction type of the node, or `_` if not found. */ export function getConstruction( - node: TSESTree.Node | _, + node: TSESTree.Node | unit, initialScope: Scope, hint = ConstructionDetectionHint.None, -): Construction | _ { - if (node == null) return _; +): Construction | unit { + if (node == null) return unit; switch (node.type) { case T.JSXElement: case T.JSXFragment: @@ -53,30 +53,30 @@ export function getConstruction( if (hint & ConstructionDetectionHint.StrictCallExpression) { return { kind: "CallExpression", node } as const; } - return _; + return unit; } case T.MemberExpression: { - if (!("object" in node)) return _; + if (!("object" in node)) return unit; return getConstruction(node.object, initialScope, hint); } case T.AssignmentExpression: case T.AssignmentPattern: { - if (!("right" in node)) return _; + if (!("right" in node)) return unit; return getConstruction(node.right, initialScope, hint); } case T.LogicalExpression: { const lvc = getConstruction(node.left, initialScope, hint); - if (lvc == null) return _; + if (lvc == null) return unit; return getConstruction(node.right, initialScope, hint); } case T.ConditionalExpression: { const cvc = getConstruction(node.consequent, initialScope, hint); - if (cvc == null) return _; + if (cvc == null) return unit; return getConstruction(node.alternate, initialScope, hint); } case T.Identifier: { if (!("name" in node) || typeof node.name !== "string") { - return _; + return unit; } const variable = initialScope.set.get(node.name); const variableNode = getVariableInitNode(variable, -1); @@ -86,11 +86,11 @@ export function getConstruction( if ("regex" in node) { return { kind: "RegExpLiteral", node } as const; } - return _; + return unit; } default: { if (!("expression" in node) || typeof node.expression !== "object") { - return _; + return unit; } return getConstruction(node.expression, initialScope, hint); } diff --git a/packages/utilities/var/src/var-declarator-id.ts b/packages/utilities/var/src/var-declarator-id.ts index 087caabcc3..b79cfde458 100644 --- a/packages/utilities/var/src/var-declarator-id.ts +++ b/packages/utilities/var/src/var-declarator-id.ts @@ -1,12 +1,12 @@ import type { TSESTree } from "@typescript-eslint/types"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; export function getVariableDeclaratorId( - node: TSESTree.Node | _, + node: TSESTree.Node | unit, prev?: TSESTree.Node, -): TSESTree.BindingName | TSESTree.Expression | _ { - if (node == null) return _; +): TSESTree.BindingName | TSESTree.Expression | unit { + if (node == null) return unit; switch (true) { case node.type === T.VariableDeclarator && node.init === prev: @@ -17,7 +17,7 @@ export function getVariableDeclaratorId( case node.type === T.BlockStatement || node.type === T.Program || node.parent === node: - return _; + return unit; default: return getVariableDeclaratorId(node.parent, node); } diff --git a/packages/utilities/var/src/var-init-node.ts b/packages/utilities/var/src/var-init-node.ts index 1d2c58ec95..bcf3b79bba 100644 --- a/packages/utilities/var/src/var-init-node.ts +++ b/packages/utilities/var/src/var-init-node.ts @@ -1,11 +1,11 @@ import type { Variable } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { DefinitionType } from "@typescript-eslint/scope-manager"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -export function getVariableInitNode(variable: Variable | _, at: number): - | _ +export function getVariableInitNode(variable: Variable | unit, at: number): + | unit | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName @@ -14,9 +14,9 @@ export function getVariableInitNode(variable: Variable | _, at: number): | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName { - if (variable == null) return _; + if (variable == null) return unit; const def = variable.defs.at(at); - if (def == null) return _; + if (def == null) return unit; switch (true) { case def.type === DefinitionType.FunctionName && def.node.type === T.FunctionDeclaration: @@ -29,6 +29,6 @@ export function getVariableInitNode(variable: Variable | _, at: number): && !("declarations" in def.node.init): return def.node.init; default: - return _; + return unit; } } diff --git a/packages/utilities/var/src/var-value-equal.ts b/packages/utilities/var/src/var-value-equal.ts index b740401327..c4e0cbbd59 100644 --- a/packages/utilities/var/src/var-value-equal.ts +++ b/packages/utilities/var/src/var-value-equal.ts @@ -1,6 +1,6 @@ import type { TSESTree } from "@typescript-eslint/types"; import * as AST from "@eslint-react/ast"; -import { _ } from "@eslint-react/eff"; +import { unit } from "@eslint-react/eff"; import { DefinitionType, type Scope, type Variable } from "@typescript-eslint/scope-manager"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { findVariable } from "./var-collect"; @@ -106,11 +106,11 @@ export function isNodeValueEqual( } } -function getVariableInitNodeLoose(variable: Variable | _, at: number): ReturnType { - if (variable == null) return _; +function getVariableInitNodeLoose(variable: Variable | unit, at: number): ReturnType { + if (variable == null) return unit; const node = getVariableInitNode(variable, at); if (node != null) return node; const def = variable.defs.at(at); if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node; - return _; + return unit; } diff --git a/packages/utilities/var/src/var-value.ts b/packages/utilities/var/src/var-value.ts index 75d26bc1d4..91fe73e26a 100644 --- a/packages/utilities/var/src/var-value.ts +++ b/packages/utilities/var/src/var-value.ts @@ -1,6 +1,6 @@ /* eslint-disable perfectionist/sort-object-types */ -import type { _ } from "@eslint-react/eff"; +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"; @@ -10,20 +10,20 @@ export type LazyValue = // Not resolved yet kind: "lazy"; node: TSESTree.Node; - initialScope: Scope | _; + initialScope: Scope | unit; } | { // Resolved to nothing kind: "none"; node: TSESTree.Node; - initialScope: Scope | _; + initialScope: Scope | unit; } | { // Resolved to something kind: "some"; node: TSESTree.Node; value: unknown; - initialScope: Scope | _; + initialScope: Scope | unit; }; export function toStaticValue(lazyValue: LazyValue) {