diff --git a/packages/core/src/utils/is-react-api.ts b/packages/core/src/utils/is-react-api.ts index e49a617a56..ec4776de2c 100644 --- a/packages/core/src/utils/is-react-api.ts +++ b/packages/core/src/utils/is-react-api.ts @@ -18,7 +18,7 @@ export function isReactAPI(api: string): isReactAPI.ReturnType { { if (node == null) return false; const getText = (n: TSESTree.Node) => context.sourceCode.getText(n); - const name = AST.stringify(node, getText); + const name = AST.toString(node, getText); if (name === api) return true; if (name.substring(name.indexOf(".") + 1) === api) return true; return false; diff --git a/packages/plugins/eslint-plugin-react-hooks-extra/src/hooks/use-no-direct-set-state-in-use-effect.ts b/packages/plugins/eslint-plugin-react-hooks-extra/src/hooks/use-no-direct-set-state-in-use-effect.ts index 099a4cfb4e..67e3871322 100644 --- a/packages/plugins/eslint-plugin-react-hooks-extra/src/hooks/use-no-direct-set-state-in-use-effect.ts +++ b/packages/plugins/eslint-plugin-react-hooks-extra/src/hooks/use-no-direct-set-state-in-use-effect.ts @@ -221,7 +221,7 @@ export function useNoDirectSetStateInUseEffect( const setStateCalls = getSetStateCalls(name, context.sourceCode.getScope(callee)); for (const setStateCall of setStateCalls) { onViolation(context, setStateCall, { - name: AST.stringify(setStateCall, (n) => context.sourceCode.getText(n)), + name: AST.toString(setStateCall, (n) => context.sourceCode.getText(n)), }); } } @@ -229,7 +229,7 @@ export function useNoDirectSetStateInUseEffect( const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id)); for (const setStateCall of setStateCalls) { onViolation(context, setStateCall, { - name: AST.stringify(setStateCall, (n) => context.sourceCode.getText(n)), + name: AST.toString(setStateCall, (n) => context.sourceCode.getText(n)), }); } } diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts index 3d5595173a..eac3cf5e3f 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts @@ -74,7 +74,7 @@ export function create(context: RuleContext): RuleListener { if (!AST.isFunction(iter)) return; const arg0 = call?.arguments[0]; if (call == null || arg0 == null) return; - if (AST.getEcmaExpression(arg0) !== iter) { + if (AST.getJSExpression(arg0) !== iter) { return; } keyedEntries.set(call, { diff --git a/packages/utilities/ast/src/__tests__/get-class-identifier.test.ts b/packages/utilities/ast/src/__tests__/get-class-identifier.test.ts index 2296f26c09..32b2b99998 100644 --- a/packages/utilities/ast/src/__tests__/get-class-identifier.test.ts +++ b/packages/utilities/ast/src/__tests__/get-class-identifier.test.ts @@ -1,4 +1,4 @@ -import type { TSESTreeClass } from "../types"; +import type { TSESTreeClass } from "../ast-node"; import path from "node:path"; import { parseForESLint } from "@typescript-eslint/parser"; @@ -7,7 +7,7 @@ import { simpleTraverse } from "@typescript-eslint/typescript-estree"; import { describe, expect, it } from "vitest"; import { getFixturesRootDir } from "../../../../../test"; -import { getClassIdentifier } from "../get-class-identifier"; +import { getClassIdentifier } from "../ast-class-id"; function parse(code: string) { return parseForESLint(code, { diff --git a/packages/utilities/ast/src/__tests__/get-function-identifier.test.ts b/packages/utilities/ast/src/__tests__/get-function-identifier.test.ts index 07a4e67eaf..089e2b5ae5 100644 --- a/packages/utilities/ast/src/__tests__/get-function-identifier.test.ts +++ b/packages/utilities/ast/src/__tests__/get-function-identifier.test.ts @@ -1,4 +1,4 @@ -import type { TSESTreeFunction } from "../types"; +import type { TSESTreeFunction } from "../ast-node"; import path from "node:path"; import { parseForESLint } from "@typescript-eslint/parser"; @@ -7,8 +7,8 @@ import { simpleTraverse } from "@typescript-eslint/typescript-estree"; import { describe, expect, it } from "vitest"; import { getFixturesRootDir } from "../../../../../test"; -import { getFunctionIdentifier } from "../get-function-identifier"; -import { isFunction } from "../is"; +import { getFunctionIdentifier } from "../ast-function-id"; +import { isFunction } from "../ast-is"; function parse(code: string) { return parseForESLint(code, { diff --git a/packages/utilities/ast/src/__tests__/get-nested-return-statements.test.ts b/packages/utilities/ast/src/__tests__/get-nested-return-statements.test.ts index 86cf35cbfe..4b3f3402b0 100644 --- a/packages/utilities/ast/src/__tests__/get-nested-return-statements.test.ts +++ b/packages/utilities/ast/src/__tests__/get-nested-return-statements.test.ts @@ -1,4 +1,4 @@ -import type { TSESTreeFunction } from "../types"; +import type { TSESTreeFunction } from "../ast-node"; import path from "node:path"; import { parseForESLint } from "@typescript-eslint/parser"; @@ -8,8 +8,8 @@ import tsx from "dedent"; import { describe, expect, it } from "vitest"; import { getFixturesRootDir } from "../../../../../test"; -import { getNestedReturnStatements } from "../get-nested-return-statements"; -import { isFunction } from "../is"; +import { isFunction } from "../ast-is"; +import { getNestedReturnStatements } from "../ast-return-statement"; function parse(code: string) { return parseForESLint(code, { diff --git a/packages/utilities/ast/src/get-array-method-callback-index-param-position.ts b/packages/utilities/ast/src/ast-array-method-callback.ts similarity index 100% rename from packages/utilities/ast/src/get-array-method-callback-index-param-position.ts rename to packages/utilities/ast/src/ast-array-method-callback.ts diff --git a/packages/utilities/ast/src/is-array-from-call.ts b/packages/utilities/ast/src/ast-array-method.ts similarity index 57% rename from packages/utilities/ast/src/is-array-from-call.ts rename to packages/utilities/ast/src/ast-array-method.ts index 012ac668eb..6af3d6addb 100644 --- a/packages/utilities/ast/src/is-array-from-call.ts +++ b/packages/utilities/ast/src/ast-array-method.ts @@ -8,3 +8,11 @@ export function isArrayFromCall(node: TSESTree.Node, loose = true): node is TSES const name = node.callee.property.name; return name === "from" || (loose && name.startsWith("from")); } + +export function isArrayMapCall(node: TSESTree.Node, loose = true): node is TSESTree.CallExpression { + if (node.type !== T.CallExpression) return false; + if (node.callee.type !== T.MemberExpression) return false; + if (node.callee.property.type !== T.Identifier) return false; + const name = node.callee.property.name; + return name === "map" || (loose && name.endsWith("Map")); +} diff --git a/packages/utilities/ast/src/get-class-identifier.ts b/packages/utilities/ast/src/ast-class-id.ts similarity index 92% rename from packages/utilities/ast/src/get-class-identifier.ts rename to packages/utilities/ast/src/ast-class-id.ts index 889624871a..71eb46a1ab 100644 --- a/packages/utilities/ast/src/get-class-identifier.ts +++ b/packages/utilities/ast/src/ast-class-id.ts @@ -1,5 +1,5 @@ import type { TSESTree } from "@typescript-eslint/types"; -import type { TSESTreeClass } from "./types"; +import type { TSESTreeClass } from "./ast-node"; import { _ } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; diff --git a/packages/utilities/ast/src/get-nested-expressions.ts b/packages/utilities/ast/src/ast-expression.ts similarity index 86% rename from packages/utilities/ast/src/get-nested-expressions.ts rename to packages/utilities/ast/src/ast-expression.ts index 19eeda2a77..283767a680 100644 --- a/packages/utilities/ast/src/get-nested-expressions.ts +++ b/packages/utilities/ast/src/ast-expression.ts @@ -1,6 +1,27 @@ import type { TSESTree } from "@typescript-eslint/types"; -import { AST_NODE_TYPES as T } from "@typescript-eslint/typescript-estree"; -import { ASTUtils } from "@typescript-eslint/utils"; +import type { TSESTreeTypeExpression } from "./ast-node"; + +import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; +import { is, isTypeExpression } from "./ast-is"; + +/** + * Recursively get the inner expression until it's not a TypeExpression + * @param node - The node to get the expression from + * @returns The inner expression + */ +export function getJSExpression(node: TSESTree.Node): Exclude< + TSESTree.Node, + TSESTreeTypeExpression +> { + if (isTypeExpression(node)) { + return getJSExpression(node.expression); + } + return node; +} + +export function isThisExpression(node: TSESTree.Expression) { + return getJSExpression(node).type === T.ThisExpression; +} /** * Get all nested expressions of type T in an expression like node @@ -10,7 +31,7 @@ import { ASTUtils } from "@typescript-eslint/utils"; */ // dprint-ignore export function getNestedExpressionsOfType(type: TNodeType): (node: TSESTree.Node) => Extract[] { - const isNodeOfType = ASTUtils.isNodeOfType(type); + const isNodeOfType = is(type); return function(node) { const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type); const expressions: Extract[] = []; diff --git a/packages/utilities/ast/src/get-function-identifier.ts b/packages/utilities/ast/src/ast-function-id.ts similarity index 97% rename from packages/utilities/ast/src/get-function-identifier.ts rename to packages/utilities/ast/src/ast-function-id.ts index e6e24d918f..bdc025917c 100644 --- a/packages/utilities/ast/src/get-function-identifier.ts +++ b/packages/utilities/ast/src/ast-function-id.ts @@ -8,11 +8,11 @@ */ import type { TSESTree } from "@typescript-eslint/types"; -import type { TSESTreeFunction } from "./types"; +import type { TSESTreeFunction } from "./ast-node"; import { _ } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { isMethodOrProperty, isTypeAssertionExpression } from "./is"; +import { isMethodOrProperty, isTypeAssertionExpression } from "./ast-is"; export function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _ { switch (true) { diff --git a/packages/utilities/ast/src/function-init-path.ts b/packages/utilities/ast/src/ast-function-init-path.ts similarity index 98% rename from packages/utilities/ast/src/function-init-path.ts rename to packages/utilities/ast/src/ast-function-init-path.ts index 9b60d68a32..53c98afd1c 100644 --- a/packages/utilities/ast/src/function-init-path.ts +++ b/packages/utilities/ast/src/ast-function-init-path.ts @@ -1,5 +1,5 @@ import type { TSESTree } from "@typescript-eslint/types"; -import type { TSESTreeFunction } from "./types"; +import type { TSESTreeFunction } from "./ast-node"; import { _ } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; diff --git a/packages/utilities/ast/src/is-empty-function.ts b/packages/utilities/ast/src/ast-function-is.ts similarity index 79% rename from packages/utilities/ast/src/is-empty-function.ts rename to packages/utilities/ast/src/ast-function-is.ts index d737789ab2..b0d65d48bf 100644 --- a/packages/utilities/ast/src/is-empty-function.ts +++ b/packages/utilities/ast/src/ast-function-is.ts @@ -1,4 +1,4 @@ -import type { TSESTreeFunction } from "./types"; +import type { TSESTreeFunction } from "./ast-node"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; diff --git a/packages/utilities/ast/src/find-parent-node.ts b/packages/utilities/ast/src/ast-hierarchy.ts similarity index 100% rename from packages/utilities/ast/src/find-parent-node.ts rename to packages/utilities/ast/src/ast-hierarchy.ts diff --git a/packages/utilities/ast/src/get-nested-identifiers.ts b/packages/utilities/ast/src/ast-id.ts similarity index 100% rename from packages/utilities/ast/src/get-nested-identifiers.ts rename to packages/utilities/ast/src/ast-id.ts diff --git a/packages/utilities/ast/src/is.ts b/packages/utilities/ast/src/ast-is.ts similarity index 98% rename from packages/utilities/ast/src/is.ts rename to packages/utilities/ast/src/ast-is.ts index 2096641e81..b37a002caf 100644 --- a/packages/utilities/ast/src/is.ts +++ b/packages/utilities/ast/src/ast-is.ts @@ -1,3 +1,4 @@ +import type { TSESTree } from "@typescript-eslint/types"; import { or } from "@eslint-react/eff"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { ASTUtils } from "@typescript-eslint/utils"; diff --git a/packages/utilities/ast/src/is-line-break.ts b/packages/utilities/ast/src/ast-line.ts similarity index 61% rename from packages/utilities/ast/src/is-line-break.ts rename to packages/utilities/ast/src/ast-line.ts index 2aa5ade870..b418b9e4a9 100644 --- a/packages/utilities/ast/src/is-line-break.ts +++ b/packages/utilities/ast/src/ast-line.ts @@ -1,7 +1,15 @@ import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { isOneOf } from "./is"; -import { isMultiLine } from "./is-multi-line"; +import { isOneOf } from "./ast-is"; + +/** + * Check if a node is multiline + * @param node The AST node to check + * @returns `true` if the node is multiline + */ +export function isMultiLine(node: TSESTree.Node) { + return node.loc.start.line !== node.loc.end.line; +} /** * Check if a node is a line break diff --git a/packages/utilities/ast/src/is-literal.ts b/packages/utilities/ast/src/ast-literal-is.ts similarity index 94% rename from packages/utilities/ast/src/is-literal.ts rename to packages/utilities/ast/src/ast-literal-is.ts index 5328d39c8b..951744098c 100644 --- a/packages/utilities/ast/src/is-literal.ts +++ b/packages/utilities/ast/src/ast-literal-is.ts @@ -1,4 +1,3 @@ -/* eslint-disable local/prefer-eqeq-nullish-comparison */ import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; @@ -22,6 +21,7 @@ export function isLiteral(node: TSESTree.Node, type?: LiteralType) { case "boolean": return typeof node.value === "boolean"; case "null": + // eslint-disable-next-line local/prefer-eqeq-nullish-comparison return node.value === null; case "number": return typeof node.value === "number"; diff --git a/packages/utilities/ast/src/is-node-equal.ts b/packages/utilities/ast/src/ast-node-equal.ts similarity index 100% rename from packages/utilities/ast/src/is-node-equal.ts rename to packages/utilities/ast/src/ast-node-equal.ts diff --git a/packages/utilities/ast/src/types.ts b/packages/utilities/ast/src/ast-node.ts similarity index 100% rename from packages/utilities/ast/src/types.ts rename to packages/utilities/ast/src/ast-node.ts diff --git a/packages/utilities/ast/src/is-process-env-node-env-compare.ts b/packages/utilities/ast/src/ast-process-env-node-env.ts similarity index 59% rename from packages/utilities/ast/src/is-process-env-node-env-compare.ts rename to packages/utilities/ast/src/ast-process-env-node-env.ts index 597bc15667..d376ac519a 100644 --- a/packages/utilities/ast/src/is-process-env-node-env-compare.ts +++ b/packages/utilities/ast/src/ast-process-env-node-env.ts @@ -1,8 +1,24 @@ import type { _ } from "@eslint-react/eff"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { isLiteral } from "./is-literal"; -import { isProcessEnvNodeEnv } from "./is-process-env-node-env"; +import { isLiteral } from "./ast-literal-is"; + +/** + * Check if the given node is a member expression that accesses `process.env.NODE_ENV` + * @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 { + return node != null + && node.type === T.MemberExpression + && node.object.type === T.MemberExpression + && node.object.object.type === T.Identifier + && node.object.object.name === "process" + && node.object.property.type === T.Identifier + && node.object.property.name === "env" + && node.property.type === T.Identifier + && node.property.name === "NODE_ENV"; +} /** * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal diff --git a/packages/utilities/ast/src/get-property-name.ts b/packages/utilities/ast/src/ast-property-name.ts similarity index 77% rename from packages/utilities/ast/src/get-property-name.ts rename to packages/utilities/ast/src/ast-property-name.ts index c486c9f28e..f7f47d8b95 100644 --- a/packages/utilities/ast/src/get-property-name.ts +++ b/packages/utilities/ast/src/ast-property-name.ts @@ -1,12 +1,12 @@ import { _ } from "@eslint-react/eff"; import { AST_NODE_TYPES as T, type TSESTree } from "@typescript-eslint/types"; -import { getEcmaExpression } from "./get-ecma-expression"; -import { isTypeExpression } from "./is"; +import { getJSExpression } from "./ast-expression"; +import { isTypeExpression } from "./ast-is"; export function getPropertyName(node: TSESTree.Node): string | _ { if (isTypeExpression(node)) { - return getPropertyName(getEcmaExpression(node)); + return getPropertyName(getJSExpression(node)); } if (node.type === T.Identifier || node.type === T.PrivateIdentifier) { return node.name; diff --git a/packages/utilities/ast/src/get-nested-return-statements.ts b/packages/utilities/ast/src/ast-return-statement.ts similarity index 91% rename from packages/utilities/ast/src/get-nested-return-statements.ts rename to packages/utilities/ast/src/ast-return-statement.ts index fd619456a9..984f4d1173 100644 --- a/packages/utilities/ast/src/get-nested-return-statements.ts +++ b/packages/utilities/ast/src/ast-return-statement.ts @@ -1,9 +1,8 @@ import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { simpleTraverse } from "@typescript-eslint/typescript-estree"; - -import { findParentNode } from "./find-parent-node"; -import { isFunction } from "./is"; +import { findParentNode } from "./ast-hierarchy"; +import { isFunction } from "./ast-is"; /** * Gets the nested return statements in the node that are within the same function diff --git a/packages/utilities/ast/src/to-readable-node-type.ts b/packages/utilities/ast/src/ast-to-readable-node-type.ts similarity index 75% rename from packages/utilities/ast/src/to-readable-node-type.ts rename to packages/utilities/ast/src/ast-to-readable-node-type.ts index 011707f5f4..48bae6ac2a 100644 --- a/packages/utilities/ast/src/to-readable-node-type.ts +++ b/packages/utilities/ast/src/ast-to-readable-node-type.ts @@ -2,8 +2,13 @@ import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { delimiterCase, replace, toLowerCase } from "string-ts"; -import { getLiteralValueType } from "./get-literal-value-type"; -import { isJSX } from "./is"; +import { isJSX } from "./ast-is"; + +function getLiteralValueType(input: bigint | boolean | null | number | string | symbol) { + // eslint-disable-next-line local/prefer-eqeq-nullish-comparison + if (input === null) return "null"; + return typeof input; +} /** * Returns human readable node type for given AST node diff --git a/packages/utilities/ast/src/stringify.ts b/packages/utilities/ast/src/ast-to-string.ts similarity index 71% rename from packages/utilities/ast/src/stringify.ts rename to packages/utilities/ast/src/ast-to-string.ts index 6ad0fed546..48f5b8b080 100644 --- a/packages/utilities/ast/src/stringify.ts +++ b/packages/utilities/ast/src/ast-to-string.ts @@ -7,17 +7,17 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; * @param getText A function that returns the text of the node in the source code * @returns Human readable node name */ -export function stringify(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string { +export function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string { switch (node.type) { case T.CallExpression: - return stringify(node.callee, getText); + return toString(node.callee, getText); case T.Identifier: case T.PrivateIdentifier: return node.name; case T.JSXIdentifier: return `<${node.name}>`; case T.JSXMemberExpression: - return `${stringify(node.object, getText)}.${stringify(node.property, getText)}`; + return `${toString(node.object, getText)}.${toString(node.property, getText)}`; case T.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`; case T.JSXText: @@ -25,7 +25,7 @@ export function stringify(node: TSESTree.Node, getText: (node: TSESTree.Node) => case T.Literal: return node.raw; case T.MemberExpression: - return `${stringify(node.object, getText)}.${stringify(node.property, getText)}`; + return `${toString(node.object, getText)}.${toString(node.property, getText)}`; default: return getText(node); } diff --git a/packages/utilities/ast/src/get-ecma-expression.ts b/packages/utilities/ast/src/get-ecma-expression.ts deleted file mode 100644 index e5fdf46cbd..0000000000 --- a/packages/utilities/ast/src/get-ecma-expression.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { TSESTree } from "@typescript-eslint/types"; - -import type { TSESTreeTypeExpression } from "./types"; -import { isTypeExpression } from "./is"; - -/** - * Recursively get the inner expression until it's not a TypeExpression - * @param node - The node to get the expression from - * @returns The inner expression - */ -export function getEcmaExpression(node: TSESTree.Node): Exclude< - TSESTree.Node, - TSESTreeTypeExpression -> { - if (isTypeExpression(node)) { - return getEcmaExpression(node.expression); - } - return node; -} diff --git a/packages/utilities/ast/src/get-literal-value-type.ts b/packages/utilities/ast/src/get-literal-value-type.ts deleted file mode 100644 index bbf1bbd91a..0000000000 --- a/packages/utilities/ast/src/get-literal-value-type.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function getLiteralValueType(input: bigint | boolean | null | number | string | symbol) { - // eslint-disable-next-line local/prefer-eqeq-nullish-comparison - if (input === null) return "null"; - return typeof input; -} diff --git a/packages/utilities/ast/src/index.ts b/packages/utilities/ast/src/index.ts index 74c5c7894d..261300acfe 100644 --- a/packages/utilities/ast/src/index.ts +++ b/packages/utilities/ast/src/index.ts @@ -1,25 +1,19 @@ -export * from "./find-parent-node"; -export * from "./function-init-path"; -export * from "./get-array-method-callback-index-param-position"; -export * from "./get-class-identifier"; -export * from "./get-ecma-expression"; -export * from "./get-function-identifier"; -export * from "./get-literal-value-type"; -export * from "./get-nested-expressions"; -export * from "./get-nested-identifiers"; -export * from "./get-nested-return-statements"; -export * from "./get-property-name"; -export * from "./is"; -export * from "./is-array-from-call"; -export * from "./is-array-map-call"; -export * from "./is-empty-function"; -export * from "./is-line-break"; -export * from "./is-literal"; -export * from "./is-multi-line"; -export * from "./is-node-equal"; -export * from "./is-process-env-node-env"; -export * from "./is-process-env-node-env-compare"; -export * from "./is-this-expression"; -export * from "./stringify"; -export * from "./to-readable-node-type"; -export type * from "./types"; +export * from "./ast-array-method"; +export * from "./ast-array-method-callback"; +export * from "./ast-class-id"; +export * from "./ast-expression"; +export * from "./ast-function-id"; +export * from "./ast-function-init-path"; +export * from "./ast-function-is"; +export * from "./ast-hierarchy"; +export * from "./ast-id"; +export * from "./ast-is"; +export * from "./ast-line"; +export * from "./ast-literal-is"; +export type * from "./ast-node"; +export * from "./ast-node-equal"; +export * from "./ast-process-env-node-env"; +export * from "./ast-property-name"; +export * from "./ast-return-statement"; +export * from "./ast-to-readable-node-type"; +export * from "./ast-to-string"; diff --git a/packages/utilities/ast/src/is-array-map-call.ts b/packages/utilities/ast/src/is-array-map-call.ts deleted file mode 100644 index 5f5c9b4c17..0000000000 --- a/packages/utilities/ast/src/is-array-map-call.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { TSESTree } from "@typescript-eslint/types"; -import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; - -export function isArrayMapCall(node: TSESTree.Node, loose = true): node is TSESTree.CallExpression { - if (node.type !== T.CallExpression) return false; - if (node.callee.type !== T.MemberExpression) return false; - if (node.callee.property.type !== T.Identifier) return false; - const name = node.callee.property.name; - return name === "map" || (loose && name.endsWith("Map")); -} diff --git a/packages/utilities/ast/src/is-multi-line.ts b/packages/utilities/ast/src/is-multi-line.ts deleted file mode 100644 index d9f65a68e6..0000000000 --- a/packages/utilities/ast/src/is-multi-line.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { TSESTree } from "@typescript-eslint/types"; - -/** - * Check if a node is multiline - * @param node The AST node to check - * @returns `true` if the node is multiline - */ -export function isMultiLine(node: TSESTree.Node) { - return node.loc.start.line !== node.loc.end.line; -} diff --git a/packages/utilities/ast/src/is-process-env-node-env.ts b/packages/utilities/ast/src/is-process-env-node-env.ts deleted file mode 100644 index a2dd84d30a..0000000000 --- a/packages/utilities/ast/src/is-process-env-node-env.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { _ } from "@eslint-react/eff"; -import type { TSESTree } from "@typescript-eslint/types"; -import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; - -/** - * Check if the given node is a member expression that accesses `process.env.NODE_ENV` - * @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 { - return node != null - && node.type === T.MemberExpression - && node.object.type === T.MemberExpression - && node.object.object.type === T.Identifier - && node.object.object.name === "process" - && node.object.property.type === T.Identifier - && node.object.property.name === "env" - && node.property.type === T.Identifier - && node.property.name === "NODE_ENV"; -} diff --git a/packages/utilities/ast/src/is-this-expression.ts b/packages/utilities/ast/src/is-this-expression.ts deleted file mode 100644 index ddb2b17bce..0000000000 --- a/packages/utilities/ast/src/is-this-expression.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { TSESTree } from "@typescript-eslint/types"; -import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; - -import { getEcmaExpression } from "./get-ecma-expression"; - -export function isThisExpression(node: TSESTree.Expression) { - return getEcmaExpression(node).type === T.ThisExpression; -}