From eec95740ca7680a6bd4ac5900b1a91d655449eaa Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 2 Sep 2022 16:16:00 +0800 Subject: [PATCH] chore: add eslint rule `consistent-type-imports` (#14901) --- .eslintrc.cjs | 4 ++++ packages/babel-core/src/config/full.ts | 2 +- packages/babel-core/src/config/helpers/config-api.ts | 2 +- packages/babel-core/src/config/validation/options.ts | 2 +- packages/babel-core/src/transformation/file/file.ts | 4 ++-- packages/babel-parser/src/index.ts | 2 +- packages/babel-parser/src/parser/expression.ts | 2 +- packages/babel-parser/src/parser/lval.ts | 2 +- packages/babel-parser/src/parser/statement.ts | 5 +++-- packages/babel-parser/src/parser/util.ts | 2 +- packages/babel-parser/src/plugins/estree.ts | 2 +- packages/babel-parser/src/plugins/flow/index.ts | 4 ++-- packages/babel-parser/src/plugins/flow/scope.ts | 4 ++-- packages/babel-parser/src/plugins/jsx/index.ts | 5 +++-- packages/babel-parser/src/plugins/placeholders.ts | 2 +- packages/babel-parser/src/plugins/typescript/index.ts | 5 +++-- packages/babel-parser/src/plugins/typescript/scope.ts | 4 ++-- packages/babel-parser/src/plugins/v8intrinsic.ts | 2 +- packages/babel-parser/src/tokenizer/index.ts | 2 +- packages/babel-parser/src/tokenizer/state.ts | 5 +++-- packages/babel-parser/src/util/class-scope.ts | 4 ++-- packages/babel-parser/src/util/expression-scope.ts | 4 ++-- packages/babel-parser/src/util/scope.ts | 6 +++--- packages/babel-plugin-transform-spread/src/index.ts | 3 ++- packages/babel-preset-env/src/types.ts | 2 +- packages/babel-standalone/src/transformScriptTags.ts | 2 +- packages/babel-traverse/scripts/generators/asserts.js | 4 ++-- packages/babel-traverse/src/path/ancestry.ts | 2 +- packages/babel-traverse/src/path/generated/asserts.ts | 4 ++-- packages/babel-traverse/src/path/lib/removal-hooks.ts | 2 +- packages/babel-traverse/src/path/removal.ts | 3 ++- packages/babel-traverse/src/scope/lib/renamer.ts | 2 +- packages/babel-traverse/src/types.ts | 2 +- 33 files changed, 56 insertions(+), 46 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 03b2f74382d6..783fad4ae651 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -44,6 +44,10 @@ module.exports = { "no-undef": "off", "no-redeclare": "off", "@babel/development-internal/disallow-ts-ignore": "error", + "@typescript-eslint/consistent-type-imports": [ + "error", + { disallowTypeAnnotations: false }, + ], }, }, { diff --git a/packages/babel-core/src/config/full.ts b/packages/babel-core/src/config/full.ts index e431fb72ebd7..30b31e1376d5 100644 --- a/packages/babel-core/src/config/full.ts +++ b/packages/babel-core/src/config/full.ts @@ -29,7 +29,7 @@ import type { PluginAPI, PresetAPI } from "./helpers/config-api"; import loadPrivatePartialConfig from "./partial"; import type { ValidatedOptions } from "./validation/options"; -import * as Context from "./cache-contexts"; +import type * as Context from "./cache-contexts"; import ConfigError from "../errors/config-error"; type LoadedDescriptor = { diff --git a/packages/babel-core/src/config/helpers/config-api.ts b/packages/babel-core/src/config/helpers/config-api.ts index 724fdc431873..567ee2ca7485 100644 --- a/packages/babel-core/src/config/helpers/config-api.ts +++ b/packages/babel-core/src/config/helpers/config-api.ts @@ -11,7 +11,7 @@ import type { import type { AssumptionName, CallerMetadata } from "../validation/options"; -import * as Context from "../cache-contexts"; +import type * as Context from "../cache-contexts"; type EnvFunction = { (): string; diff --git a/packages/babel-core/src/config/validation/options.ts b/packages/babel-core/src/config/validation/options.ts index 0d96c0b15d20..0895188b0f61 100644 --- a/packages/babel-core/src/config/validation/options.ts +++ b/packages/babel-core/src/config/validation/options.ts @@ -1,7 +1,7 @@ import type { InputTargets, Targets } from "@babel/helper-compilation-targets"; import type { ConfigItem } from "../item"; -import Plugin from "../plugin"; +import type Plugin from "../plugin"; import removed from "./removed"; import { diff --git a/packages/babel-core/src/transformation/file/file.ts b/packages/babel-core/src/transformation/file/file.ts index ad3a5524718c..2badd1d14a8e 100644 --- a/packages/babel-core/src/transformation/file/file.ts +++ b/packages/babel-core/src/transformation/file/file.ts @@ -1,6 +1,6 @@ import * as helpers from "@babel/helpers"; -import { NodePath, Scope } from "@babel/traverse"; -import type { HubInterface, Visitor } from "@babel/traverse"; +import { NodePath } from "@babel/traverse"; +import type { HubInterface, Visitor, Scope } from "@babel/traverse"; import { codeFrameColumns } from "@babel/code-frame"; import traverse from "@babel/traverse"; import { cloneNode, interpreterDirective } from "@babel/types"; diff --git a/packages/babel-parser/src/index.ts b/packages/babel-parser/src/index.ts index 286d7ff04621..4c81655b7758 100644 --- a/packages/babel-parser/src/index.ts +++ b/packages/babel-parser/src/index.ts @@ -14,8 +14,8 @@ import type { } from "./typings"; import Parser from "./parser"; +import type { ExportedTokenType } from "./tokenizer/types"; import { - ExportedTokenType, getExportedToken, tt as internalTokenTypes, type InternalTokenTypes, diff --git a/packages/babel-parser/src/parser/expression.ts b/packages/babel-parser/src/parser/expression.ts index 13ea7160dfa0..adc926d3e46a 100644 --- a/packages/babel-parser/src/parser/expression.ts +++ b/packages/babel-parser/src/parser/expression.ts @@ -32,7 +32,7 @@ import { tt, type TokenType, } from "../tokenizer/types"; -import * as N from "../types"; +import type * as N from "../types"; import LValParser from "./lval"; import { isKeyword, diff --git a/packages/babel-parser/src/parser/lval.ts b/packages/babel-parser/src/parser/lval.ts index d030d6cc726b..dc26e1eab708 100644 --- a/packages/babel-parser/src/parser/lval.ts +++ b/packages/babel-parser/src/parser/lval.ts @@ -31,7 +31,7 @@ import { BIND_NONE, BIND_SCOPE_LEXICAL, } from "../util/scopeflags"; -import { ExpressionErrors } from "./util"; +import type { ExpressionErrors } from "./util"; import { Errors, type LValAncestor } from "../parse-error"; import type Parser from "./index"; diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts index 552b634c77a6..284afe45e911 100644 --- a/packages/babel-parser/src/parser/statement.ts +++ b/packages/babel-parser/src/parser/statement.ts @@ -1,4 +1,4 @@ -import * as N from "../types"; +import type * as N from "../types"; import { tokenIsIdentifier, tokenIsLoop, @@ -38,7 +38,8 @@ import { } from "../util/expression-scope"; import type { SourceType } from "../options"; import { Token } from "../tokenizer"; -import { Position, createPositionWithColumnOffset } from "../util/location"; +import type { Position } from "../util/location"; +import { createPositionWithColumnOffset } from "../util/location"; import { cloneStringLiteral, cloneIdentifier, type Undone } from "./node"; import type Parser from "./index"; diff --git a/packages/babel-parser/src/parser/util.ts b/packages/babel-parser/src/parser/util.ts index b78ccacaf466..36177ec17963 100644 --- a/packages/babel-parser/src/parser/util.ts +++ b/packages/babel-parser/src/parser/util.ts @@ -5,7 +5,7 @@ import { type TokenType, } from "../tokenizer/types"; import Tokenizer from "../tokenizer"; -import State from "../tokenizer/state"; +import type State from "../tokenizer/state"; import type { EstreePropertyDefinition, Node, ObjectProperty } from "../types"; import { lineBreak, skipWhiteSpaceToLineBreak } from "../util/whitespace"; import { isIdentifierChar } from "../util/identifier"; diff --git a/packages/babel-parser/src/plugins/estree.ts b/packages/babel-parser/src/plugins/estree.ts index 94ed4f143e31..4192f21ad77c 100644 --- a/packages/babel-parser/src/plugins/estree.ts +++ b/packages/babel-parser/src/plugins/estree.ts @@ -1,7 +1,7 @@ import { type TokenType } from "../tokenizer/types"; import type Parser from "../parser"; import type { ExpressionErrors } from "../parser/util"; -import * as N from "../types"; +import type * as N from "../types"; import type { Node as NodeType, NodeBase, File } from "../types"; import type { Position } from "../util/location"; import { Errors } from "../parse-error"; diff --git a/packages/babel-parser/src/plugins/flow/index.ts b/packages/babel-parser/src/plugins/flow/index.ts index 6114a7a0e1a3..54d84153ac23 100644 --- a/packages/babel-parser/src/plugins/flow/index.ts +++ b/packages/babel-parser/src/plugins/flow/index.ts @@ -11,8 +11,8 @@ import { type TokenType, tokenIsFlowInterfaceOrTypeOrOpaque, } from "../../tokenizer/types"; -import * as N from "../../types"; -import { Position } from "../../util/location"; +import type * as N from "../../types"; +import type { Position } from "../../util/location"; import { types as tc } from "../../tokenizer/context"; import * as charCodes from "charcodes"; import { isIteratorStart } from "../../util/identifier"; diff --git a/packages/babel-parser/src/plugins/flow/scope.ts b/packages/babel-parser/src/plugins/flow/scope.ts index b628761041bd..894ab871b2b3 100644 --- a/packages/babel-parser/src/plugins/flow/scope.ts +++ b/packages/babel-parser/src/plugins/flow/scope.ts @@ -1,11 +1,11 @@ -import { Position } from "../../util/location"; +import type { Position } from "../../util/location"; import ScopeHandler, { Scope } from "../../util/scope"; import { BIND_FLAGS_FLOW_DECLARE_FN, type ScopeFlags, type BindingTypes, } from "../../util/scopeflags"; -import * as N from "../../types"; +import type * as N from "../../types"; // Reference implementation: https://github.com/facebook/flow/blob/23aeb2a2ef6eb4241ce178fde5d8f17c5f747fb5/src/typing/env.ml#L536-L584 class FlowScope extends Scope { diff --git a/packages/babel-parser/src/plugins/jsx/index.ts b/packages/babel-parser/src/plugins/jsx/index.ts index 60991e05c5ea..02c25c556507 100644 --- a/packages/babel-parser/src/plugins/jsx/index.ts +++ b/packages/babel-parser/src/plugins/jsx/index.ts @@ -10,8 +10,9 @@ import { type TokenType, tt, } from "../../tokenizer/types"; -import { TokContext, types as tc } from "../../tokenizer/context"; -import * as N from "../../types"; +import type { TokContext } from "../../tokenizer/context"; +import { types as tc } from "../../tokenizer/context"; +import type * as N from "../../types"; import { isIdentifierChar, isIdentifierStart } from "../../util/identifier"; import type { Position } from "../../util/location"; import { isNewLine } from "../../util/whitespace"; diff --git a/packages/babel-parser/src/plugins/placeholders.ts b/packages/babel-parser/src/plugins/placeholders.ts index dbe7cdca9660..da7eff69d135 100644 --- a/packages/babel-parser/src/plugins/placeholders.ts +++ b/packages/babel-parser/src/plugins/placeholders.ts @@ -2,7 +2,7 @@ import * as charCodes from "charcodes"; import { tokenLabelName, tt } from "../tokenizer/types"; import type Parser from "../parser"; -import * as N from "../types"; +import type * as N from "../types"; import { ParseErrorEnum } from "../parse-error"; import type { Undone } from "../parser/node"; import type { ExpressionErrors } from "../parser/util"; diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index 1c9b801cefff..35c5e40e11ff 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -13,8 +13,9 @@ import { tokenCanStartExpression, } from "../../tokenizer/types"; import { types as tc } from "../../tokenizer/context"; -import * as N from "../../types"; -import { Position, createPositionWithColumnOffset } from "../../util/location"; +import type * as N from "../../types"; +import type { Position } from "../../util/location"; +import { createPositionWithColumnOffset } from "../../util/location"; import type Parser from "../../parser"; import { type BindingTypes, diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index 113b410ac402..fa390603c38c 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -1,4 +1,4 @@ -import { Position } from "../../util/location"; +import type { Position } from "../../util/location"; import ScopeHandler, { Scope } from "../../util/scope"; import { BIND_KIND_TYPE, @@ -10,7 +10,7 @@ import { type ScopeFlags, type BindingTypes, } from "../../util/scopeflags"; -import * as N from "../../types"; +import type * as N from "../../types"; class TypeScriptScope extends Scope { types: Set = new Set(); diff --git a/packages/babel-parser/src/plugins/v8intrinsic.ts b/packages/babel-parser/src/plugins/v8intrinsic.ts index 4722b0bd6eff..4c657cd09a90 100644 --- a/packages/babel-parser/src/plugins/v8intrinsic.ts +++ b/packages/babel-parser/src/plugins/v8intrinsic.ts @@ -1,6 +1,6 @@ import type Parser from "../parser"; import { tokenIsIdentifier, tt } from "../tokenizer/types"; -import * as N from "../types"; +import type * as N from "../types"; import type { ExpressionErrors } from "../parser/util"; export default (superClass: typeof Parser) => diff --git a/packages/babel-parser/src/tokenizer/index.ts b/packages/babel-parser/src/tokenizer/index.ts index fadbc99e2b22..51f4f988955c 100644 --- a/packages/babel-parser/src/tokenizer/index.ts +++ b/packages/babel-parser/src/tokenizer/index.ts @@ -7,7 +7,7 @@ import { createPositionWithColumnOffset, } from "../util/location"; import CommentsParser, { type CommentWhitespace } from "../parser/comments"; -import * as N from "../types"; +import type * as N from "../types"; import * as charCodes from "charcodes"; import { isIdentifierStart, isIdentifierChar } from "../util/identifier"; import { diff --git a/packages/babel-parser/src/tokenizer/state.ts b/packages/babel-parser/src/tokenizer/state.ts index 2888ac2f88eb..c160d1d5190a 100644 --- a/packages/babel-parser/src/tokenizer/state.ts +++ b/packages/babel-parser/src/tokenizer/state.ts @@ -1,11 +1,12 @@ import type { Options } from "../options"; -import * as N from "../types"; +import type * as N from "../types"; import type { CommentWhitespace } from "../parser/comments"; import { Position } from "../util/location"; import { types as ct, type TokContext } from "./context"; import { tt, type TokenType } from "./types"; -import { Errors, type ParseError } from "../parse-error"; +import type { Errors } from "../parse-error"; +import { type ParseError } from "../parse-error"; export type DeferredStrictError = | typeof Errors.StrictNumericEscape diff --git a/packages/babel-parser/src/util/class-scope.ts b/packages/babel-parser/src/util/class-scope.ts index ce3dabfc0ab0..a3c852ff2a19 100644 --- a/packages/babel-parser/src/util/class-scope.ts +++ b/packages/babel-parser/src/util/class-scope.ts @@ -3,9 +3,9 @@ import { CLASS_ELEMENT_FLAG_STATIC, type ClassElementTypes, } from "./scopeflags"; -import { Position } from "./location"; +import type { Position } from "./location"; import { Errors } from "../parse-error"; -import Tokenizer from "../tokenizer"; +import type Tokenizer from "../tokenizer"; export class ClassScope { // A list of private named declared in the current class diff --git a/packages/babel-parser/src/util/expression-scope.ts b/packages/babel-parser/src/util/expression-scope.ts index a54355189c7d..95200c425703 100644 --- a/packages/babel-parser/src/util/expression-scope.ts +++ b/packages/babel-parser/src/util/expression-scope.ts @@ -1,7 +1,7 @@ import { Errors, type ParseErrorConstructor } from "../parse-error"; -import { Position } from "./location"; +import type { Position } from "./location"; import type { Node } from "../types"; -import Tokenizer from "../tokenizer"; +import type Tokenizer from "../tokenizer"; /** * @module util/expression-scope diff --git a/packages/babel-parser/src/util/scope.ts b/packages/babel-parser/src/util/scope.ts index 786e0abfc39a..27f4d5bb000b 100644 --- a/packages/babel-parser/src/util/scope.ts +++ b/packages/babel-parser/src/util/scope.ts @@ -15,10 +15,10 @@ import { type ScopeFlags, type BindingTypes, } from "./scopeflags"; -import { Position } from "./location"; -import * as N from "../types"; +import type { Position } from "./location"; +import type * as N from "../types"; import { Errors } from "../parse-error"; -import Tokenizer from "../tokenizer"; +import type Tokenizer from "../tokenizer"; // Start an AST node, attaching a start offset. export class Scope { diff --git a/packages/babel-plugin-transform-spread/src/index.ts b/packages/babel-plugin-transform-spread/src/index.ts index f54259325c54..8de86d35fab7 100644 --- a/packages/babel-plugin-transform-spread/src/index.ts +++ b/packages/babel-plugin-transform-spread/src/index.ts @@ -1,6 +1,7 @@ import { declare } from "@babel/helper-plugin-utils"; import { skipTransparentExprWrappers } from "@babel/helper-skip-transparent-expression-wrappers"; -import { types as t, File } from "@babel/core"; +import type { File } from "@babel/core"; +import { types as t } from "@babel/core"; import type { NodePath, Scope } from "@babel/traverse"; type ListElement = t.SpreadElement | t.Expression; diff --git a/packages/babel-preset-env/src/types.ts b/packages/babel-preset-env/src/types.ts index cdee1f246907..e0fb50ec4979 100644 --- a/packages/babel-preset-env/src/types.ts +++ b/packages/babel-preset-env/src/types.ts @@ -1,4 +1,4 @@ -import { ModulesOption, UseBuiltInsOption } from "./options"; +import type { ModulesOption, UseBuiltInsOption } from "./options"; import type { NormalizedCorejsOption } from "./normalize-options"; import type { Targets, InputTargets } from "@babel/helper-compilation-targets"; diff --git a/packages/babel-standalone/src/transformScriptTags.ts b/packages/babel-standalone/src/transformScriptTags.ts index 58dcbf469ff9..48294afd0fe4 100644 --- a/packages/babel-standalone/src/transformScriptTags.ts +++ b/packages/babel-standalone/src/transformScriptTags.ts @@ -8,7 +8,7 @@ const scriptTypes = ["text/jsx", "text/babel"]; -import { transform } from "./index"; +import type { transform } from "./index"; import type { InputOptions } from "@babel/core"; let headEl: HTMLHeadElement; diff --git a/packages/babel-traverse/scripts/generators/asserts.js b/packages/babel-traverse/scripts/generators/asserts.js index 20bb24c632a2..80dad30368e1 100644 --- a/packages/babel-traverse/scripts/generators/asserts.js +++ b/packages/babel-traverse/scripts/generators/asserts.js @@ -5,8 +5,8 @@ export default function generateAsserts() { * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ -import * as t from "@babel/types"; -import NodePath from "../index"; +import type * as t from "@babel/types"; +import type NodePath from "../index"; export interface NodePathAssetions {`; diff --git a/packages/babel-traverse/src/path/ancestry.ts b/packages/babel-traverse/src/path/ancestry.ts index 742a49d2cf39..70cba8264473 100644 --- a/packages/babel-traverse/src/path/ancestry.ts +++ b/packages/babel-traverse/src/path/ancestry.ts @@ -2,7 +2,7 @@ import { VISITOR_KEYS } from "@babel/types"; import type * as t from "@babel/types"; -import NodePath from "./index"; +import type NodePath from "./index"; /** * Starting at the parent path of the current `NodePath` and going up the diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index fa863227ec9a..8f58d171740d 100644 --- a/packages/babel-traverse/src/path/generated/asserts.ts +++ b/packages/babel-traverse/src/path/generated/asserts.ts @@ -2,8 +2,8 @@ * This file is auto-generated! Do not modify it directly. * To re-generate run 'make build' */ -import * as t from "@babel/types"; -import NodePath from "../index"; +import type * as t from "@babel/types"; +import type NodePath from "../index"; export interface NodePathAssetions { assertAccessor(opts?: object): asserts this is NodePath; diff --git a/packages/babel-traverse/src/path/lib/removal-hooks.ts b/packages/babel-traverse/src/path/lib/removal-hooks.ts index 105fb9cfea2f..ed3c1c3d7d1c 100644 --- a/packages/babel-traverse/src/path/lib/removal-hooks.ts +++ b/packages/babel-traverse/src/path/lib/removal-hooks.ts @@ -1,6 +1,6 @@ // this file contains hooks that handle ancestry cleanup of parent nodes when removing children -import NodePath from ".."; +import type NodePath from ".."; import type * as t from "@babel/types"; /** * Pre hooks should be used for either rejecting removal or delegating removal diff --git a/packages/babel-traverse/src/path/removal.ts b/packages/babel-traverse/src/path/removal.ts index b4366f767674..e1a6abef9b04 100644 --- a/packages/babel-traverse/src/path/removal.ts +++ b/packages/babel-traverse/src/path/removal.ts @@ -2,7 +2,8 @@ import { hooks } from "./lib/removal-hooks"; import { path as pathCache } from "../cache"; -import NodePath, { REMOVED, SHOULD_SKIP } from "./index"; +import type NodePath from "./index"; +import { REMOVED, SHOULD_SKIP } from "./index"; export function remove(this: NodePath) { this._assertUnremoved(); diff --git a/packages/babel-traverse/src/scope/lib/renamer.ts b/packages/babel-traverse/src/scope/lib/renamer.ts index d81e71b419b6..c3ba79706d01 100644 --- a/packages/babel-traverse/src/scope/lib/renamer.ts +++ b/packages/babel-traverse/src/scope/lib/renamer.ts @@ -1,4 +1,4 @@ -import Binding from "../binding"; +import type Binding from "../binding"; import splitExportDeclaration from "@babel/helper-split-export-declaration"; import * as t from "@babel/types"; import type { NodePath, Visitor } from "../.."; diff --git a/packages/babel-traverse/src/types.ts b/packages/babel-traverse/src/types.ts index 58e3353409a3..b4ae4259341a 100644 --- a/packages/babel-traverse/src/types.ts +++ b/packages/babel-traverse/src/types.ts @@ -1,5 +1,5 @@ import type * as t from "@babel/types"; -import { NodePath } from "./index"; +import type { NodePath } from "./index"; import type { VirtualTypeAliases } from "./path/lib/virtual-types"; export type Visitor = VisitNodeObject & {