Skip to content

Commit 55170b1

Browse files
committed
Update to @typescript-eslint/typescript-estree 5.x
1 parent 67b4972 commit 55170b1

13 files changed

Lines changed: 2042 additions & 2339 deletions

lib/parse/ClassIndex.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import type { ClassDeclaration,
2-
TSInterfaceDeclaration,
3-
TSTypeAliasDeclaration,
4-
TSEnumDeclaration,
5-
TypeNode,
6-
TSTypeParameterInstantiation } from '@typescript-eslint/types/dist/ts-estree';
7-
8-
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
1+
import type { AST, TSESTreeOptions, TSESTree } from '@typescript-eslint/typescript-estree';
92

103
/**
114
* A collection of classes, with exported name as key.
@@ -48,7 +41,7 @@ export interface ClassLoaded extends ClassReference {
4841
// The name of the file the class is defined in.
4942
fileName: string;
5043
// The loaded class declaration.
51-
declaration: ClassDeclaration;
44+
declaration: TSESTree.ClassDeclaration;
5245
// The full AST the class was present in.
5346
ast: AST<TSESTreeOptions>;
5447
// A super class reference if the class has one
@@ -66,7 +59,7 @@ export interface ClassLoaded extends ClassReference {
6659
/**
6760
* A hash of generic type name to its properties.
6861
*/
69-
export type GenericTypes = Record<string, { type?: TypeNode }>;
62+
export type GenericTypes = Record<string, { type?: TSESTree.TypeNode }>;
7063

7164
/**
7265
* Something (like a class or interface) that may have generic types assigned to it as instantiation.
@@ -75,7 +68,7 @@ export interface GenericallyTyped<T> {
7568
// The typed value
7669
value: T;
7770
// The generic types of this value
78-
genericTypeInstantiations?: TSTypeParameterInstantiation;
71+
genericTypeInstantiations?: TSESTree.TSTypeParameterInstantiation;
7972
}
8073

8174
/**
@@ -88,7 +81,7 @@ export interface InterfaceLoaded extends ClassReference {
8881
// The name of the file the interface is defined in.
8982
fileName: string;
9083
// The loaded interface declaration.
91-
declaration: TSInterfaceDeclaration;
84+
declaration: TSESTree.TSInterfaceDeclaration;
9285
// The full AST the interface was present in.
9386
ast: AST<TSESTreeOptions>;
9487
// Super interface references if the interface has them
@@ -104,7 +97,7 @@ export interface InterfaceLoaded extends ClassReference {
10497
*/
10598
export interface MemberField {
10699
name: string;
107-
range: TypeNode | undefined;
100+
range: TSESTree.TypeNode | undefined;
108101
}
109102

110103
/**
@@ -117,7 +110,7 @@ export interface TypeLoaded extends ClassReference {
117110
// The name of the file the interface is defined in.
118111
fileName: string;
119112
// The loaded type declaration.
120-
declaration: TSTypeAliasDeclaration;
113+
declaration: TSESTree.TSTypeAliasDeclaration;
121114
// The full AST the interface was present in.
122115
ast: AST<TSESTreeOptions>;
123116
// The tsdoc comment of this class
@@ -136,7 +129,7 @@ export interface EnumLoaded extends ClassReference {
136129
// The name of the file the interface is defined in.
137130
fileName: string;
138131
// The loaded enum declaration.
139-
declaration: TSEnumDeclaration;
132+
declaration: TSESTree.TSEnumDeclaration;
140133
// The full AST the interface was present in.
141134
ast: AST<TSESTreeOptions>;
142135
// The tsdoc comment of this class

lib/parse/ClassLoader.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import * as Path from 'path';
2-
import type {
3-
ClassDeclaration,
4-
TSEnumDeclaration,
5-
TSInterfaceDeclaration,
6-
TSModuleBlock,
7-
TSModuleDeclaration,
8-
TSTypeAliasDeclaration,
9-
} from '@typescript-eslint/types/dist/ts-estree';
10-
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
2+
import type { AST, TSESTreeOptions, TSESTree } from '@typescript-eslint/typescript-estree';
113
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
124
import type { Logger } from 'winston';
135
import type { ResolutionContext } from '../resolution/ResolutionContext';
@@ -43,7 +35,10 @@ export class ClassLoader {
4335
* @param declaration A class declaration.
4436
* @param fileName The file name of the current class.
4537
*/
46-
public getSuperClassName(declaration: ClassDeclaration, fileName: string): GenericallyTyped<string> | undefined {
38+
public getSuperClassName(
39+
declaration: TSESTree.ClassDeclaration,
40+
fileName: string,
41+
): GenericallyTyped<string> | undefined {
4742
if (!declaration.superClass) {
4843
return;
4944
}
@@ -69,7 +64,10 @@ export class ClassLoader {
6964
* @param declaration An interface declaration.
7065
* @param fileName The file name of the current class.
7166
*/
72-
public getSuperInterfaceNames(declaration: TSInterfaceDeclaration, fileName: string): GenericallyTyped<string>[] {
67+
public getSuperInterfaceNames(
68+
declaration: TSESTree.TSInterfaceDeclaration,
69+
fileName: string,
70+
): GenericallyTyped<string>[] {
7371
return <GenericallyTyped<string>[]> (declaration.extends || [])
7472
// eslint-disable-next-line array-callback-return
7573
.map(extendsExpression => {
@@ -92,7 +90,10 @@ export class ClassLoader {
9290
* @param declaration A class declaration.
9391
* @param fileName The file name of the current class.
9492
*/
95-
public getClassInterfaceNames(declaration: ClassDeclaration, fileName: string): GenericallyTyped<string>[] {
93+
public getClassInterfaceNames(
94+
declaration: TSESTree.ClassDeclaration,
95+
fileName: string,
96+
): GenericallyTyped<string>[] {
9697
const interfaceNames: GenericallyTyped<string>[] = [];
9798
if (declaration.implements) {
9899
for (const implement of declaration.implements) {
@@ -154,7 +155,7 @@ export class ClassLoader {
154155
* such as a type alias or enum.
155156
*/
156157
public async loadClassDeclarationFromAst<CI extends boolean, CT extends boolean>(
157-
ast: AST<TSESTreeOptions> | TSModuleBlock,
158+
ast: AST<TSESTreeOptions> | TSESTree.TSModuleBlock,
158159
targetString: string,
159160
classReference: ClassReference,
160161
considerInterfaces: CI,
@@ -367,7 +368,7 @@ export class ClassLoader {
367368
if (enumMember.id.type === AST_NODE_TYPES.Identifier && enumMember.id.name === enumKey &&
368369
enumMember.initializer && enumMember.initializer.type === AST_NODE_TYPES.Literal) {
369370
// Expose the enum entry as type alias
370-
const typeNode: TSTypeAliasDeclaration = {
371+
const typeNode: TSESTree.TSTypeAliasDeclaration = {
371372
type: AST_NODE_TYPES.TSTypeAliasDeclaration,
372373
id: {
373374
type: AST_NODE_TYPES.Identifier,
@@ -411,9 +412,9 @@ export class ClassLoader {
411412

412413
// Check if the export assignment refers to a namespace
413414
if (exportAssignment && typeof exportAssignment === 'string' && exportAssignment in declaredNamespaces) {
414-
const namespace: TSModuleDeclaration = declaredNamespaces[exportAssignment];
415+
const namespace: TSESTree.TSModuleDeclaration = declaredNamespaces[exportAssignment];
415416
return this.loadClassDeclarationFromAst(
416-
<TSModuleBlock>namespace.body,
417+
<TSESTree.TSModuleBlock>namespace.body,
417418
targetString,
418419
classReference,
419420
considerInterfaces,
@@ -430,7 +431,7 @@ export class ClassLoader {
430431
* @param classDeclaration A class or interface declaration.
431432
*/
432433
public collectGenericTypes(
433-
classDeclaration: ClassDeclaration | TSInterfaceDeclaration | TSTypeAliasDeclaration,
434+
classDeclaration: TSESTree.ClassDeclaration | TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration,
434435
): GenericTypes {
435436
const genericTypes: GenericTypes = {};
436437
if (classDeclaration.typeParameters) {
@@ -533,27 +534,27 @@ export class ClassLoader {
533534
public getClassElements(
534535
packageName: string,
535536
fileName: string,
536-
ast: AST<TSESTreeOptions> | TSModuleBlock,
537+
ast: AST<TSESTreeOptions> | TSESTree.TSModuleBlock,
537538
): ClassElements {
538-
const exportedClasses: Record<string, ClassDeclaration> = {};
539-
const exportedInterfaces: Record<string, TSInterfaceDeclaration> = {};
540-
const exportedTypes: Record<string, TSTypeAliasDeclaration> = {};
541-
const exportedEnums: Record<string, TSEnumDeclaration> = {};
542-
const exportedNamespaces: Record<string, TSModuleDeclaration> = {};
539+
const exportedClasses: Record<string, TSESTree.ClassDeclaration> = {};
540+
const exportedInterfaces: Record<string, TSESTree.TSInterfaceDeclaration> = {};
541+
const exportedTypes: Record<string, TSESTree.TSTypeAliasDeclaration> = {};
542+
const exportedEnums: Record<string, TSESTree.TSEnumDeclaration> = {};
543+
const exportedNamespaces: Record<string, TSESTree.TSModuleDeclaration> = {};
543544
const exportedImportedElements: Record<string, ClassReference> = {};
544545
const exportedImportedAll: { packageName: string; fileName: string; fileNameReferenced: string }[] = [];
545546
const exportedImportedAllNamed:
546547
Record<string, { packageName: string; fileName: string; fileNameReferenced: string }> = {};
547548
const exportedUnknowns: Record<string, string> = {};
548-
const declaredClasses: Record<string, ClassDeclaration> = {};
549-
const declaredInterfaces: Record<string, TSInterfaceDeclaration> = {};
550-
const declaredTypes: Record<string, TSTypeAliasDeclaration> = {};
551-
const declaredEnums: Record<string, TSEnumDeclaration> = {};
552-
const declaredNamespaces: Record<string, TSModuleDeclaration> = {};
549+
const declaredClasses: Record<string, TSESTree.ClassDeclaration> = {};
550+
const declaredInterfaces: Record<string, TSESTree.TSInterfaceDeclaration> = {};
551+
const declaredTypes: Record<string, TSESTree.TSTypeAliasDeclaration> = {};
552+
const declaredEnums: Record<string, TSESTree.TSEnumDeclaration> = {};
553+
const declaredNamespaces: Record<string, TSESTree.TSModuleDeclaration> = {};
553554
const importedElements: Record<string, ClassReference> = {};
554555
const importedElementsAllNamed:
555556
Record<string, { packageName: string; fileName: string; fileNameReferenced: string }> = {};
556-
let exportAssignment: string | ClassDeclaration | undefined;
557+
let exportAssignment: string | TSESTree.ClassDeclaration | undefined;
557558

558559
for (const statement of ast.body) {
559560
if (statement.type === AST_NODE_TYPES.ExportNamedDeclaration) {
@@ -685,15 +686,15 @@ export interface ClassLoaderArgs {
685686
*/
686687
export interface ClassElements {
687688
// Classes that have been declared in a file via `export class A`
688-
exportedClasses: Record<string, ClassDeclaration>;
689+
exportedClasses: Record<string, TSESTree.ClassDeclaration>;
689690
// Interfaces that have been declared in a file via `export interface A`
690-
exportedInterfaces: Record<string, TSInterfaceDeclaration>;
691+
exportedInterfaces: Record<string, TSESTree.TSInterfaceDeclaration>;
691692
// Types that have been declared in a file via `export type A = ...`
692-
exportedTypes: Record<string, TSTypeAliasDeclaration>;
693+
exportedTypes: Record<string, TSESTree.TSTypeAliasDeclaration>;
693694
// Enums that have been declared in a file via `export enum A {...}`
694-
exportedEnums: Record<string, TSEnumDeclaration>;
695+
exportedEnums: Record<string, TSESTree.TSEnumDeclaration>;
695696
// Namespaces that have been declared in a file via `export namespace A { ... }`
696-
exportedNamespaces: Record<string, TSModuleDeclaration>;
697+
exportedNamespaces: Record<string, TSESTree.TSModuleDeclaration>;
697698
// Elements that have been exported via `export { A as B } from "b"`
698699
exportedImportedElements: Record<string, ClassReference>;
699700
// Exports via `export * from "b"`
@@ -703,19 +704,19 @@ export interface ClassElements {
703704
// Things that have been exported via `export {A as B}`, where the target is not known
704705
exportedUnknowns: Record<string, string>;
705706
// Classes that have been declared in a file via `declare class A`
706-
declaredClasses: Record<string, ClassDeclaration>;
707+
declaredClasses: Record<string, TSESTree.ClassDeclaration>;
707708
// Interfaces that have been declared in a file via `declare interface A`
708-
declaredInterfaces: Record<string, TSInterfaceDeclaration>;
709+
declaredInterfaces: Record<string, TSESTree.TSInterfaceDeclaration>;
709710
// Types that have been declared in a file via `declare type A = ...`
710-
declaredTypes: Record<string, TSTypeAliasDeclaration>;
711+
declaredTypes: Record<string, TSESTree.TSTypeAliasDeclaration>;
711712
// Enums that have been declared in a file via `declare enum A {...}`
712-
declaredEnums: Record<string, TSEnumDeclaration>;
713+
declaredEnums: Record<string, TSESTree.TSEnumDeclaration>;
713714
// Namespaces that have been declared in a file via `declare namespace A { ... }`
714-
declaredNamespaces: Record<string, TSModuleDeclaration>;
715+
declaredNamespaces: Record<string, TSESTree.TSModuleDeclaration>;
715716
// Elements that are imported from elsewhere via `import {A} from ''`
716717
importedElements: Record<string, ClassReference>;
717718
// Elements that are imported from elsewhere via `import * as A from ''`
718719
importedElementsAllNamed: Record<string, { packageName: string; fileName: string; fileNameReferenced: string }>;
719720
// Element exported via `export = ...`
720-
exportAssignment: string | ClassDeclaration | undefined;
721+
exportAssignment: string | TSESTree.ClassDeclaration | undefined;
721722
}

lib/parse/CommentLoader.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { MethodDefinition, TSPropertySignature,
2-
TSIndexSignature, BaseNode } from '@typescript-eslint/types/dist/ts-estree';
1+
import type { TSESTree } from '@typescript-eslint/typescript-estree';
32
import * as commentParse from 'comment-parser';
43
import type { ClassReference, ClassReferenceLoaded } from './ClassIndex';
54
import type { ConstructorHolder } from './ConstructorLoader';
6-
75
import type { DefaultNested, DefaultValue, ParameterRangeUnresolved } from './ParameterLoader';
86

97
/**
@@ -48,7 +46,7 @@ export class CommentLoader {
4846
*/
4947
public getCommentDataFromConstructorSingle(
5048
classLoaded: ClassReferenceLoaded,
51-
constructor: MethodDefinition,
49+
constructor: TSESTree.MethodDefinition,
5250
): ConstructorCommentData {
5351
// Get the constructor comment
5452
const comment = this.getCommentRaw(classLoaded, constructor);
@@ -94,7 +92,7 @@ export class CommentLoader {
9492
*/
9593
public getCommentDataFromField(
9694
classLoaded: ClassReferenceLoaded,
97-
field: TSPropertySignature | TSIndexSignature,
95+
field: TSESTree.TSPropertySignature | TSESTree.TSIndexSignature,
9896
): CommentData {
9997
const comment = this.getCommentRaw(classLoaded, field);
10098
if (comment) {
@@ -227,7 +225,7 @@ export class CommentLoader {
227225
* @param classLoaded The loaded class in which the field is defined.
228226
* @param node A node, such as a field or constructor.
229227
*/
230-
public getCommentRaw(classLoaded: ClassReferenceLoaded, node: BaseNode): string | undefined {
228+
public getCommentRaw(classLoaded: ClassReferenceLoaded, node: TSESTree.BaseNode): string | undefined {
231229
const line = node.loc.start.line;
232230
for (const comment of classLoaded.ast.comments || []) {
233231
if (comment.loc.end.line === line - 1) {

lib/parse/ConstructorLoader.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ClassDeclaration, MethodDefinition } from '@typescript-eslint/types/dist/ts-estree';
2-
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
1+
import type { AST, TSESTreeOptions, TSESTree } from '@typescript-eslint/typescript-estree';
32
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
43
import type { ClassIndex, ClassLoaded, ClassReferenceLoaded, GenericallyTyped } from './ClassIndex';
54
import type { ParameterDataField, ParameterRangeUnresolved, ParameterLoader } from './ParameterLoader';
@@ -63,16 +62,14 @@ export class ConstructorLoader {
6362
*/
6463
public getConstructor(classLoaded: GenericallyTyped<ClassLoaded>): ConstructorHolder | undefined {
6564
// First look for the constructor in this class
66-
let constructor: MethodDefinition | undefined = this.getConstructorInClass(classLoaded.value.declaration);
65+
let constructor: TSESTree.MethodDefinition | undefined = this.getConstructorInClass(classLoaded.value.declaration);
6766

6867
// If no constructor was found, look in the super class
69-
if (!constructor) {
70-
if (classLoaded.value.superClass) {
71-
const constructorDataSuper = this.getConstructor(classLoaded.value.superClass);
72-
if (constructorDataSuper) {
73-
constructor = constructorDataSuper.constructor;
74-
classLoaded = constructorDataSuper.classLoaded;
75-
}
68+
if (!constructor && classLoaded.value.superClass) {
69+
const constructorDataSuper = this.getConstructor(classLoaded.value.superClass);
70+
if (constructorDataSuper) {
71+
constructor = constructorDataSuper.constructor;
72+
classLoaded = constructorDataSuper.classLoaded;
7673
}
7774
}
7875

@@ -83,7 +80,7 @@ export class ConstructorLoader {
8380
* Retrieve the constructor in the given class, or undefined if it could not be found.
8481
* @param declaration A class declaration
8582
*/
86-
public getConstructorInClass(declaration: ClassDeclaration): MethodDefinition | undefined {
83+
public getConstructorInClass(declaration: TSESTree.ClassDeclaration): TSESTree.MethodDefinition | undefined {
8784
for (const element of declaration.body.body) {
8885
if (element.type === AST_NODE_TYPES.MethodDefinition &&
8986
element.kind === 'constructor') {
@@ -99,7 +96,7 @@ export class ConstructorLoader {
9996
* @param ast A parsed typescript file
10097
* @param fileName The file name, for error reporting.
10198
*/
102-
public getClass(className: string, ast: AST<TSESTreeOptions>, fileName: string): ClassDeclaration {
99+
public getClass(className: string, ast: AST<TSESTreeOptions>, fileName: string): TSESTree.ClassDeclaration {
103100
for (const statement of ast.body) {
104101
// Classes in the form of `declare class A {}`
105102
if (statement.type === AST_NODE_TYPES.ClassDeclaration &&
@@ -136,6 +133,6 @@ export interface ConstructorData<R> {
136133
* Datastructure for holding a constructor and the class it is part of.
137134
*/
138135
export interface ConstructorHolder {
139-
constructor: MethodDefinition;
136+
constructor: TSESTree.MethodDefinition;
140137
classLoaded: GenericallyTyped<ClassLoaded>;
141138
}

lib/parse/MemberLoader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ export class MemberLoader {
4444
for (const element of classLoaded.declaration.body.body) {
4545
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
4646
switch (element.type) {
47-
case AST_NODE_TYPES.ClassProperty:
48-
case AST_NODE_TYPES.TSAbstractClassProperty:
47+
case AST_NODE_TYPES.PropertyDefinition:
48+
case AST_NODE_TYPES.TSAbstractPropertyDefinition:
4949
case AST_NODE_TYPES.MethodDefinition:
5050
case AST_NODE_TYPES.TSAbstractMethodDefinition:
5151
case AST_NODE_TYPES.TSPropertySignature:
5252
case AST_NODE_TYPES.TSMethodSignature:
5353
if (element.key.type === 'Identifier') {
5454
// TODO: more types may be needed here, such as AST_NODE_TYPES.TSPropertySignature
55-
const typeNode = element.type === AST_NODE_TYPES.ClassProperty ||
56-
element.type === AST_NODE_TYPES.TSAbstractClassProperty ?
55+
const typeNode = element.type === AST_NODE_TYPES.PropertyDefinition ||
56+
element.type === AST_NODE_TYPES.TSAbstractPropertyDefinition ?
5757
element.typeAnnotation?.typeAnnotation :
5858
undefined;
5959
members.push({

0 commit comments

Comments
 (0)