From 5f9ded7d69d840fa0d0fb522226272d9aff09cb4 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 26 Jun 2022 17:27:25 -0400 Subject: [PATCH 1/3] chore(utils)\!: remove (ts-)eslint-scope types --- packages/utils/src/index.ts | 3 +- .../utils/src/ts-eslint-scope/Definition.ts | 40 ---- packages/utils/src/ts-eslint-scope/Options.ts | 21 -- .../src/ts-eslint-scope/PatternVisitor.ts | 38 ---- packages/utils/src/ts-eslint-scope/README.md | 3 - .../utils/src/ts-eslint-scope/Reference.ts | 42 ---- .../utils/src/ts-eslint-scope/Referencer.ts | 81 -------- packages/utils/src/ts-eslint-scope/Scope.ts | 196 ------------------ .../utils/src/ts-eslint-scope/ScopeManager.ts | 61 ------ .../utils/src/ts-eslint-scope/Variable.ts | 22 -- packages/utils/src/ts-eslint-scope/analyze.ts | 21 -- packages/utils/src/ts-eslint-scope/index.ts | 13 -- 12 files changed, 1 insertion(+), 540 deletions(-) delete mode 100644 packages/utils/src/ts-eslint-scope/Definition.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Options.ts delete mode 100644 packages/utils/src/ts-eslint-scope/PatternVisitor.ts delete mode 100644 packages/utils/src/ts-eslint-scope/README.md delete mode 100644 packages/utils/src/ts-eslint-scope/Reference.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Referencer.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Scope.ts delete mode 100644 packages/utils/src/ts-eslint-scope/ScopeManager.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Variable.ts delete mode 100644 packages/utils/src/ts-eslint-scope/analyze.ts delete mode 100644 packages/utils/src/ts-eslint-scope/index.ts diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 31328386269a..c2c366379a0e 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -2,7 +2,6 @@ import * as ASTUtils from './ast-utils'; import * as ESLintUtils from './eslint-utils'; import * as JSONSchema from './json-schema'; import * as TSESLint from './ts-eslint'; -import * as TSESLintScope from './ts-eslint-scope'; -export { ASTUtils, ESLintUtils, JSONSchema, TSESLint, TSESLintScope }; +export { ASTUtils, ESLintUtils, JSONSchema, TSESLint }; export * from './ts-estree'; diff --git a/packages/utils/src/ts-eslint-scope/Definition.ts b/packages/utils/src/ts-eslint-scope/Definition.ts deleted file mode 100644 index 1999c4f4863e..000000000000 --- a/packages/utils/src/ts-eslint-scope/Definition.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - Definition as ESLintDefinition, - ParameterDefinition as ESLintParameterDefinition, -} from 'eslint-scope/lib/definition'; -import { TSESTree } from '../ts-estree'; - -interface Definition { - type: string; - name: TSESTree.BindingName; - node: TSESTree.Node; - parent?: TSESTree.Node | null; - index?: number | null; - kind?: string | null; - rest?: boolean; -} -interface DefinitionConstructor { - new ( - type: string, - name: TSESTree.BindingName | TSESTree.PropertyName, - node: TSESTree.Node, - parent?: TSESTree.Node | null, - index?: number | null, - kind?: string | null, - ): Definition; -} -const Definition = ESLintDefinition as DefinitionConstructor; - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -interface ParameterDefinition extends Definition {} -const ParameterDefinition = - ESLintParameterDefinition as DefinitionConstructor & { - new ( - name: TSESTree.Node, - node: TSESTree.Node, - index?: number | null, - rest?: boolean, - ): ParameterDefinition; - }; - -export { Definition, ParameterDefinition }; diff --git a/packages/utils/src/ts-eslint-scope/Options.ts b/packages/utils/src/ts-eslint-scope/Options.ts deleted file mode 100644 index a450e225b7fd..000000000000 --- a/packages/utils/src/ts-eslint-scope/Options.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { TSESTree } from '../ts-estree'; - -type PatternVisitorCallback = ( - pattern: TSESTree.Identifier, - info: { - rest: boolean; - topLevel: boolean; - assignments: TSESTree.AssignmentPattern[]; - }, -) => void; - -interface PatternVisitorOptions { - processRightHandNodes?: boolean; -} - -interface Visitor { - visitChildren(node?: T): void; - visit(node?: T): void; -} - -export { PatternVisitorCallback, PatternVisitorOptions, Visitor }; diff --git a/packages/utils/src/ts-eslint-scope/PatternVisitor.ts b/packages/utils/src/ts-eslint-scope/PatternVisitor.ts deleted file mode 100644 index 8563f6d934bb..000000000000 --- a/packages/utils/src/ts-eslint-scope/PatternVisitor.ts +++ /dev/null @@ -1,38 +0,0 @@ -import ESLintPatternVisitor from 'eslint-scope/lib/pattern-visitor'; -import { TSESTree } from '../ts-estree'; -import { ScopeManager } from './ScopeManager'; -import { - PatternVisitorCallback, - PatternVisitorOptions, - Visitor, -} from './Options'; - -interface PatternVisitor extends Visitor { - options: PatternVisitorOptions; - scopeManager: ScopeManager; - parent?: TSESTree.Node; - rightHandNodes: TSESTree.Node[]; - - Identifier(pattern: TSESTree.Node): void; - Property(property: TSESTree.Node): void; - ArrayPattern(pattern: TSESTree.Node): void; - AssignmentPattern(pattern: TSESTree.Node): void; - RestElement(pattern: TSESTree.Node): void; - MemberExpression(node: TSESTree.Node): void; - SpreadElement(node: TSESTree.Node): void; - ArrayExpression(node: TSESTree.Node): void; - AssignmentExpression(node: TSESTree.Node): void; - CallExpression(node: TSESTree.Node): void; -} -const PatternVisitor = ESLintPatternVisitor as { - new ( - options: PatternVisitorOptions, - rootPattern: TSESTree.BaseNode, - callback: PatternVisitorCallback, - ): PatternVisitor; - - // static methods - isPattern(node: TSESTree.Node): boolean; -}; - -export { PatternVisitor }; diff --git a/packages/utils/src/ts-eslint-scope/README.md b/packages/utils/src/ts-eslint-scope/README.md deleted file mode 100644 index 6cabba14fbff..000000000000 --- a/packages/utils/src/ts-eslint-scope/README.md +++ /dev/null @@ -1,3 +0,0 @@ -These will need to be removed in the next major as `eslint-scope` v6+ no longer export their internals. - -Issue: https://github.com/typescript-eslint/typescript-eslint/issues/4041 diff --git a/packages/utils/src/ts-eslint-scope/Reference.ts b/packages/utils/src/ts-eslint-scope/Reference.ts deleted file mode 100644 index 8d5c295f9107..000000000000 --- a/packages/utils/src/ts-eslint-scope/Reference.ts +++ /dev/null @@ -1,42 +0,0 @@ -import ESLintReference from 'eslint-scope/lib/reference'; -import { TSESTree } from '../ts-estree'; -import { Scope } from './Scope'; -import { Variable } from './Variable'; - -export type ReferenceFlag = 0x1 | 0x2 | 0x3; - -interface Reference { - identifier: TSESTree.Identifier; - from: Scope; - resolved: Variable | null; - writeExpr: TSESTree.Node | null; - init: boolean; - - partial: boolean; - __maybeImplicitGlobal: boolean; - tainted?: boolean; - typeMode?: boolean; - - isWrite(): boolean; - isRead(): boolean; - isWriteOnly(): boolean; - isReadOnly(): boolean; - isReadWrite(): boolean; -} -const Reference = ESLintReference as { - new ( - identifier: TSESTree.Identifier, - scope: Scope, - flag?: ReferenceFlag, - writeExpr?: TSESTree.Node | null, - maybeImplicitGlobal?: boolean, - partial?: boolean, - init?: boolean, - ): Reference; - - READ: 0x1; - WRITE: 0x2; - RW: 0x3; -}; - -export { Reference }; diff --git a/packages/utils/src/ts-eslint-scope/Referencer.ts b/packages/utils/src/ts-eslint-scope/Referencer.ts deleted file mode 100644 index 1d1180f21f83..000000000000 --- a/packages/utils/src/ts-eslint-scope/Referencer.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import ESLintReferencer from 'eslint-scope/lib/referencer'; -import { TSESTree } from '../ts-estree'; -import { - PatternVisitorCallback, - PatternVisitorOptions, - Visitor, -} from './Options'; -import { Scope } from './Scope'; -import { ScopeManager } from './ScopeManager'; - -interface Referencer extends Visitor { - isInnerMethodDefinition: boolean; - options: any; - scopeManager: SM; - parent?: TSESTree.Node; - - currentScope(): Scope; - close(node: TSESTree.Node): void; - pushInnerMethodDefinition(isInnerMethodDefinition: boolean): boolean; - popInnerMethodDefinition(isInnerMethodDefinition: boolean): void; - - referencingDefaultValue( - pattern: any, - assignments: any, - maybeImplicitGlobal: any, - init: boolean, - ): void; - visitPattern( - node: TSESTree.Node, - options: PatternVisitorOptions, - callback: PatternVisitorCallback, - ): void; - visitFunction(node: TSESTree.Node): void; - visitClass(node: TSESTree.Node): void; - visitProperty(node: TSESTree.Node): void; - visitForIn(node: TSESTree.Node): void; - visitVariableDeclaration( - variableTargetScope: any, - type: any, - node: TSESTree.Node, - index: any, - ): void; - - AssignmentExpression(node: TSESTree.Node): void; - CatchClause(node: TSESTree.Node): void; - Program(node: TSESTree.Program): void; - Identifier(node: TSESTree.Identifier): void; - UpdateExpression(node: TSESTree.Node): void; - MemberExpression(node: TSESTree.Node): void; - Property(node: TSESTree.Node): void; - MethodDefinition(node: TSESTree.Node): void; - BreakStatement(): void; - ContinueStatement(): void; - LabeledStatement(node: TSESTree.Node): void; - ForStatement(node: TSESTree.Node): void; - ClassExpression(node: TSESTree.Node): void; - ClassDeclaration(node: TSESTree.Node): void; - CallExpression(node: TSESTree.Node): void; - BlockStatement(node: TSESTree.Node): void; - ThisExpression(): void; - WithStatement(node: TSESTree.Node): void; - VariableDeclaration(node: TSESTree.Node): void; - SwitchStatement(node: TSESTree.Node): void; - FunctionDeclaration(node: TSESTree.Node): void; - FunctionExpression(node: TSESTree.Node): void; - ForOfStatement(node: TSESTree.Node): void; - ForInStatement(node: TSESTree.Node): void; - ArrowFunctionExpression(node: TSESTree.Node): void; - ImportDeclaration(node: TSESTree.Node): void; - visitExportDeclaration(node: TSESTree.Node): void; - ExportDeclaration(node: TSESTree.Node): void; - ExportNamedDeclaration(node: TSESTree.Node): void; - ExportSpecifier(node: TSESTree.Node): void; - MetaProperty(): void; -} -const Referencer = ESLintReferencer as { - new (options: any, scopeManager: SM): Referencer; -}; - -export { Referencer }; diff --git a/packages/utils/src/ts-eslint-scope/Scope.ts b/packages/utils/src/ts-eslint-scope/Scope.ts deleted file mode 100644 index 9b2c711d2dc2..000000000000 --- a/packages/utils/src/ts-eslint-scope/Scope.ts +++ /dev/null @@ -1,196 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ - -import { - Scope as ESLintScope, - GlobalScope as ESLintGlobalScope, - ModuleScope as ESLintModuleScope, - FunctionExpressionNameScope as ESLintFunctionExpressionNameScope, - CatchScope as ESLintCatchScope, - WithScope as ESLintWithScope, - BlockScope as ESLintBlockScope, - SwitchScope as ESLintSwitchScope, - FunctionScope as ESLintFunctionScope, - ForScope as ESLintForScope, - ClassScope as ESLintClassScope, -} from 'eslint-scope/lib/scope'; -import { TSESTree } from '../ts-estree'; -import { Definition } from './Definition'; -import { Reference, ReferenceFlag } from './Reference'; -import { ScopeManager } from './ScopeManager'; -import { Variable } from './Variable'; - -type ScopeType = - | 'block' - | 'catch' - | 'class' - | 'for' - | 'function' - | 'function-expression-name' - | 'global' - | 'module' - | 'switch' - | 'with' - | 'TDZ' - | 'enum' - | 'empty-function'; - -interface Scope { - type: ScopeType; - isStrict: boolean; - upper: Scope | null; - childScopes: Scope[]; - variableScope: Scope; - block: TSESTree.Node; - variables: Variable[]; - set: Map; - references: Reference[]; - through: Reference[]; - thisFound?: boolean; - taints: Map; - functionExpressionScope: boolean; - __left: Reference[]; - - __shouldStaticallyClose(scopeManager: ScopeManager): boolean; - __shouldStaticallyCloseForGlobal(ref: any): boolean; - __staticCloseRef(ref: any): void; - __dynamicCloseRef(ref: any): void; - __globalCloseRef(ref: any): void; - __close(scopeManager: ScopeManager): Scope; - __isValidResolution(ref: any, variable: any): variable is Variable; - __resolve(ref: Reference): boolean; - __delegateToUpperScope(ref: any): void; - __addDeclaredVariablesOfNode(variable: any, node: TSESTree.Node): void; - __defineGeneric( - name: string, - set: Map, - variables: Variable[], - node: TSESTree.Identifier, - def: Definition, - ): void; - - __define(node: TSESTree.Node, def: Definition): void; - - __referencing( - node: TSESTree.Node, - assign?: ReferenceFlag, - writeExpr?: TSESTree.Node, - maybeImplicitGlobal?: any, - partial?: any, - init?: any, - ): void; - - __detectEval(): void; - __detectThis(): void; - __isClosed(): boolean; - /** - * returns resolved {Reference} - * @method Scope#resolve - * @param {Espree.Identifier} ident - identifier to be resolved. - * @returns {Reference} reference - */ - resolve(ident: TSESTree.Node): Reference; - - /** - * returns this scope is static - * @method Scope#isStatic - * @returns {boolean} static - */ - isStatic(): boolean; - - /** - * returns this scope has materialized arguments - * @method Scope#isArgumentsMaterialized - * @returns {boolean} arguments materialized - */ - isArgumentsMaterialized(): boolean; - - /** - * returns this scope has materialized `this` reference - * @method Scope#isThisMaterialized - * @returns {boolean} this materialized - */ - isThisMaterialized(): boolean; - - isUsedName(name: any): boolean; -} -interface ScopeConstructor { - new ( - scopeManager: ScopeManager, - type: ScopeType, - upperScope: Scope | null, - block: TSESTree.Node | null, - isMethodDefinition: boolean, - ): Scope; -} -const Scope = ESLintScope as ScopeConstructor; - -interface ScopeChildConstructorWithUpperScope { - new ( - scopeManager: ScopeManager, - upperScope: Scope, - block: TSESTree.Node | null, - ): T; -} - -interface GlobalScope extends Scope {} -const GlobalScope = ESLintGlobalScope as ScopeConstructor & { - new (scopeManager: ScopeManager, block: TSESTree.Node | null): GlobalScope; -}; - -interface ModuleScope extends Scope {} -const ModuleScope = ESLintModuleScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface FunctionExpressionNameScope extends Scope {} -const FunctionExpressionNameScope = - ESLintFunctionExpressionNameScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface CatchScope extends Scope {} -const CatchScope = ESLintCatchScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface WithScope extends Scope {} -const WithScope = ESLintWithScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface BlockScope extends Scope {} -const BlockScope = ESLintBlockScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface SwitchScope extends Scope {} -const SwitchScope = ESLintSwitchScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface FunctionScope extends Scope {} -const FunctionScope = ESLintFunctionScope as ScopeConstructor & { - new ( - scopeManager: ScopeManager, - upperScope: Scope, - block: TSESTree.Node | null, - isMethodDefinition: boolean, - ): FunctionScope; -}; - -interface ForScope extends Scope {} -const ForScope = ESLintForScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface ClassScope extends Scope {} -const ClassScope = ESLintClassScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -export { - ScopeType, - Scope, - GlobalScope, - ModuleScope, - FunctionExpressionNameScope, - CatchScope, - WithScope, - BlockScope, - SwitchScope, - FunctionScope, - ForScope, - ClassScope, -}; diff --git a/packages/utils/src/ts-eslint-scope/ScopeManager.ts b/packages/utils/src/ts-eslint-scope/ScopeManager.ts deleted file mode 100644 index 9f971d797646..000000000000 --- a/packages/utils/src/ts-eslint-scope/ScopeManager.ts +++ /dev/null @@ -1,61 +0,0 @@ -import ESLintScopeManager from 'eslint-scope/lib/scope-manager'; -import { TSESTree } from '../ts-estree'; -import { EcmaVersion } from '../ts-eslint'; -import { Scope } from './Scope'; -import { Variable } from './Variable'; - -interface ScopeManagerOptions { - directive?: boolean; - optimistic?: boolean; - ignoreEval?: boolean; - nodejsScope?: boolean; - sourceType?: 'module' | 'script'; - impliedStrict?: boolean; - ecmaVersion?: EcmaVersion; -} - -interface ScopeManager { - __options: ScopeManagerOptions; - __currentScope: Scope; - __nodeToScope: WeakMap; - __declaredVariables: WeakMap; - - scopes: Scope[]; - globalScope: Scope; - - __useDirective(): boolean; - __isOptimistic(): boolean; - __ignoreEval(): boolean; - __isNodejsScope(): boolean; - isModule(): boolean; - isImpliedStrict(): boolean; - isStrictModeSupported(): boolean; - - // Returns appropriate scope for this node. - __get(node: TSESTree.Node): Scope | undefined; - getDeclaredVariables(node: TSESTree.Node): Variable[]; - acquire(node: TSESTree.Node, inner?: boolean): Scope | null; - acquireAll(node: TSESTree.Node): Scope | null; - release(node: TSESTree.Node, inner?: boolean): Scope | null; - attach(): void; - detach(): void; - - __nestScope(scope: T): T; - __nestGlobalScope(node: TSESTree.Node): Scope; - __nestBlockScope(node: TSESTree.Node): Scope; - __nestFunctionScope(node: TSESTree.Node, isMethodDefinition: boolean): Scope; - __nestForScope(node: TSESTree.Node): Scope; - __nestCatchScope(node: TSESTree.Node): Scope; - __nestWithScope(node: TSESTree.Node): Scope; - __nestClassScope(node: TSESTree.Node): Scope; - __nestSwitchScope(node: TSESTree.Node): Scope; - __nestModuleScope(node: TSESTree.Node): Scope; - __nestFunctionExpressionNameScope(node: TSESTree.Node): Scope; - - __isES6(): boolean; -} -const ScopeManager = ESLintScopeManager as { - new (options: ScopeManagerOptions): ScopeManager; -}; - -export { ScopeManager, ScopeManagerOptions }; diff --git a/packages/utils/src/ts-eslint-scope/Variable.ts b/packages/utils/src/ts-eslint-scope/Variable.ts deleted file mode 100644 index c9ff75f95d54..000000000000 --- a/packages/utils/src/ts-eslint-scope/Variable.ts +++ /dev/null @@ -1,22 +0,0 @@ -import ESLintVariable from 'eslint-scope/lib/variable'; -import { TSESTree } from '../ts-estree'; -import { Reference } from './Reference'; -import { Definition } from './Definition'; -import { Scope } from './Scope'; - -interface Variable { - name: string; - identifiers: TSESTree.Identifier[]; - references: Reference[]; - defs: Definition[]; - eslintUsed?: boolean; - stack?: unknown; - tainted?: boolean; - scope?: Scope; -} - -const Variable = ESLintVariable as { - new (): Variable; -}; - -export { Variable }; diff --git a/packages/utils/src/ts-eslint-scope/analyze.ts b/packages/utils/src/ts-eslint-scope/analyze.ts deleted file mode 100644 index 51d69ba8cbec..000000000000 --- a/packages/utils/src/ts-eslint-scope/analyze.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { analyze as ESLintAnalyze } from 'eslint-scope'; -import { EcmaVersion } from '../ts-eslint'; -import { TSESTree } from '../ts-estree'; -import { ScopeManager } from './ScopeManager'; - -interface AnalysisOptions { - optimistic?: boolean; - directive?: boolean; - ignoreEval?: boolean; - nodejsScope?: boolean; - impliedStrict?: boolean; - fallback?: string | ((node: TSESTree.Node) => string[]); - sourceType?: 'script' | 'module'; - ecmaVersion?: EcmaVersion; -} -const analyze = ESLintAnalyze as ( - ast: TSESTree.Node, - options?: AnalysisOptions, -) => ScopeManager; - -export { analyze, AnalysisOptions }; diff --git a/packages/utils/src/ts-eslint-scope/index.ts b/packages/utils/src/ts-eslint-scope/index.ts deleted file mode 100644 index 870c34fce1bb..000000000000 --- a/packages/utils/src/ts-eslint-scope/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { version as ESLintVersion } from 'eslint-scope'; - -export * from './analyze'; -export * from './Definition'; -export * from './Options'; -export * from './PatternVisitor'; -export * from './Reference'; -export * from './Referencer'; -export * from './Scope'; -export * from './ScopeManager'; -export * from './Variable'; - -export const version: string = ESLintVersion; From cbb306beaa5d50736f194d815975e8771f100c5a Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 26 Oct 2022 10:25:43 -0400 Subject: [PATCH 2/3] Remove eslint-scope dep --- packages/utils/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/utils/package.json b/packages/utils/package.json index 66bc99ae8e97..267a86b4c7fb 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -43,7 +43,6 @@ "@typescript-eslint/scope-manager": "5.29.0", "@typescript-eslint/types": "5.29.0", "@typescript-eslint/typescript-estree": "5.29.0", - "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, "peerDependencies": { From bf185b21b86b8b9ef983490031102d1f8700f617 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 26 Oct 2022 10:26:55 -0400 Subject: [PATCH 3/3] More file deletions --- .../utils/src/ts-eslint-scope/Definition.ts | 41 ---- packages/utils/src/ts-eslint-scope/Options.ts | 21 -- .../src/ts-eslint-scope/PatternVisitor.ts | 39 ---- .../utils/src/ts-eslint-scope/Reference.ts | 43 ---- .../utils/src/ts-eslint-scope/Referencer.ts | 82 -------- packages/utils/src/ts-eslint-scope/Scope.ts | 197 ------------------ .../utils/src/ts-eslint-scope/ScopeManager.ts | 62 ------ .../utils/src/ts-eslint-scope/Variable.ts | 23 -- packages/utils/src/ts-eslint-scope/analyze.ts | 22 -- 9 files changed, 530 deletions(-) delete mode 100644 packages/utils/src/ts-eslint-scope/Definition.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Options.ts delete mode 100644 packages/utils/src/ts-eslint-scope/PatternVisitor.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Reference.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Referencer.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Scope.ts delete mode 100644 packages/utils/src/ts-eslint-scope/ScopeManager.ts delete mode 100644 packages/utils/src/ts-eslint-scope/Variable.ts delete mode 100644 packages/utils/src/ts-eslint-scope/analyze.ts diff --git a/packages/utils/src/ts-eslint-scope/Definition.ts b/packages/utils/src/ts-eslint-scope/Definition.ts deleted file mode 100644 index 3e35ecc9fc25..000000000000 --- a/packages/utils/src/ts-eslint-scope/Definition.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - Definition as ESLintDefinition, - ParameterDefinition as ESLintParameterDefinition, -} from 'eslint-scope/lib/definition'; - -import type { TSESTree } from '../ts-estree'; - -interface Definition { - type: string; - name: TSESTree.BindingName; - node: TSESTree.Node; - parent?: TSESTree.Node | null; - index?: number | null; - kind?: string | null; - rest?: boolean; -} -interface DefinitionConstructor { - new ( - type: string, - name: TSESTree.BindingName | TSESTree.PropertyName, - node: TSESTree.Node, - parent?: TSESTree.Node | null, - index?: number | null, - kind?: string | null, - ): Definition; -} -const Definition = ESLintDefinition as DefinitionConstructor; - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -interface ParameterDefinition extends Definition {} -const ParameterDefinition = - ESLintParameterDefinition as DefinitionConstructor & { - new ( - name: TSESTree.Node, - node: TSESTree.Node, - index?: number | null, - rest?: boolean, - ): ParameterDefinition; - }; - -export { Definition, ParameterDefinition }; diff --git a/packages/utils/src/ts-eslint-scope/Options.ts b/packages/utils/src/ts-eslint-scope/Options.ts deleted file mode 100644 index 0b1600ae1cbc..000000000000 --- a/packages/utils/src/ts-eslint-scope/Options.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { TSESTree } from '../ts-estree'; - -type PatternVisitorCallback = ( - pattern: TSESTree.Identifier, - info: { - rest: boolean; - topLevel: boolean; - assignments: TSESTree.AssignmentPattern[]; - }, -) => void; - -interface PatternVisitorOptions { - processRightHandNodes?: boolean; -} - -interface Visitor { - visitChildren(node?: T): void; - visit(node?: T): void; -} - -export { PatternVisitorCallback, PatternVisitorOptions, Visitor }; diff --git a/packages/utils/src/ts-eslint-scope/PatternVisitor.ts b/packages/utils/src/ts-eslint-scope/PatternVisitor.ts deleted file mode 100644 index 75840211e28b..000000000000 --- a/packages/utils/src/ts-eslint-scope/PatternVisitor.ts +++ /dev/null @@ -1,39 +0,0 @@ -import ESLintPatternVisitor from 'eslint-scope/lib/pattern-visitor'; - -import type { TSESTree } from '../ts-estree'; -import type { - PatternVisitorCallback, - PatternVisitorOptions, - Visitor, -} from './Options'; -import type { ScopeManager } from './ScopeManager'; - -interface PatternVisitor extends Visitor { - options: PatternVisitorOptions; - scopeManager: ScopeManager; - parent?: TSESTree.Node; - rightHandNodes: TSESTree.Node[]; - - Identifier(pattern: TSESTree.Node): void; - Property(property: TSESTree.Node): void; - ArrayPattern(pattern: TSESTree.Node): void; - AssignmentPattern(pattern: TSESTree.Node): void; - RestElement(pattern: TSESTree.Node): void; - MemberExpression(node: TSESTree.Node): void; - SpreadElement(node: TSESTree.Node): void; - ArrayExpression(node: TSESTree.Node): void; - AssignmentExpression(node: TSESTree.Node): void; - CallExpression(node: TSESTree.Node): void; -} -const PatternVisitor = ESLintPatternVisitor as { - new ( - options: PatternVisitorOptions, - rootPattern: TSESTree.BaseNode, - callback: PatternVisitorCallback, - ): PatternVisitor; - - // static methods - isPattern(node: TSESTree.Node): boolean; -}; - -export { PatternVisitor }; diff --git a/packages/utils/src/ts-eslint-scope/Reference.ts b/packages/utils/src/ts-eslint-scope/Reference.ts deleted file mode 100644 index d2dd6554977b..000000000000 --- a/packages/utils/src/ts-eslint-scope/Reference.ts +++ /dev/null @@ -1,43 +0,0 @@ -import ESLintReference from 'eslint-scope/lib/reference'; - -import type { TSESTree } from '../ts-estree'; -import type { Scope } from './Scope'; -import type { Variable } from './Variable'; - -export type ReferenceFlag = 0x1 | 0x2 | 0x3; - -interface Reference { - identifier: TSESTree.Identifier; - from: Scope; - resolved: Variable | null; - writeExpr: TSESTree.Node | null; - init: boolean; - - partial: boolean; - __maybeImplicitGlobal: boolean; - tainted?: boolean; - typeMode?: boolean; - - isWrite(): boolean; - isRead(): boolean; - isWriteOnly(): boolean; - isReadOnly(): boolean; - isReadWrite(): boolean; -} -const Reference = ESLintReference as { - new ( - identifier: TSESTree.Identifier, - scope: Scope, - flag?: ReferenceFlag, - writeExpr?: TSESTree.Node | null, - maybeImplicitGlobal?: boolean, - partial?: boolean, - init?: boolean, - ): Reference; - - READ: 0x1; - WRITE: 0x2; - RW: 0x3; -}; - -export { Reference }; diff --git a/packages/utils/src/ts-eslint-scope/Referencer.ts b/packages/utils/src/ts-eslint-scope/Referencer.ts deleted file mode 100644 index 3bd6b27b20d5..000000000000 --- a/packages/utils/src/ts-eslint-scope/Referencer.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import ESLintReferencer from 'eslint-scope/lib/referencer'; - -import type { TSESTree } from '../ts-estree'; -import type { - PatternVisitorCallback, - PatternVisitorOptions, - Visitor, -} from './Options'; -import type { Scope } from './Scope'; -import type { ScopeManager } from './ScopeManager'; - -interface Referencer extends Visitor { - isInnerMethodDefinition: boolean; - options: any; - scopeManager: SM; - parent?: TSESTree.Node; - - currentScope(): Scope; - close(node: TSESTree.Node): void; - pushInnerMethodDefinition(isInnerMethodDefinition: boolean): boolean; - popInnerMethodDefinition(isInnerMethodDefinition: boolean): void; - - referencingDefaultValue( - pattern: any, - assignments: any, - maybeImplicitGlobal: any, - init: boolean, - ): void; - visitPattern( - node: TSESTree.Node, - options: PatternVisitorOptions, - callback: PatternVisitorCallback, - ): void; - visitFunction(node: TSESTree.Node): void; - visitClass(node: TSESTree.Node): void; - visitProperty(node: TSESTree.Node): void; - visitForIn(node: TSESTree.Node): void; - visitVariableDeclaration( - variableTargetScope: any, - type: any, - node: TSESTree.Node, - index: any, - ): void; - - AssignmentExpression(node: TSESTree.Node): void; - CatchClause(node: TSESTree.Node): void; - Program(node: TSESTree.Program): void; - Identifier(node: TSESTree.Identifier): void; - UpdateExpression(node: TSESTree.Node): void; - MemberExpression(node: TSESTree.Node): void; - Property(node: TSESTree.Node): void; - MethodDefinition(node: TSESTree.Node): void; - BreakStatement(): void; - ContinueStatement(): void; - LabeledStatement(node: TSESTree.Node): void; - ForStatement(node: TSESTree.Node): void; - ClassExpression(node: TSESTree.Node): void; - ClassDeclaration(node: TSESTree.Node): void; - CallExpression(node: TSESTree.Node): void; - BlockStatement(node: TSESTree.Node): void; - ThisExpression(): void; - WithStatement(node: TSESTree.Node): void; - VariableDeclaration(node: TSESTree.Node): void; - SwitchStatement(node: TSESTree.Node): void; - FunctionDeclaration(node: TSESTree.Node): void; - FunctionExpression(node: TSESTree.Node): void; - ForOfStatement(node: TSESTree.Node): void; - ForInStatement(node: TSESTree.Node): void; - ArrowFunctionExpression(node: TSESTree.Node): void; - ImportDeclaration(node: TSESTree.Node): void; - visitExportDeclaration(node: TSESTree.Node): void; - ExportDeclaration(node: TSESTree.Node): void; - ExportNamedDeclaration(node: TSESTree.Node): void; - ExportSpecifier(node: TSESTree.Node): void; - MetaProperty(): void; -} -const Referencer = ESLintReferencer as { - new (options: any, scopeManager: SM): Referencer; -}; - -export { Referencer }; diff --git a/packages/utils/src/ts-eslint-scope/Scope.ts b/packages/utils/src/ts-eslint-scope/Scope.ts deleted file mode 100644 index e0f3320043a0..000000000000 --- a/packages/utils/src/ts-eslint-scope/Scope.ts +++ /dev/null @@ -1,197 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ - -import { - BlockScope as ESLintBlockScope, - CatchScope as ESLintCatchScope, - ClassScope as ESLintClassScope, - ForScope as ESLintForScope, - FunctionExpressionNameScope as ESLintFunctionExpressionNameScope, - FunctionScope as ESLintFunctionScope, - GlobalScope as ESLintGlobalScope, - ModuleScope as ESLintModuleScope, - Scope as ESLintScope, - SwitchScope as ESLintSwitchScope, - WithScope as ESLintWithScope, -} from 'eslint-scope/lib/scope'; - -import type { TSESTree } from '../ts-estree'; -import type { Definition } from './Definition'; -import type { Reference, ReferenceFlag } from './Reference'; -import type { ScopeManager } from './ScopeManager'; -import type { Variable } from './Variable'; - -type ScopeType = - | 'block' - | 'catch' - | 'class' - | 'for' - | 'function' - | 'function-expression-name' - | 'global' - | 'module' - | 'switch' - | 'with' - | 'TDZ' - | 'enum' - | 'empty-function'; - -interface Scope { - type: ScopeType; - isStrict: boolean; - upper: Scope | null; - childScopes: Scope[]; - variableScope: Scope; - block: TSESTree.Node; - variables: Variable[]; - set: Map; - references: Reference[]; - through: Reference[]; - thisFound?: boolean; - taints: Map; - functionExpressionScope: boolean; - __left: Reference[]; - - __shouldStaticallyClose(scopeManager: ScopeManager): boolean; - __shouldStaticallyCloseForGlobal(ref: any): boolean; - __staticCloseRef(ref: any): void; - __dynamicCloseRef(ref: any): void; - __globalCloseRef(ref: any): void; - __close(scopeManager: ScopeManager): Scope; - __isValidResolution(ref: any, variable: any): variable is Variable; - __resolve(ref: Reference): boolean; - __delegateToUpperScope(ref: any): void; - __addDeclaredVariablesOfNode(variable: any, node: TSESTree.Node): void; - __defineGeneric( - name: string, - set: Map, - variables: Variable[], - node: TSESTree.Identifier, - def: Definition, - ): void; - - __define(node: TSESTree.Node, def: Definition): void; - - __referencing( - node: TSESTree.Node, - assign?: ReferenceFlag, - writeExpr?: TSESTree.Node, - maybeImplicitGlobal?: any, - partial?: any, - init?: any, - ): void; - - __detectEval(): void; - __detectThis(): void; - __isClosed(): boolean; - /** - * returns resolved {Reference} - * @method Scope#resolve - * @param {Espree.Identifier} ident - identifier to be resolved. - * @returns {Reference} reference - */ - resolve(ident: TSESTree.Node): Reference; - - /** - * returns this scope is static - * @method Scope#isStatic - * @returns {boolean} static - */ - isStatic(): boolean; - - /** - * returns this scope has materialized arguments - * @method Scope#isArgumentsMaterialized - * @returns {boolean} arguments materialized - */ - isArgumentsMaterialized(): boolean; - - /** - * returns this scope has materialized `this` reference - * @method Scope#isThisMaterialized - * @returns {boolean} this materialized - */ - isThisMaterialized(): boolean; - - isUsedName(name: any): boolean; -} -interface ScopeConstructor { - new ( - scopeManager: ScopeManager, - type: ScopeType, - upperScope: Scope | null, - block: TSESTree.Node | null, - isMethodDefinition: boolean, - ): Scope; -} -const Scope = ESLintScope as ScopeConstructor; - -interface ScopeChildConstructorWithUpperScope { - new ( - scopeManager: ScopeManager, - upperScope: Scope, - block: TSESTree.Node | null, - ): T; -} - -interface GlobalScope extends Scope {} -const GlobalScope = ESLintGlobalScope as ScopeConstructor & { - new (scopeManager: ScopeManager, block: TSESTree.Node | null): GlobalScope; -}; - -interface ModuleScope extends Scope {} -const ModuleScope = ESLintModuleScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface FunctionExpressionNameScope extends Scope {} -const FunctionExpressionNameScope = - ESLintFunctionExpressionNameScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface CatchScope extends Scope {} -const CatchScope = ESLintCatchScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface WithScope extends Scope {} -const WithScope = ESLintWithScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface BlockScope extends Scope {} -const BlockScope = ESLintBlockScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface SwitchScope extends Scope {} -const SwitchScope = ESLintSwitchScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface FunctionScope extends Scope {} -const FunctionScope = ESLintFunctionScope as ScopeConstructor & { - new ( - scopeManager: ScopeManager, - upperScope: Scope, - block: TSESTree.Node | null, - isMethodDefinition: boolean, - ): FunctionScope; -}; - -interface ForScope extends Scope {} -const ForScope = ESLintForScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -interface ClassScope extends Scope {} -const ClassScope = ESLintClassScope as ScopeConstructor & - ScopeChildConstructorWithUpperScope; - -export { - ScopeType, - Scope, - GlobalScope, - ModuleScope, - FunctionExpressionNameScope, - CatchScope, - WithScope, - BlockScope, - SwitchScope, - FunctionScope, - ForScope, - ClassScope, -}; diff --git a/packages/utils/src/ts-eslint-scope/ScopeManager.ts b/packages/utils/src/ts-eslint-scope/ScopeManager.ts deleted file mode 100644 index c7bbb2425c9b..000000000000 --- a/packages/utils/src/ts-eslint-scope/ScopeManager.ts +++ /dev/null @@ -1,62 +0,0 @@ -import ESLintScopeManager from 'eslint-scope/lib/scope-manager'; - -import type { EcmaVersion } from '../ts-eslint'; -import type { TSESTree } from '../ts-estree'; -import type { Scope } from './Scope'; -import type { Variable } from './Variable'; - -interface ScopeManagerOptions { - directive?: boolean; - optimistic?: boolean; - ignoreEval?: boolean; - nodejsScope?: boolean; - sourceType?: 'module' | 'script'; - impliedStrict?: boolean; - ecmaVersion?: EcmaVersion; -} - -interface ScopeManager { - __options: ScopeManagerOptions; - __currentScope: Scope; - __nodeToScope: WeakMap; - __declaredVariables: WeakMap; - - scopes: Scope[]; - globalScope: Scope; - - __useDirective(): boolean; - __isOptimistic(): boolean; - __ignoreEval(): boolean; - __isNodejsScope(): boolean; - isModule(): boolean; - isImpliedStrict(): boolean; - isStrictModeSupported(): boolean; - - // Returns appropriate scope for this node. - __get(node: TSESTree.Node): Scope | undefined; - getDeclaredVariables(node: TSESTree.Node): Variable[]; - acquire(node: TSESTree.Node, inner?: boolean): Scope | null; - acquireAll(node: TSESTree.Node): Scope | null; - release(node: TSESTree.Node, inner?: boolean): Scope | null; - attach(): void; - detach(): void; - - __nestScope(scope: T): T; - __nestGlobalScope(node: TSESTree.Node): Scope; - __nestBlockScope(node: TSESTree.Node): Scope; - __nestFunctionScope(node: TSESTree.Node, isMethodDefinition: boolean): Scope; - __nestForScope(node: TSESTree.Node): Scope; - __nestCatchScope(node: TSESTree.Node): Scope; - __nestWithScope(node: TSESTree.Node): Scope; - __nestClassScope(node: TSESTree.Node): Scope; - __nestSwitchScope(node: TSESTree.Node): Scope; - __nestModuleScope(node: TSESTree.Node): Scope; - __nestFunctionExpressionNameScope(node: TSESTree.Node): Scope; - - __isES6(): boolean; -} -const ScopeManager = ESLintScopeManager as { - new (options: ScopeManagerOptions): ScopeManager; -}; - -export { ScopeManager, ScopeManagerOptions }; diff --git a/packages/utils/src/ts-eslint-scope/Variable.ts b/packages/utils/src/ts-eslint-scope/Variable.ts deleted file mode 100644 index 192c9f895507..000000000000 --- a/packages/utils/src/ts-eslint-scope/Variable.ts +++ /dev/null @@ -1,23 +0,0 @@ -import ESLintVariable from 'eslint-scope/lib/variable'; - -import type { TSESTree } from '../ts-estree'; -import type { Definition } from './Definition'; -import type { Reference } from './Reference'; -import type { Scope } from './Scope'; - -interface Variable { - name: string; - identifiers: TSESTree.Identifier[]; - references: Reference[]; - defs: Definition[]; - eslintUsed?: boolean; - stack?: unknown; - tainted?: boolean; - scope?: Scope; -} - -const Variable = ESLintVariable as { - new (): Variable; -}; - -export { Variable }; diff --git a/packages/utils/src/ts-eslint-scope/analyze.ts b/packages/utils/src/ts-eslint-scope/analyze.ts deleted file mode 100644 index 1543f93fa1a3..000000000000 --- a/packages/utils/src/ts-eslint-scope/analyze.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { analyze as ESLintAnalyze } from 'eslint-scope'; - -import type { EcmaVersion } from '../ts-eslint'; -import type { TSESTree } from '../ts-estree'; -import type { ScopeManager } from './ScopeManager'; - -interface AnalysisOptions { - optimistic?: boolean; - directive?: boolean; - ignoreEval?: boolean; - nodejsScope?: boolean; - impliedStrict?: boolean; - fallback?: string | ((node: TSESTree.Node) => string[]); - sourceType?: 'script' | 'module'; - ecmaVersion?: EcmaVersion; -} -const analyze = ESLintAnalyze as ( - ast: TSESTree.Node, - options?: AnalysisOptions, -) => ScopeManager; - -export { analyze, AnalysisOptions };