From 217c710d99445994b9c8db7b9bee9b9cc63bc4cb Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 22 Feb 2023 22:35:41 -0500 Subject: [PATCH] fix: bumped ts-api-utils to 0.0.39 (#6497) * fix: bumped ts-api-utils to 0.0.28 * Fix snippets formatting * Rename tools to tsutils too * ...and the docs * Fixed compile issues * Correct patch version * Correct patch --- docs/Custom_Rules.mdx | 4 +-- packages/eslint-plugin/package.json | 2 +- .../eslint-plugin/src/rules/await-thenable.ts | 4 +-- .../eslint-plugin/src/rules/dot-notation.ts | 4 +-- .../src/rules/no-confusing-void-expression.ts | 4 +-- .../src/rules/no-dynamic-delete.ts | 4 +-- .../src/rules/no-floating-promises.ts | 8 ++--- .../src/rules/no-implied-eval.ts | 4 +-- .../src/rules/no-meaningless-void-operator.ts | 4 +-- .../src/rules/no-misused-promises.ts | 24 +++++++-------- .../rules/no-redundant-type-constituents.ts | 12 ++++---- .../no-unnecessary-boolean-literal-compare.ts | 6 ++-- .../src/rules/no-unnecessary-condition.ts | 29 +++++++++---------- .../src/rules/no-unnecessary-qualifier.ts | 4 +-- .../rules/no-unnecessary-type-arguments.ts | 4 +-- .../rules/no-unnecessary-type-assertion.ts | 10 +++---- .../src/rules/no-unsafe-assignment.ts | 4 +-- .../eslint-plugin/src/rules/no-unsafe-call.ts | 4 +-- .../src/rules/no-unsafe-member-access.ts | 4 +-- .../src/rules/no-unsafe-return.ts | 4 +-- .../non-nullable-type-assertion-style.ts | 10 ++++--- .../src/rules/prefer-nullish-coalescing.ts | 4 +-- .../src/rules/prefer-readonly.ts | 22 +++++++------- .../src/rules/prefer-regexp-exec.ts | 4 +-- .../eslint-plugin/src/rules/require-await.ts | 6 ++-- .../eslint-plugin/src/rules/return-await.ts | 4 +-- .../src/rules/strict-boolean-expressions.ts | 22 +++++++------- .../src/rules/switch-exhaustiveness-check.ts | 6 ++-- .../eslint-plugin/src/rules/unbound-method.ts | 4 +-- .../prefer-readonly-parameter-types.test.ts | 22 ++++++++++++-- .../tests/rules/require-await.test.ts | 12 ++++++++ packages/type-utils/package.json | 2 +- .../type-utils/src/containsAllTypesByName.ts | 6 ++-- packages/type-utils/src/isTypeReadonly.ts | 22 ++++++++------ packages/type-utils/src/isUnsafeAssignment.ts | 4 +-- packages/type-utils/src/predicates.ts | 4 +-- packages/type-utils/src/typeFlagUtils.ts | 4 +-- packages/typescript-estree/package.json | 2 +- .../typescript-estree/src/convert-comments.ts | 4 +-- ...0.0.21.patch => ts-api-utils+0.0.39.patch} | 2 +- yarn.lock | 8 ++--- 41 files changed, 175 insertions(+), 142 deletions(-) rename patches/{ts-api-utils+0.0.21.patch => ts-api-utils+0.0.39.patch} (91%) diff --git a/docs/Custom_Rules.mdx b/docs/Custom_Rules.mdx index b332c0cd6d6..d636a993112 100644 --- a/docs/Custom_Rules.mdx +++ b/docs/Custom_Rules.mdx @@ -229,7 +229,7 @@ This rule bans for-of looping over an enum by using the TypeScript type checker ```ts import { ESLintUtils } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-tools'; +import * as tsutils from 'ts-api-tools'; import * as ts from 'typescript'; export const rule = createRule({ @@ -243,7 +243,7 @@ export const rule = createRule({ const type = services.getTypeAtLocation(node); // 3. Check the TS type using the TypeScript APIs - if (tools.isTypeFlagSet(nodeType, ts.TypeFlags.EnumLike)) { + if (tsutils.isTypeFlagSet(nodeType, ts.TypeFlags.EnumLike)) { context.report({ messageId: 'loopOverEnum', node: node.right, diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 7565816652b..e1a43fee587 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -65,7 +65,7 @@ "natural-compare-lite": "^1.4.0", "regexpp": "^3.2.0", "semver": "^7.3.7", - "ts-api-utils": "^0.0.22" + "ts-api-utils": "^0.0.39" }, "devDependencies": { "@types/debug": "*", diff --git a/packages/eslint-plugin/src/rules/await-thenable.ts b/packages/eslint-plugin/src/rules/await-thenable.ts index 86d1688da02..fca9fd83de0 100644 --- a/packages/eslint-plugin/src/rules/await-thenable.ts +++ b/packages/eslint-plugin/src/rules/await-thenable.ts @@ -1,4 +1,4 @@ -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as util from '../util'; @@ -31,7 +31,7 @@ export default util.createRule({ const originalNode = services.esTreeNodeToTSNodeMap.get(node); - if (!tools.isThenableType(checker, originalNode.expression, type)) { + if (!tsutils.isThenableType(checker, originalNode.expression, type)) { context.report({ messageId: 'await', node, diff --git a/packages/eslint-plugin/src/rules/dot-notation.ts b/packages/eslint-plugin/src/rules/dot-notation.ts index e6c0d9e7a83..d79c8fcdb5e 100644 --- a/packages/eslint-plugin/src/rules/dot-notation.ts +++ b/packages/eslint-plugin/src/rules/dot-notation.ts @@ -1,5 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import type { @@ -75,7 +75,7 @@ export default createRule({ options.allowProtectedClassPropertyAccess; const allowIndexSignaturePropertyAccess = (options.allowIndexSignaturePropertyAccess ?? false) || - tools.isCompilerOptionEnabled( + tsutils.isCompilerOptionEnabled( services.program.getCompilerOptions(), 'noPropertyAccessFromIndexSignature', ); diff --git a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts index 2a8d6f5f604..8dbb6708bb3 100644 --- a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts +++ b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -81,7 +81,7 @@ export default util.createRule({ ): void { const services = util.getParserServices(context); const type = util.getConstrainedTypeAtLocation(services, node); - if (!tools.isTypeFlagSet(type, ts.TypeFlags.VoidLike)) { + if (!tsutils.isTypeFlagSet(type, ts.TypeFlags.VoidLike)) { // not a void expression return; } diff --git a/packages/eslint-plugin/src/rules/no-dynamic-delete.ts b/packages/eslint-plugin/src/rules/no-dynamic-delete.ts index 6cf68bf2764..0d1127f8a92 100644 --- a/packages/eslint-plugin/src/rules/no-dynamic-delete.ts +++ b/packages/eslint-plugin/src/rules/no-dynamic-delete.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as util from '../util'; @@ -97,6 +97,6 @@ function isNecessaryDynamicAccess(property: TSESTree.Expression): boolean { return ( typeof property.value === 'string' && - !tools.isValidPropertyAccess(property.value) + !tsutils.isValidPropertyAccess(property.value) ); } diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 77ce7dfbc34..053e6763693 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -240,7 +240,7 @@ export default util.createRule({ // https://github.com/ajafff/tsutils/blob/49d0d31050b44b81e918eae4fbaf1dfe7b7286af/util/type.ts#L95-L125 function isPromiseLike(checker: ts.TypeChecker, node: ts.Node): boolean { const type = checker.getTypeAtLocation(node); - for (const ty of tools.unionTypeParts(checker.getApparentType(type))) { + for (const ty of tsutils.unionTypeParts(checker.getApparentType(type))) { const then = ty.getProperty('then'); if (then === undefined) { continue; @@ -266,7 +266,7 @@ function hasMatchingSignature( type: ts.Type, matcher: (signature: ts.Signature) => boolean, ): boolean { - for (const t of tools.unionTypeParts(type)) { + for (const t of tsutils.unionTypeParts(type)) { if (t.getCallSignatures().some(matcher)) { return true; } @@ -283,7 +283,7 @@ function isFunctionParam( const type: ts.Type | undefined = checker.getApparentType( checker.getTypeOfSymbolAtLocation(param, node), ); - for (const t of tools.unionTypeParts(type)) { + for (const t of tsutils.unionTypeParts(type)) { if (t.getCallSignatures().length !== 0) { return true; } diff --git a/packages/eslint-plugin/src/rules/no-implied-eval.ts b/packages/eslint-plugin/src/rules/no-implied-eval.ts index 0e042232f61..1da7114a0d4 100644 --- a/packages/eslint-plugin/src/rules/no-implied-eval.ts +++ b/packages/eslint-plugin/src/rules/no-implied-eval.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -69,7 +69,7 @@ export default util.createRule({ if ( symbol && - tools.isSymbolFlagSet( + tsutils.isSymbolFlagSet( symbol, ts.SymbolFlags.Function | ts.SymbolFlags.Method, ) diff --git a/packages/eslint-plugin/src/rules/no-meaningless-void-operator.ts b/packages/eslint-plugin/src/rules/no-meaningless-void-operator.ts index 528344ea699..524c5438788 100644 --- a/packages/eslint-plugin/src/rules/no-meaningless-void-operator.ts +++ b/packages/eslint-plugin/src/rules/no-meaningless-void-operator.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { ESLintUtils } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -61,7 +61,7 @@ export default util.createRule< }; const argType = services.getTypeAtLocation(node.argument); - const unionParts = tools.unionTypeParts(argType); + const unionParts = tsutils.unionTypeParts(argType); if ( unionParts.every( part => part.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined), diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index 400778454a9..89e56703c06 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -410,8 +410,8 @@ export default util.createRule({ function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean { const type = checker.getTypeAtLocation(node); - for (const subType of tools.unionTypeParts(checker.getApparentType(type))) { - if (tools.isThenableType(checker, node, subType)) { + for (const subType of tsutils.unionTypeParts(checker.getApparentType(type))) { + if (tsutils.isThenableType(checker, node, subType)) { return true; } } @@ -426,7 +426,7 @@ function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean { function isAlwaysThenable(checker: ts.TypeChecker, node: ts.Node): boolean { const type = checker.getTypeAtLocation(node); - for (const subType of tools.unionTypeParts(checker.getApparentType(type))) { + for (const subType of tsutils.unionTypeParts(checker.getApparentType(type))) { const thenProp = subType.getProperty('then'); // If one of the alternates has no then property, it is not thenable in all @@ -440,7 +440,7 @@ function isAlwaysThenable(checker: ts.TypeChecker, node: ts.Node): boolean { // be of the right form to consider it thenable. const thenType = checker.getTypeOfSymbolAtLocation(thenProp, node); let hasThenableSignature = false; - for (const subType of tools.unionTypeParts(thenType)) { + for (const subType of tsutils.unionTypeParts(thenType)) { for (const signature of subType.getCallSignatures()) { if ( signature.parameters.length !== 0 && @@ -478,7 +478,7 @@ function isFunctionParam( const type: ts.Type | undefined = checker.getApparentType( checker.getTypeOfSymbolAtLocation(param, node), ); - for (const subType of tools.unionTypeParts(type)) { + for (const subType of tsutils.unionTypeParts(type)) { if (subType.getCallSignatures().length !== 0) { return true; } @@ -527,7 +527,7 @@ function voidFunctionArguments( // We can't use checker.getResolvedSignature because it prefers an early '() => void' over a later '() => Promise' // See https://github.com/microsoft/TypeScript/issues/48077 - for (const subType of tools.unionTypeParts(type)) { + for (const subType of tsutils.unionTypeParts(type)) { // Standard function calls and `new` have two different types of signatures const signatures = ts.isCallExpression(node) ? subType.getCallSignatures() @@ -610,7 +610,7 @@ function anySignatureIsThenableType( ): boolean { for (const signature of type.getCallSignatures()) { const returnType = signature.getReturnType(); - if (tools.isThenableType(checker, node, returnType)) { + if (tsutils.isThenableType(checker, node, returnType)) { return true; } } @@ -626,7 +626,7 @@ function isThenableReturningFunctionType( node: ts.Node, type: ts.Type, ): boolean { - for (const subType of tools.unionTypeParts(type)) { + for (const subType of tsutils.unionTypeParts(type)) { if (anySignatureIsThenableType(checker, node, subType)) { return true; } @@ -645,17 +645,17 @@ function isVoidReturningFunctionType( ): boolean { let hadVoidReturn = false; - for (const subType of tools.unionTypeParts(type)) { + for (const subType of tsutils.unionTypeParts(type)) { for (const signature of subType.getCallSignatures()) { const returnType = signature.getReturnType(); // If a certain positional argument accepts both thenable and void returns, // a promise-returning function is valid - if (tools.isThenableType(checker, node, returnType)) { + if (tsutils.isThenableType(checker, node, returnType)) { return false; } - hadVoidReturn ||= tools.isTypeFlagSet(returnType, ts.TypeFlags.Void); + hadVoidReturn ||= tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void); } } diff --git a/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts b/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts index 825e4640540..3d7d4428eeb 100644 --- a/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts +++ b/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts @@ -1,5 +1,5 @@ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -106,11 +106,11 @@ function describeLiteralType(type: ts.Type): string { return `${type.value.negative ? '-' : ''}${type.value.base10Value}n`; } - if (tools.isBooleanLiteralType(type, true)) { + if (tsutils.isTrueLiteralType(type)) { return 'true'; } - if (tools.isBooleanLiteralType(type, false)) { + if (tsutils.isFalseLiteralType(type)) { return 'false'; } @@ -166,10 +166,10 @@ function isNodeInsideReturnType(node: TSESTree.TSUnionType): boolean { function unionTypePartsUnlessBoolean(type: ts.Type): ts.Type[] { return type.isUnion() && type.types.length === 2 && - tools.isBooleanLiteralType(type.types[0], false) && - tools.isBooleanLiteralType(type.types[1], true) + tsutils.isFalseLiteralType(type.types[0]) && + tsutils.isTrueLiteralType(type.types[1]) ? [type] - : tools.unionTypeParts(type); + : tsutils.unionTypeParts(type); } export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts index c88ac20675b..5f12660fd6d 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -110,7 +110,7 @@ export default util.createRule({ } function isBooleanType(expressionType: ts.Type): boolean { - return tools.isTypeFlagSet( + return tsutils.isTypeFlagSet( expressionType, ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral, ); @@ -131,7 +131,7 @@ export default util.createRule({ const nonNullishTypes = types.filter( type => - !tools.isTypeFlagSet( + !tsutils.isTypeFlagSet( type, ts.TypeFlags.Undefined | ts.TypeFlags.Null, ), diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index b060ba86cd6..739e2e2a9f0 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { @@ -21,11 +21,12 @@ import { // Truthiness utilities // #region const isTruthyLiteral = (type: ts.Type): boolean => - tools.isBooleanLiteralType(type, true) || - (tools.isLiteralType(type) && !!type.value); + tsutils.isTrueLiteralType(type) || + // || type. + (type.isLiteral() && !!type.value); const isPossiblyFalsy = (type: ts.Type): boolean => - tools + tsutils .unionTypeParts(type) // PossiblyFalsy flag includes literal values, so exclude ones that // are definitely truthy @@ -33,7 +34,7 @@ const isPossiblyFalsy = (type: ts.Type): boolean => .some(type => isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy)); const isPossiblyTruthy = (type: ts.Type): boolean => - tools.unionTypeParts(type).some(type => !tools.isFalsyType(type)); + tsutils.unionTypeParts(type).some(type => !tsutils.isFalsyType(type)); // Nullish utilities const nullishFlag = ts.TypeFlags.Undefined | ts.TypeFlags.Null; @@ -41,19 +42,18 @@ const isNullishType = (type: ts.Type): boolean => isTypeFlagSet(type, nullishFlag); const isPossiblyNullish = (type: ts.Type): boolean => - tools.unionTypeParts(type).some(isNullishType); + tsutils.unionTypeParts(type).some(isNullishType); const isAlwaysNullish = (type: ts.Type): boolean => - tools.unionTypeParts(type).every(isNullishType); + tsutils.unionTypeParts(type).every(isNullishType); // isLiteralType only covers numbers and strings, this is a more exhaustive check. const isLiteral = (type: ts.Type): boolean => - tools.isBooleanLiteralType(type, true) || - tools.isBooleanLiteralType(type, false) || + tsutils.isBooleanLiteralType(type) || type.flags === ts.TypeFlags.Undefined || type.flags === ts.TypeFlags.Null || type.flags === ts.TypeFlags.Void || - tools.isLiteralType(type); + type.isLiteral(); // #endregion export type Options = [ @@ -145,7 +145,7 @@ export default createRule({ const checker = services.program.getTypeChecker(); const sourceCode = context.getSourceCode(); const compilerOptions = services.program.getCompilerOptions(); - const isStrictNullChecks = tools.isStrictCompilerOptionEnabled( + const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'strictNullChecks', ); @@ -227,7 +227,7 @@ export default createRule({ // Conditional is always necessary if it involves: // `any` or `unknown` or a naked type variable if ( - tools + tsutils .unionTypeParts(type) .some( part => @@ -389,9 +389,8 @@ export default createRule({ */ if ( allowConstantLoopConditions && - tools.isBooleanLiteralType( + tsutils.isTrueLiteralType( getConstrainedTypeAtLocation(services, node.test), - true, ) ) { return; @@ -446,7 +445,7 @@ export default createRule({ // (Value to complexity ratio is dubious however) } // Otherwise just do type analysis on the function as a whole. - const returnTypes = tools + const returnTypes = tsutils .getCallSignaturesOfType( getConstrainedTypeAtLocation(services, callback), ) diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts index 57c6a4fd605..357a5b45f3d 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -33,7 +33,7 @@ export default util.createRule({ symbol: ts.Symbol, checker: ts.TypeChecker, ): ts.Symbol | null { - return tools.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) + return tsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : null; } diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts index beeea459717..e0d305cc0dd 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts @@ -1,5 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -179,7 +179,7 @@ function getAliasedSymbol( symbol: ts.Symbol, checker: ts.TypeChecker, ): ts.Symbol { - return tools.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) + return tsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : symbol; } diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 3d38a30e32c..76fc59da74b 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -94,7 +94,7 @@ export default util.createRule({ if ( // non-strict mode doesn't care about used before assigned errors - tools.isStrictCompilerOptionEnabled( + tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'strictNullChecks', ) && @@ -241,9 +241,9 @@ export default util.createRule({ const castType = services.getTypeAtLocation(node); if ( - tools.isTypeFlagSet(castType, ts.TypeFlags.Literal) || - (tools.isObjectType(castType) && - (tools.isObjectFlagSet(castType, ts.ObjectFlags.Tuple) || + tsutils.isTypeFlagSet(castType, ts.TypeFlags.Literal) || + (tsutils.isObjectType(castType) && + (tsutils.isObjectFlagSet(castType, ts.ObjectFlags.Tuple) || couldBeTupleType(castType))) ) { // It's not always safe to remove a cast to a literal type or tuple diff --git a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts index b9ce9f49ad8..7e929071e19 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import type * as ts from 'typescript'; import * as util from '../util'; @@ -45,7 +45,7 @@ export default util.createRule({ const services = util.getParserServices(context); const checker = services.program.getTypeChecker(); const compilerOptions = services.program.getCompilerOptions(); - const isNoImplicitThis = tools.isStrictCompilerOptionEnabled( + const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'noImplicitThis', ); diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index d7fe95aa2fc..b47d3ee9d85 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -1,5 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as util from '../util'; import { getThisExpression } from '../util'; @@ -34,7 +34,7 @@ export default util.createRule<[], MessageIds>({ create(context) { const services = util.getParserServices(context); const compilerOptions = services.program.getCompilerOptions(); - const isNoImplicitThis = tools.isStrictCompilerOptionEnabled( + const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'noImplicitThis', ); diff --git a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts index 345d1c744cf..a5a8d3c6c4b 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as util from '../util'; import { getThisExpression } from '../util'; @@ -35,7 +35,7 @@ export default util.createRule({ create(context) { const services = util.getParserServices(context); const compilerOptions = services.program.getCompilerOptions(); - const isNoImplicitThis = tools.isStrictCompilerOptionEnabled( + const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'noImplicitThis', ); diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index c8c2ed9bbbf..93a1226e9e4 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -31,7 +31,7 @@ export default util.createRule({ const services = util.getParserServices(context); const checker = services.program.getTypeChecker(); const compilerOptions = services.program.getCompilerOptions(); - const isNoImplicitThis = tools.isStrictCompilerOptionEnabled( + const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'noImplicitThis', ); diff --git a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts index 36d6d7bd819..9b0a313e756 100644 --- a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts +++ b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -30,18 +30,20 @@ export default util.createRule({ const getTypesIfNotLoose = (node: TSESTree.Node): ts.Type[] | undefined => { const type = services.getTypeAtLocation(node); - if (tools.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) { + if ( + tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown) + ) { return undefined; } - return tools.unionTypeParts(type); + return tsutils.unionTypeParts(type); }; const couldBeNullish = (type: ts.Type): boolean => { if (type.flags & ts.TypeFlags.TypeParameter) { const constraint = type.getConstraint(); return constraint == null || couldBeNullish(constraint); - } else if (tools.isUnionType(type)) { + } else if (tsutils.isUnionType(type)) { for (const part of type.types) { if (couldBeNullish(part)) { return true; diff --git a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts index 58ead7e4b7a..39bee570147 100644 --- a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts +++ b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -83,7 +83,7 @@ export default util.createRule({ const services = util.getParserServices(context); const compilerOptions = services.program.getCompilerOptions(); const sourceCode = context.getSourceCode(); - const isStrictNullChecks = tools.isStrictCompilerOptionEnabled( + const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'strictNullChecks', ); diff --git a/packages/eslint-plugin/src/rules/prefer-readonly.ts b/packages/eslint-plugin/src/rules/prefer-readonly.ts index e91aa5bc8a9..0f83d598d29 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -82,7 +82,7 @@ export default util.createRule({ ): void { if ( parent.left === node && - tools.isAssignmentKind(parent.operatorToken.kind) + tsutils.isAssignmentKind(parent.operatorToken.kind) ) { classScope.addVariableModification(node); } @@ -140,7 +140,7 @@ export default util.createRule({ | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.MethodDefinition, - ): boolean | tools.ScopeBoundary { + ): boolean { if (classScopeStack.length === 0) { return false; } @@ -150,7 +150,7 @@ export default util.createRule({ return false; } - return tools.isFunctionScopeBoundary(tsNode); + return tsutils.isFunctionScopeBoundary(tsNode); } function getEsNodesFromViolatingNode( @@ -273,7 +273,7 @@ class ClassScope { private readonly onlyInlineLambdas?: boolean, ) { const classType = checker.getTypeAtLocation(classNode); - if (tools.isIntersectionType(classType)) { + if (tsutils.isIntersectionType(classType)) { this.classType = classType.types[0]; } else { this.classType = classType; @@ -288,8 +288,8 @@ class ClassScope { public addDeclaredVariable(node: ParameterOrPropertyDeclaration): void { if ( - !tools.isModifierFlagSet(node, ts.ModifierFlags.Private) || - tools.isModifierFlagSet(node, ts.ModifierFlags.Readonly) || + !tsutils.isModifierFlagSet(node, ts.ModifierFlags.Private) || + tsutils.isModifierFlagSet(node, ts.ModifierFlags.Readonly) || ts.isComputedPropertyName(node.name) ) { return; @@ -303,7 +303,7 @@ class ClassScope { return; } - (tools.isModifierFlagSet(node, ts.ModifierFlags.Static) + (tsutils.isModifierFlagSet(node, ts.ModifierFlags.Static) ? this.privateModifiableStatics : this.privateModifiableMembers ).set(node.name.getText(), node); @@ -319,8 +319,8 @@ class ClassScope { } const modifyingStatic = - tools.isObjectType(modifierType) && - tools.isObjectFlagSet(modifierType, ts.ObjectFlags.Anonymous); + tsutils.isObjectType(modifierType) && + tsutils.isObjectFlagSet(modifierType, ts.ObjectFlags.Anonymous); if ( !modifyingStatic && this.constructorScopeDepth === DIRECTLY_INSIDE_CONSTRUCTOR @@ -344,7 +344,7 @@ class ClassScope { this.constructorScopeDepth = DIRECTLY_INSIDE_CONSTRUCTOR; for (const parameter of node.parameters) { - if (tools.isModifierFlagSet(parameter, ts.ModifierFlags.Private)) { + if (tsutils.isModifierFlagSet(parameter, ts.ModifierFlags.Private)) { this.addDeclaredVariable(parameter); } } diff --git a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts index dd185a476a5..e68d5c207ac 100644 --- a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts +++ b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import type * as ts from 'typescript'; import { @@ -133,7 +133,7 @@ export default createRule({ const argumentType = services.getTypeAtLocation(argumentNode); const argumentTypes = collectArgumentTypes( - tools.unionTypeParts(argumentType), + tsutils.unionTypeParts(argumentType), ); switch (argumentTypes) { case ArgumentType.RegExp: diff --git a/packages/eslint-plugin/src/rules/require-await.ts b/packages/eslint-plugin/src/rules/require-await.ts index f363c2ee662..b59bfe41bbb 100644 --- a/packages/eslint-plugin/src/rules/require-await.ts +++ b/packages/eslint-plugin/src/rules/require-await.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import type * as ts from 'typescript'; import * as util from '../util'; @@ -88,7 +88,7 @@ export default util.createRule({ function isThenableType(node: ts.Node): boolean { const type = checker.getTypeAtLocation(node); - return tools.isThenableType(checker, node, type); + return tsutils.isThenableType(checker, node, type); } /** @@ -119,7 +119,7 @@ export default util.createRule({ const type = services.getTypeAtLocation(node.argument); const typesToCheck = expandUnionOrIntersectionType(type); for (const type of typesToCheck) { - const asyncIterator = tools.getWellKnownSymbolPropertyOfType( + const asyncIterator = tsutils.getWellKnownSymbolPropertyOfType( type, 'asyncIterator', checker, diff --git a/packages/eslint-plugin/src/rules/return-await.ts b/packages/eslint-plugin/src/rules/return-await.ts index 9fbe9850c68..89422a32db0 100644 --- a/packages/eslint-plugin/src/rules/return-await.ts +++ b/packages/eslint-plugin/src/rules/return-await.ts @@ -1,6 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -187,7 +187,7 @@ export default util.createRule({ } const type = checker.getTypeAtLocation(child); - const isThenable = tools.isThenableType(checker, expression, type); + const isThenable = tsutils.isThenableType(checker, expression, type); if (!isAwait && !isThenable) { return; diff --git a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts index 111fcca5e64..2737b10cc97 100644 --- a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts +++ b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts @@ -3,7 +3,7 @@ import type { TSESTree, } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -155,7 +155,7 @@ export default util.createRule({ const checker = services.program.getTypeChecker(); const compilerOptions = services.program.getCompilerOptions(); const sourceCode = context.getSourceCode(); - const isStrictNullChecks = tools.isStrictCompilerOptionEnabled( + const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled( compilerOptions, 'strictNullChecks', ); @@ -268,7 +268,7 @@ export default util.createRule({ */ function checkNode(node: TSESTree.Node): void { const type = util.getConstrainedTypeAtLocation(services, node); - const types = inspectVariantTypes(tools.unionTypeParts(type)); + const types = inspectVariantTypes(tsutils.unionTypeParts(type)); const is = (...wantedTypes: readonly VariantType[]): boolean => types.size === wantedTypes.length && @@ -802,7 +802,7 @@ export default util.createRule({ if ( types.some(type => - tools.isTypeFlagSet( + tsutils.isTypeFlagSet( type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike, ), @@ -811,7 +811,7 @@ export default util.createRule({ variantTypes.add('nullish'); } const booleans = types.filter(type => - tools.isTypeFlagSet(type, ts.TypeFlags.BooleanLike), + tsutils.isTypeFlagSet(type, ts.TypeFlags.BooleanLike), ); // If incoming type is either "true" or "false", there will be one type @@ -819,7 +819,7 @@ export default util.createRule({ // If incoming type is boolean, there will be two type objects with // intrinsicName set "true" and "false" each because of ts-api-utils.unionTypeParts() if (booleans.length === 1) { - tools.isBooleanLiteralType(booleans[0], true) + tsutils.isTrueLiteralType(booleans[0]) ? variantTypes.add('truthy boolean') : variantTypes.add('boolean'); } else if (booleans.length === 2) { @@ -827,7 +827,7 @@ export default util.createRule({ } const strings = types.filter(type => - tools.isTypeFlagSet(type, ts.TypeFlags.StringLike), + tsutils.isTypeFlagSet(type, ts.TypeFlags.StringLike), ); if (strings.length) { @@ -839,7 +839,7 @@ export default util.createRule({ } const numbers = types.filter(type => - tools.isTypeFlagSet( + tsutils.isTypeFlagSet( type, ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike, ), @@ -853,7 +853,7 @@ export default util.createRule({ } if ( - types.some(type => tools.isTypeFlagSet(type, ts.TypeFlags.EnumLike)) + types.some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.EnumLike)) ) { variantTypes.add('enum'); } @@ -861,7 +861,7 @@ export default util.createRule({ if ( types.some( type => - !tools.isTypeFlagSet( + !tsutils.isTypeFlagSet( type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | @@ -893,7 +893,7 @@ export default util.createRule({ variantTypes.add('any'); } - if (types.some(type => tools.isTypeFlagSet(type, ts.TypeFlags.Never))) { + if (types.some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.Never))) { variantTypes.add('never'); } diff --git a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts index 420a60f03d7..caba3e9b933 100644 --- a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts +++ b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts @@ -1,5 +1,5 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { @@ -115,7 +115,7 @@ export default createRule({ const symbolName = discriminantType.getSymbol()?.escapedName; if (discriminantType.isUnion()) { - const unionTypes = tools.unionTypeParts(discriminantType); + const unionTypes = tsutils.unionTypeParts(discriminantType); const caseTypes: Set = new Set(); for (const switchCase of node.cases) { if (switchCase.test == null) { @@ -143,7 +143,7 @@ export default createRule({ data: { missingBranches: missingBranchTypes .map(missingType => - tools.isTypeFlagSet(missingType, ts.TypeFlags.ESSymbolLike) + tsutils.isTypeFlagSet(missingType, ts.TypeFlags.ESSymbolLike) ? `typeof ${missingType.getSymbol()?.escapedName as string}` : checker.typeToString(missingType), ) diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index 93aaddf1a79..4b69571ed30 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import * as util from '../util'; @@ -281,7 +281,7 @@ function checkMethod( !thisArgIsVoid && !( ignoreStatic && - tools.hasModifier( + tsutils.hasModifier( getModifiers(valueDeclaration), ts.SyntaxKind.StaticKeyword, ) diff --git a/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts b/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts index 7cd0527b2cf..44919f60d79 100644 --- a/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts @@ -369,7 +369,7 @@ ruleTester.run('prefer-readonly-parameter-types', rule, { interface Obj { readonly [K: string]: Obj; } - + function foo(event: Obj): void {} `, options: [ @@ -386,11 +386,11 @@ ruleTester.run('prefer-readonly-parameter-types', rule, { interface Obj1 { readonly [K: string]: Obj2; } - + interface Obj2 { readonly [K: string]: Obj1; } - + function foo(event: Obj1): void {} `, options: [ @@ -869,5 +869,21 @@ ruleTester.run('prefer-readonly-parameter-types', rule, { }, ], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/3405 + { + code: ` + type MyType = { + [K in keyof T]: 'cat' | 'dog' | T[K]; + }; + + function method(value: MyType) { + return value; + } + + method(['cat', 'dog']); + method<'mouse'[]>(['cat', 'mouse']); + `, + errors: [{ line: 6, messageId: 'shouldBeReadonly' }], + }, ], }); diff --git a/packages/eslint-plugin/tests/rules/require-await.test.ts b/packages/eslint-plugin/tests/rules/require-await.test.ts index c31dab5a0d7..6cd40be6deb 100644 --- a/packages/eslint-plugin/tests/rules/require-await.test.ts +++ b/packages/eslint-plugin/tests/rules/require-await.test.ts @@ -218,6 +218,18 @@ async function* foo(): Promise { return new Promise(res => res(\`hello\`)); } `, + // https://github.com/typescript-eslint/typescript-eslint/issues/5458 + ` + async function* f() { + let x!: Omit< + { + [Symbol.asyncIterator](): AsyncIterator; + }, + 'z' + >; + yield* x; + } + `, ], invalid: [ diff --git a/packages/type-utils/package.json b/packages/type-utils/package.json index 67848dd4b9a..f93aa96e8e6 100644 --- a/packages/type-utils/package.json +++ b/packages/type-utils/package.json @@ -50,7 +50,7 @@ "@typescript-eslint/typescript-estree": "5.53.0", "@typescript-eslint/utils": "5.53.0", "debug": "^4.3.4", - "ts-api-utils": "^0.0.22" + "ts-api-utils": "^0.0.39" }, "devDependencies": { "@typescript-eslint/parser": "5.53.0", diff --git a/packages/type-utils/src/containsAllTypesByName.ts b/packages/type-utils/src/containsAllTypesByName.ts index 7021f2b5cb0..dcd6c87c807 100644 --- a/packages/type-utils/src/containsAllTypesByName.ts +++ b/packages/type-utils/src/containsAllTypesByName.ts @@ -1,4 +1,4 @@ -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { isTypeFlagSet } from './typeFlagUtils'; @@ -20,7 +20,7 @@ export function containsAllTypesByName( return !allowAny; } - if (tools.isTypeReference(type)) { + if (tsutils.isTypeReference(type)) { type = type.target; } @@ -32,7 +32,7 @@ export function containsAllTypesByName( const predicate = (t: ts.Type): boolean => containsAllTypesByName(t, allowAny, allowedNames, matchAnyInstead); - if (tools.isUnionOrIntersectionType(type)) { + if (tsutils.isUnionOrIntersectionType(type)) { return matchAnyInstead ? type.types.some(predicate) : type.types.every(predicate); diff --git a/packages/type-utils/src/isTypeReadonly.ts b/packages/type-utils/src/isTypeReadonly.ts index 825aa38b7c5..6a6e94cf814 100644 --- a/packages/type-utils/src/isTypeReadonly.ts +++ b/packages/type-utils/src/isTypeReadonly.ts @@ -1,5 +1,5 @@ import { ESLintUtils } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { getTypeOfPropertyOfType } from './propertyTypes'; @@ -128,7 +128,7 @@ function isTypeReadonlyObject( if ( property.valueDeclaration !== undefined && hasSymbol(property.valueDeclaration) && - tools.isSymbolFlagSet( + tsutils.isSymbolFlagSet( property.valueDeclaration.symbol, ts.SymbolFlags.Method, ) @@ -144,14 +144,18 @@ function isTypeReadonlyObject( if ( lastDeclaration !== undefined && hasSymbol(lastDeclaration) && - tools.isSymbolFlagSet(lastDeclaration.symbol, ts.SymbolFlags.Method) + tsutils.isSymbolFlagSet(lastDeclaration.symbol, ts.SymbolFlags.Method) ) { continue; } } if ( - tools.isPropertyReadonlyInType(type, property.getEscapedName(), checker) + tsutils.isPropertyReadonlyInType( + type, + property.getEscapedName(), + checker, + ) ) { continue; } @@ -216,9 +220,9 @@ function isTypeReadonlyRecurser( ): Readonlyness.Readonly | Readonlyness.Mutable { seenTypes.add(type); - if (tools.isUnionType(type)) { + if (tsutils.isUnionType(type)) { // all types in the union must be readonly - const result = tools + const result = tsutils .unionTypeParts(type) .every( t => @@ -230,7 +234,7 @@ function isTypeReadonlyRecurser( return readonlyness; } - if (tools.isIntersectionType(type)) { + if (tsutils.isIntersectionType(type)) { // Special case for handling arrays/tuples (as readonly arrays/tuples always have mutable methods). if ( type.types.some(t => checker.isArrayType(t) || checker.isTupleType(t)) @@ -256,7 +260,7 @@ function isTypeReadonlyRecurser( } } - if (tools.isConditionalType(type)) { + if (tsutils.isConditionalType(type)) { const result = [type.root.node.trueType, type.root.node.falseType] .map(checker.getTypeFromTypeNode) .every( @@ -272,7 +276,7 @@ function isTypeReadonlyRecurser( // all non-object, non-intersection types are readonly. // this should only be primitive types - if (!tools.isObjectType(type)) { + if (!tsutils.isObjectType(type)) { return Readonlyness.Readonly; } diff --git a/packages/type-utils/src/isUnsafeAssignment.ts b/packages/type-utils/src/isUnsafeAssignment.ts index be92fcaace1..4805b3fa4da 100644 --- a/packages/type-utils/src/isUnsafeAssignment.ts +++ b/packages/type-utils/src/isUnsafeAssignment.ts @@ -1,6 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import type * as ts from 'typescript'; import { isTypeAnyType, isTypeUnknownType } from './predicates'; @@ -32,7 +32,7 @@ export function isUnsafeAssignment( } } - if (tools.isTypeReference(type) && tools.isTypeReference(receiver)) { + if (tsutils.isTypeReference(type) && tsutils.isTypeReference(receiver)) { // TODO - figure out how to handle cases like this, // where the types are assignable, but not the same type /* diff --git a/packages/type-utils/src/predicates.ts b/packages/type-utils/src/predicates.ts index fa4524e7808..f194bc9d92e 100644 --- a/packages/type-utils/src/predicates.ts +++ b/packages/type-utils/src/predicates.ts @@ -1,5 +1,5 @@ import debug from 'debug'; -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { getTypeArguments } from './getTypeArguments'; @@ -39,7 +39,7 @@ export function isTypeArrayTypeOrUnionOfArrayTypes( type: ts.Type, checker: ts.TypeChecker, ): boolean { - for (const t of tools.unionTypeParts(type)) { + for (const t of tsutils.unionTypeParts(type)) { if (!checker.isArrayType(t)) { return false; } diff --git a/packages/type-utils/src/typeFlagUtils.ts b/packages/type-utils/src/typeFlagUtils.ts index 7e2003f6fe2..11507ed5c78 100644 --- a/packages/type-utils/src/typeFlagUtils.ts +++ b/packages/type-utils/src/typeFlagUtils.ts @@ -1,4 +1,4 @@ -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; /** @@ -6,7 +6,7 @@ import * as ts from 'typescript'; */ export function getTypeFlags(type: ts.Type): ts.TypeFlags { let flags: ts.TypeFlags = 0; - for (const t of tools.unionTypeParts(type)) { + for (const t of tsutils.unionTypeParts(type)) { flags |= t.flags; } return flags; diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 54678d6f631..b5d956398af 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -68,7 +68,7 @@ "globby": "^11.1.0", "is-glob": "^4.0.3", "semver": "^7.3.7", - "ts-api-utils": "^0.0.22" + "ts-api-utils": "^0.0.39" }, "devDependencies": { "@babel/code-frame": "*", diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index dec2d5bcaa5..a8e98ddbca8 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -1,4 +1,4 @@ -import * as tools from 'ts-api-utils'; +import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; import { getLocFor } from './node-utils'; @@ -18,7 +18,7 @@ export function convertComments( ): TSESTree.Comment[] { const comments: TSESTree.Comment[] = []; - tools.forEachComment( + tsutils.forEachComment( ast, (_, comment) => { const type = diff --git a/patches/ts-api-utils+0.0.21.patch b/patches/ts-api-utils+0.0.39.patch similarity index 91% rename from patches/ts-api-utils+0.0.21.patch rename to patches/ts-api-utils+0.0.39.patch index e7ed2ef0bdf..d895b77dec5 100644 --- a/patches/ts-api-utils+0.0.21.patch +++ b/patches/ts-api-utils+0.0.39.patch @@ -10,4 +10,4 @@ index 41ee37c..e4279d1 100644 + "type": "commonjs", "exports": { ".": { - "types": "./lib/index.d.ts", + "types": { diff --git a/yarn.lock b/yarn.lock index 54d2b8cdeab..a0edd69251c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13296,10 +13296,10 @@ trough@^1.0.0: resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.5.tgz#b8b639cefad7d0bb2abd37d433ff8293efa5f406" integrity sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA== -ts-api-utils@^0.0.22: - version "0.0.22" - resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.22.tgz#c58aac346f3990e6e164b4907aca57f54d81a2e8" - integrity sha512-XrQNMP/CQk2gOa+NfNIxNSf60n+RsC7tAkyCxhwnkShxUFpitvwNDfDxdMIZxHtdKKqqeRi94T191sNN7pFSrg== +ts-api-utils@^0.0.39: + version "0.0.39" + resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.39.tgz#cd3d2dd88a68cbc8259cf9944fbd4dbd19f1d69c" + integrity sha512-JSEMbhv2bJCgJUhN/6y58Om6k7rmZ7BwJsklWwv0srfMc7HkhnfHA1sGpGltS6VSTMT4PVEqj/IVsCAPcU1l/g== ts-essentials@^2.0.3: version "2.0.12"