Skip to content

Commit

Permalink
chore: add eslint rule consistent-type-imports (#14901)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Sep 2, 2022
1 parent b50d889 commit eec9574
Show file tree
Hide file tree
Showing 33 changed files with 56 additions and 46 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Expand Up @@ -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 },
],
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/full.ts
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/helpers/config-api.ts
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion 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 {
Expand Down
4 changes: 2 additions & 2 deletions 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";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/index.ts
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.ts
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/lval.ts
Expand Up @@ -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";

Expand Down
5 changes: 3 additions & 2 deletions 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,
Expand Down Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/util.ts
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions 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 {
Expand Down
5 changes: 3 additions & 2 deletions packages/babel-parser/src/plugins/jsx/index.ts
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/placeholders.ts
Expand Up @@ -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";
Expand Down
5 changes: 3 additions & 2 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions 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,
Expand All @@ -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<string> = new Set();
Expand Down
2 changes: 1 addition & 1 deletion 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) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/tokenizer/index.ts
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions 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
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/util/class-scope.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-parser/src/util/scope.ts
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion 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;
Expand Down
2 changes: 1 addition & 1 deletion 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";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-standalone/src/transformScriptTags.ts
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/scripts/generators/asserts.js
Expand Up @@ -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 {`;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/path/ancestry.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/src/path/generated/asserts.ts
Expand Up @@ -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<t.Accessor>;
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-traverse/src/path/removal.ts
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion 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 "../..";
Expand Down
2 changes: 1 addition & 1 deletion 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<S = {}> = VisitNodeObject<S, t.Node> & {
Expand Down

0 comments on commit eec9574

Please sign in to comment.