Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP Integrate used tsutils functions#5689

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
26 commits
Select commitHold shift + click to select a range
bdde634
WIP Integrate used tsutils functions
varwasabiSep 25, 2022
ffb2dd1
Add `isJsxExpression`
varwasabiSep 25, 2022
1342253
Add `isNewExpression`
varwasabiSep 25, 2022
84b2283
Add `isPropertyDeclaration`
varwasabiSep 25, 2022
daf96d3
Add `isPropertyAssignment`
varwasabiSep 25, 2022
03f3d00
Add `isUnionOrIntersectionType`
varwasabiSep 25, 2022
371b6b1
Add `isValidPropertyAccess`
varwasabiSep 25, 2022
b74a090
Add `isParameterDeclaration`
varwasabiSep 25, 2022
066efc0
Add `isObjectType`
varwasabiSep 25, 2022
844cb10
Add `isObjectFlagSet`
varwasabiSep 25, 2022
4bd0bd0
Add `isModifierFlagSet`
varwasabiSep 25, 2022
64ea998
Add `isVariableDeclaration`
varwasabiSep 25, 2022
2090ade
Add `isStrictCompilerOptionEnabled`
varwasabiSep 25, 2022
2f11a14
Add `isSymbolFlagSet`
varwasabiSep 25, 2022
bc8f8cc
Add `isThenableType`
varwasabiSep 25, 2022
fe48d85
Add `getWellKnownSymbolPropertyOfType`
varwasabiSep 25, 2022
cffe5d3
Add `isCompilerOptionEnabled`
varwasabiSep 25, 2022
cb5f139
Remove various usages of tsutils
varwasabiSep 25, 2022
b6f1705
Add `isExpression`
varwasabiSep 25, 2022
e11c028
Remove tsutils import from `CUSTOM_RULES.md`
varwasabiSep 25, 2022
e324b3f
Add `isLiteralType`
varwasabiSep 25, 2022
5661313
Add `isFalsyType`
varwasabiSep 25, 2022
81cdc88
Add `getCallSignaturesOfType`
varwasabiSep 25, 2022
8457217
Add `isFunctionScopeBoundary`
varwasabiSep 25, 2022
eb35908
Use original isTypeFlagSet
varwasabiSep 25, 2022
4f1cbd7
Merge branch 'main' into integrate-tsutils
varwasabiSep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionsdocs/development/CUSTOM_RULES.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -222,9 +222,9 @@ By mapping from ESTree nodes to TypeScript nodes and retrieving the TypeScript p
This rule bans for-of looping over an enum by using the type-checker via typescript-eslint and TypeScript APIs:

```ts
import { isTypeFlagSet } from '@typescript-eslint/type-utils';
import { ESLintUtils } from '@typescript-eslint/utils';
import * as ts from 'typescript';
import * as tsutils from 'tsutils';

export const rule = createRule({
create(context) {
Expand All@@ -241,7 +241,7 @@ export const rule = createRule({
const nodeType = checker.getTypeAtLocation(originalNode);

// 3. Check the TS node type using the TypeScript APIs
if (tsutils.isTypeFlagSet(nodeType, ts.TypeFlags.EnumLike)) {
if (isTypeFlagSet(nodeType, ts.TypeFlags.EnumLike)) {
context.report({
messageId: 'loopOverEnum',
node: node.right,
Expand Down
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/await-thenable.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import* as tsutils from 'tsutils';
import{ isThenableType } from '@typescript-eslint/type-utils';

import * as util from '../util';

Expand DownExpand Up@@ -30,7 +30,7 @@ export default util.createRule({
if (
!util.isTypeAnyType(type) &&
!util.isTypeUnknownType(type) &&
!tsutils.isThenableType(checker, originalNode.expression, type)
!isThenableType(checker, originalNode.expression, type)
) {
context.report({
messageId: 'await',
Expand Down
5 changes: 2 additions & 3 deletionspackages/eslint-plugin/src/rules/dot-notation.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { isCompilerOptionEnabled } from '@typescript-eslint/type-utils';
import type { TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import type {
Expand DownExpand Up@@ -77,9 +77,8 @@ export default createRule<Options, MessageIds>({
options.allowProtectedClassPropertyAccess;
const allowIndexSignaturePropertyAccess =
(options.allowIndexSignaturePropertyAccess ?? false) ||
tsutils.isCompilerOptionEnabled(
isCompilerOptionEnabled(
program.getCompilerOptions(),
// @ts-expect-error - TS is refining the type to never for some reason
'noPropertyAccessFromIndexSignature',
);

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { isTypeFlagSet } from '@typescript-eslint/type-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -84,7 +84,7 @@ export default util.createRule<Options, MessageId>({
const checker = parserServices.program.getTypeChecker();
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
const type = util.getConstrainedTypeAtLocation(checker, tsNode);
if (!tsutils.isTypeFlagSet(type, ts.TypeFlags.VoidLike)) {
if (!isTypeFlagSet(type, ts.TypeFlags.VoidLike)) {
// not a void expression
return;
}
Expand Down
5 changes: 2 additions & 3 deletionspackages/eslint-plugin/src/rules/no-dynamic-delete.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { isValidPropertyAccess } from '@typescript-eslint/type-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';

import * as util from '../util';

Expand DownExpand Up@@ -96,7 +96,6 @@ function isNecessaryDynamicAccess(property: TSESTree.Expression): boolean {
}

return (
typeof property.value === 'string' &&
!tsutils.isValidPropertyAccess(property.value)
typeof property.value === 'string' && !isValidPropertyAccess(property.value)
);
}
8 changes: 4 additions & 4 deletionspackages/eslint-plugin/src/rules/no-floating-promises.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { unionTypeParts } from '@typescript-eslint/type-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import type * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -183,7 +183,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 oftsutils.unionTypeParts(checker.getApparentType(type))) {
for (const ty of unionTypeParts(checker.getApparentType(type))) {
const then = ty.getProperty('then');
if (then === undefined) {
continue;
Expand All@@ -209,7 +209,7 @@ function hasMatchingSignature(
type: ts.Type,
matcher: (signature: ts.Signature) => boolean,
): boolean {
for (const t oftsutils.unionTypeParts(type)) {
for (const t of unionTypeParts(type)) {
if (t.getCallSignatures().some(matcher)) {
return true;
}
Expand All@@ -226,7 +226,7 @@ function isFunctionParam(
const type: ts.Type | undefined = checker.getApparentType(
checker.getTypeOfSymbolAtLocation(param, node),
);
for (const t oftsutils.unionTypeParts(type)) {
for (const t of unionTypeParts(type)) {
if (t.getCallSignatures().length !== 0) {
return true;
}
Expand Down
7 changes: 2 additions & 5 deletionspackages/eslint-plugin/src/rules/no-implied-eval.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { isSymbolFlagSet } from '@typescript-eslint/type-utils';
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -71,10 +71,7 @@ export default util.createRule({

if (
symbol &&
tsutils.isSymbolFlagSet(
symbol,
ts.SymbolFlags.Function | ts.SymbolFlags.Method,
)
isSymbolFlagSet(symbol, ts.SymbolFlags.Function | ts.SymbolFlags.Method)
) {
return true;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { unionTypeParts } from '@typescript-eslint/type-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { ESLintUtils } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -64,7 +64,7 @@ export default util.createRule<
node.argument,
);
const argType = checker.getTypeAtLocation(argTsNode);
const unionParts =tsutils.unionTypeParts(argType);
const unionParts = unionTypeParts(argType);
if (
unionParts.every(
part => part.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined),
Expand Down
31 changes: 18 additions & 13 deletionspackages/eslint-plugin/src/rules/no-misused-promises.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
import {
isCallExpression,
isThenableType,
isTypeFlagSet,
unionTypeParts,
} from '@typescript-eslint/type-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -410,8 +415,8 @@ export default util.createRule<Options, MessageId>({
function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
const type = checker.getTypeAtLocation(node);

for (const subType oftsutils.unionTypeParts(checker.getApparentType(type))) {
if (tsutils.isThenableType(checker, node, subType)) {
for (const subType of unionTypeParts(checker.getApparentType(type))) {
if (isThenableType(checker, node, subType)) {
return true;
}
}
Expand All@@ -426,7 +431,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 oftsutils.unionTypeParts(checker.getApparentType(type))) {
for (const subType of 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 +445,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 oftsutils.unionTypeParts(thenType)) {
for (const subType of unionTypeParts(thenType)) {
for (const signature of subType.getCallSignatures()) {
if (
signature.parameters.length !== 0 &&
Expand DownExpand Up@@ -478,7 +483,7 @@ function isFunctionParam(
const type: ts.Type | undefined = checker.getApparentType(
checker.getTypeOfSymbolAtLocation(param, node),
);
for (const subType oftsutils.unionTypeParts(type)) {
for (const subType of unionTypeParts(type)) {
if (subType.getCallSignatures().length !== 0) {
return true;
}
Expand All@@ -500,9 +505,9 @@ function voidFunctionParams(
// 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 oftsutils.unionTypeParts(type)) {
for (const subType of unionTypeParts(type)) {
// Standard function calls and `new` have two different types of signatures
const signatures =ts.isCallExpression(node)
const signatures = isCallExpression(node)
? subType.getCallSignatures()
: subType.getConstructSignatures();
for (const signature of signatures) {
Expand DownExpand Up@@ -540,7 +545,7 @@ function anySignatureIsThenableType(
): boolean {
for (const signature of type.getCallSignatures()) {
const returnType = signature.getReturnType();
if (tsutils.isThenableType(checker, node, returnType)) {
if (isThenableType(checker, node, returnType)) {
return true;
}
}
Expand All@@ -556,7 +561,7 @@ function isThenableReturningFunctionType(
node: ts.Node,
type: ts.Type,
): boolean {
for (const subType oftsutils.unionTypeParts(type)) {
for (const subType of unionTypeParts(type)) {
if (anySignatureIsThenableType(checker, node, subType)) {
return true;
}
Expand All@@ -575,17 +580,17 @@ function isVoidReturningFunctionType(
): boolean {
let hadVoidReturn = false;

for (const subType oftsutils.unionTypeParts(type)) {
for (const subType of 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 (tsutils.isThenableType(checker, node, returnType)) {
if (isThenableType(checker, node, returnType)) {
return false;
}

hadVoidReturn ||=tsutils.isTypeFlagSet(returnType, ts.TypeFlags.Void);
hadVoidReturn ||= isTypeFlagSet(returnType, ts.TypeFlags.Void);
}
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
import {
isBooleanLiteralType,
unionTypeParts,
} from '@typescript-eslint/type-utils';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -106,11 +109,11 @@ function describeLiteralType(type: ts.Type): string {
return `${type.value.negative ? '-' : ''}${type.value.base10Value}n`;
}

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

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

Expand DownExpand Up@@ -167,10 +170,10 @@ function isNodeInsideReturnType(node: TSESTree.TSUnionType): boolean {
function unionTypePartsUnlessBoolean(type: ts.Type): ts.Type[] {
return type.isUnion() &&
type.types.length === 2 &&
tsutils.isBooleanLiteralType(type.types[0], false) &&
tsutils.isBooleanLiteralType(type.types[1], true)
isBooleanLiteralType(type.types[0], false) &&
isBooleanLiteralType(type.types[1], true)
? [type]
:tsutils.unionTypeParts(type);
: unionTypeParts(type);
}

export default util.createRule({
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import* as tsutils from 'tsutils';
import{ isTypeFlagSet } from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -113,7 +113,7 @@ export default util.createRule<Options, MessageIds>({
}

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

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

const hasNonNullishType = nonNullishTypes.length > 0;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
import {
getCallSignaturesOfType,
isBooleanLiteralType,
isFalsyType,
isLiteralType,
isStrictCompilerOptionEnabled,
unionTypeParts,
} from 'tsutils';
} from '@typescript-eslint/type-utils';
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
import * as ts from 'typescript';

import {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { isSymbolFlagSet } from '@typescript-eslint/type-utils';
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -35,7 +35,7 @@ export default util.createRule({
symbol: ts.Symbol,
checker: ts.TypeChecker,
): ts.Symbol | null {
returntsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
return isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
? checker.getAliasedSymbol(symbol)
: null;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
import {
isCallExpression,
isSymbolFlagSet,
} from '@typescript-eslint/type-utils';
import type { TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Expand DownExpand Up@@ -129,7 +132,7 @@ function getTypeParametersFromNode(
return getTypeParametersFromType(node.typeName, checker);
}

if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
if (isCallExpression(node) || ts.isNewExpression(node)) {
return getTypeParametersFromCall(node, checker);
}

Expand DownExpand Up@@ -180,7 +183,7 @@ function getAliasedSymbol(
symbol: ts.Symbol,
checker: ts.TypeChecker,
): ts.Symbol {
returntsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
return isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
? checker.getAliasedSymbol(symbol)
: symbol;
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp