From 4c87b2486a9c90794d972a4d093c1dc22ffb418b Mon Sep 17 00:00:00 2001 From: Armano Date: Mon, 15 Nov 2021 08:36:25 +0100 Subject: [PATCH] fix: correct issues with circular imports (#4140) --- .../eslint-plugin/src/rules/no-restricted-imports.ts | 2 +- .../eslint-plugin/src/util/collectUnusedVariables.ts | 11 ++++++----- packages/eslint-plugin/src/util/isTypeReadonly.ts | 3 ++- .../scope-manager/src/referencer/PatternVisitor.ts | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-restricted-imports.ts b/packages/eslint-plugin/src/rules/no-restricted-imports.ts index d7437cab76b..2429795240e 100644 --- a/packages/eslint-plugin/src/rules/no-restricted-imports.ts +++ b/packages/eslint-plugin/src/rules/no-restricted-imports.ts @@ -1,5 +1,5 @@ import { TSESTree } from '@typescript-eslint/experimental-utils'; -import { +import type { ArrayOfStringOrObject, ArrayOfStringOrObjectPatterns, } from 'eslint/lib/rules/no-restricted-imports'; diff --git a/packages/eslint-plugin/src/util/collectUnusedVariables.ts b/packages/eslint-plugin/src/util/collectUnusedVariables.ts index a1cfac27232..f62d7588753 100644 --- a/packages/eslint-plugin/src/util/collectUnusedVariables.ts +++ b/packages/eslint-plugin/src/util/collectUnusedVariables.ts @@ -1,11 +1,12 @@ import { AST_NODE_TYPES, TSESLint, + ASTUtils, TSESTree, } from '@typescript-eslint/experimental-utils'; import { ImplicitLibVariable } from '@typescript-eslint/scope-manager'; import { Visitor } from '@typescript-eslint/scope-manager/dist/referencer/Visitor'; -import * as util from '.'; +import { nullThrows } from './nullThrows'; class UnusedVarsVisitor< TMessageIds extends string, @@ -24,7 +25,7 @@ class UnusedVarsVisitor< visitChildrenEvenIfSelectorExists: true, }); - this.#scopeManager = util.nullThrows( + this.#scopeManager = nullThrows( context.getSourceCode().scopeManager, 'Missing required scope manager', ); @@ -545,11 +546,11 @@ function isUsedVariable(variable: TSESLint.Scope.Variable): boolean { function isInLoop(node: TSESTree.Node): boolean { let currentNode: TSESTree.Node | undefined = node; while (currentNode) { - if (util.isFunction(currentNode)) { + if (ASTUtils.isFunction(currentNode)) { break; } - if (util.isLoop(currentNode)) { + if (ASTUtils.isLoop(currentNode)) { return true; } @@ -620,7 +621,7 @@ function isUsedVariable(variable: TSESLint.Scope.Variable): boolean { function getUpperFunction(node: TSESTree.Node): TSESTree.Node | null { let currentNode: TSESTree.Node | undefined = node; while (currentNode) { - if (util.isFunction(currentNode)) { + if (ASTUtils.isFunction(currentNode)) { return currentNode; } currentNode = currentNode.parent; diff --git a/packages/eslint-plugin/src/util/isTypeReadonly.ts b/packages/eslint-plugin/src/util/isTypeReadonly.ts index 8231455c294..efb6966d676 100644 --- a/packages/eslint-plugin/src/util/isTypeReadonly.ts +++ b/packages/eslint-plugin/src/util/isTypeReadonly.ts @@ -7,7 +7,8 @@ import { isSymbolFlagSet, } from 'tsutils'; import * as ts from 'typescript'; -import { getTypeOfPropertyOfType, nullThrows, NullThrowsReasons } from '.'; +import { nullThrows, NullThrowsReasons } from './nullThrows'; +import { getTypeOfPropertyOfType } from './propertyTypes'; const enum Readonlyness { /** the type cannot be handled by the function */ diff --git a/packages/scope-manager/src/referencer/PatternVisitor.ts b/packages/scope-manager/src/referencer/PatternVisitor.ts index eaca842cbd5..eb34103457d 100644 --- a/packages/scope-manager/src/referencer/PatternVisitor.ts +++ b/packages/scope-manager/src/referencer/PatternVisitor.ts @@ -1,5 +1,5 @@ import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types'; -import { VisitorBase, VisitorOptions } from './Visitor'; +import { VisitorBase, VisitorOptions } from './VisitorBase'; type PatternVisitorCallback = ( pattern: TSESTree.Identifier,