Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bumped ts-api-utils to 0.0.39 #6497

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/Custom_Rules.mdx
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Expand Up @@ -53,7 +53,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.28"
},
"devDependencies": {
"@types/debug": "*",
Expand Down
4 changes: 2 additions & 2 deletions 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';

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions 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 {
Expand Down Expand Up @@ -75,7 +75,7 @@ export default createRule<Options, MessageIds>({
options.allowProtectedClassPropertyAccess;
const allowIndexSignaturePropertyAccess =
(options.allowIndexSignaturePropertyAccess ?? false) ||
tools.isCompilerOptionEnabled(
tsutils.isCompilerOptionEnabled(
services.program.getCompilerOptions(),
'noPropertyAccessFromIndexSignature',
);
Expand Down
@@ -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';
Expand Down Expand Up @@ -81,7 +81,7 @@ export default util.createRule<Options, MessageId>({
): 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;
}
Expand Down
4 changes: 2 additions & 2 deletions 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';

Expand Down Expand Up @@ -97,6 +97,6 @@ function isNecessaryDynamicAccess(property: TSESTree.Expression): boolean {

return (
typeof property.value === 'string' &&
!tools.isValidPropertyAccess(property.value)
!tsutils.isValidPropertyAccess(property.value)
);
}
8 changes: 4 additions & 4 deletions 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';
Expand Down Expand Up @@ -240,7 +240,7 @@ export default util.createRule<Options, MessageId>({
// 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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions 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';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default util.createRule({

if (
symbol &&
tools.isSymbolFlagSet(
tsutils.isSymbolFlagSet(
symbol,
ts.SymbolFlags.Function | ts.SymbolFlags.Method,
)
Expand Down
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
24 changes: 12 additions & 12 deletions 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';
Expand Down Expand Up @@ -410,8 +410,8 @@ export default util.createRule<Options, MessageId>({
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;
}
}
Expand All @@ -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
Expand 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 &&
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ function voidFunctionArguments(
// We can't use checker.getResolvedSignature because it prefers an early '() => void' over a later '() => Promise<void>'
// 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()
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
@@ -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';
Expand Down Expand Up @@ -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.isBooleanLiteralType(type, true)) {
return 'true';
}

if (tools.isBooleanLiteralType(type, false)) {
if (tsutils.isBooleanLiteralType(type, false)) {
return 'false';
}

Expand Down Expand Up @@ -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.isBooleanLiteralType(type.types[0], false) &&
tsutils.isBooleanLiteralType(type.types[1], true)
? [type]
: tools.unionTypeParts(type);
: tsutils.unionTypeParts(type);
}

export default util.createRule({
Expand Down
@@ -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';
Expand Down Expand Up @@ -110,7 +110,7 @@ export default util.createRule<Options, MessageIds>({
}

function isBooleanType(expressionType: ts.Type): boolean {
return tools.isTypeFlagSet(
return tsutils.isTypeFlagSet(
expressionType,
ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral,
);
Expand All @@ -131,7 +131,7 @@ export default util.createRule<Options, MessageIds>({

const nonNullishTypes = types.filter(
type =>
!tools.isTypeFlagSet(
!tsutils.isTypeFlagSet(
type,
ts.TypeFlags.Undefined | ts.TypeFlags.Null,
),
Expand Down