Skip to content

Commit

Permalink
chore(repo): enable consistent-type-imports for typescript files (#…
Browse files Browse the repository at this point in the history
…1325)

* refactor: distinguish between types of import

* add consistent-type-import into the eslint config

* fix: change the import method of non compliant rules
  • Loading branch information
jerry-lllman authored Nov 27, 2022
1 parent fd93b71 commit a2e582a
Show file tree
Hide file tree
Showing 72 changed files with 153 additions and 135 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
'sort-keys': 'off',
'typescript-sort-keys/interface': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off'
'import/no-unresolved': 'off',
'@typescript-eslint/consistent-type-imports': 'error'
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/alias/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

import type { ResolvedAlias, ResolverFunction, ResolverObject, RollupAliasOptions } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/alias/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, PluginHooks } from 'rollup';
import type { Plugin, PluginHooks } from 'rollup';

type MapToFunction<T> = T extends Function ? T : never;

Expand Down
2 changes: 1 addition & 1 deletion packages/auto-install/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mod from 'module';
import { exec } from 'child_process';
import { promisify } from 'util';

import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

import type { RollupAutoInstallOptions } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/auto-install/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export interface RollupAutoInstallOptions {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/babel/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** eslint-disable @typescript-eslint/no-unused-vars */
import type { RollupOptions } from 'rollup';

import babelPlugin, {
babel,
Expand All @@ -8,7 +9,7 @@ import babelPlugin, {
createBabelOutputPluginFactory
} from '../types';

const rollupConfig: import('rollup').RollupOptions = {
const rollupConfig: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
Expand Down
6 changes: 3 additions & 3 deletions packages/babel/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Plugin, PluginContext, TransformPluginContext } from 'rollup';
import { FilterPattern, CreateFilter } from '@rollup/pluginutils';
import * as babelCore from '@babel/core';
import type { Plugin, PluginContext, TransformPluginContext } from 'rollup';
import type { FilterPattern, CreateFilter } from '@rollup/pluginutils';
import type * as babelCore from '@babel/core';

export interface RollupBabelInputPluginOptions
extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {
Expand Down
2 changes: 1 addition & 1 deletion packages/beep/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

/**
* 🍣 A Rollup plugin that beeps when a build ends with errors.
Expand Down
2 changes: 1 addition & 1 deletion packages/buble/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transform } from 'buble';
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';

import type { RollupBubleOptions } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/buble/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import buble from '..';

Expand Down
6 changes: 3 additions & 3 deletions packages/buble/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FilterPattern } from '@rollup/pluginutils';
import { TransformOptions } from 'buble';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { TransformOptions } from 'buble';
import type { Plugin } from 'rollup';

export interface RollupBubleOptions extends TransformOptions {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/commonjs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

type RequireReturnsDefaultOption = boolean | 'auto' | 'preferred' | 'namespace';
type DefaultIsModuleExportsOption = boolean | 'auto';
Expand Down
2 changes: 1 addition & 1 deletion packages/data-uri/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'url';

import { Plugin, RollupError } from 'rollup';
import type { Plugin, RollupError } from 'rollup';

import { dataToEsm } from '@rollup/pluginutils';

Expand Down
2 changes: 1 addition & 1 deletion packages/data-uri/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

/**
* A Rollup plugin which imports modules from Data URIs.
Expand Down
2 changes: 1 addition & 1 deletion packages/dsv/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import dsv from '..';

Expand Down
6 changes: 3 additions & 3 deletions packages/dsv/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DSVRowString } from 'd3-dsv';
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { DSVRowString } from 'd3-dsv';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

interface RollupDsvOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamic-import-vars/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import dynamicImportVars, { dynamicImportToGlob } from '../src';

Expand Down
10 changes: 4 additions & 6 deletions packages/dynamic-import-vars/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';
import type { BaseNode } from 'estree';

interface RollupDynamicImportVariablesOptions {
/**
Expand All @@ -24,10 +25,7 @@ interface RollupDynamicImportVariablesOptions {

export class VariableDynamicImportError extends Error {}

export function dynamicImportToGlob(
node: import('estree').BaseNode,
sourceString: string
): null | string;
export function dynamicImportToGlob(node: BaseNode, sourceString: string): null | string;

/**
* Support variables in dynamic imports in Rollup.
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { relative, resolve, sep } from 'path';

import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';
import { ESLint } from 'eslint';

Expand Down
6 changes: 3 additions & 3 deletions packages/eslint/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Plugin } from 'rollup';
import { CLIEngine, ESLint } from 'eslint';
import { CreateFilter } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';
import type { CLIEngine, ESLint } from 'eslint';
import type { CreateFilter } from '@rollup/pluginutils';

export interface RollupEslintOptions extends ESLint.Options {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import graphql from '..';

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

export interface RollupGraphqlOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/html/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extname } from 'path';

import { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup';
import type { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup';

import type { RollupHtmlOptions, RollupHtmlTemplateOptions } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/html/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';
import type { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';

export interface RollupHtmlTemplateOptions {
title: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/image/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import image from '..';

Expand Down
4 changes: 2 additions & 2 deletions packages/image/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

interface RollupImageOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/inject/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import inject from '..';

Expand Down
2 changes: 1 addition & 1 deletion packages/inject/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

type Injectment = string | [string, string];

Expand Down
2 changes: 1 addition & 1 deletion packages/json/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import json from '..';

Expand Down
4 changes: 2 additions & 2 deletions packages/json/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

export interface RollupJsonOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import legacy from '..';

Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

interface RollupLegacyOptions {
[key: string]: string | { [key: string]: string };
Expand Down
2 changes: 1 addition & 1 deletion packages/multi-entry/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import multiEntry from '..';

Expand Down
4 changes: 2 additions & 2 deletions packages/multi-entry/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

interface RollupMultiEntryOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/node-resolve/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export const DEFAULTS: {
customResolveOptions: {};
Expand Down
2 changes: 1 addition & 1 deletion packages/pluginutils/src/attachScopes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as estree from 'estree';
import type * as estree from 'estree';

import { walk } from 'estree-walker';

Expand Down
18 changes: 13 additions & 5 deletions packages/pluginutils/src/extractAssignedNames.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import type {
ArrayPattern,
AssignmentPattern,
Identifier,
ObjectPattern,
RestElement
} from 'estree';

import type { ExtractAssignedNames } from '../types';

interface Extractors {
[key: string]: (names: string[], param: any) => void;
}

const extractors: Extractors = {
ArrayPattern(names: string[], param: import('estree').ArrayPattern) {
ArrayPattern(names: string[], param: ArrayPattern) {
for (const element of param.elements) {
if (element) extractors[element.type](names, element);
}
},

AssignmentPattern(names: string[], param: import('estree').AssignmentPattern) {
AssignmentPattern(names: string[], param: AssignmentPattern) {
extractors[param.left.type](names, param.left);
},

Identifier(names: string[], param: import('estree').Identifier) {
Identifier(names: string[], param: Identifier) {
names.push(param.name);
},

MemberExpression() {},

ObjectPattern(names: string[], param: import('estree').ObjectPattern) {
ObjectPattern(names: string[], param: ObjectPattern) {
for (const prop of param.properties) {
// @ts-ignore Typescript reports that this is not a valid type
if (prop.type === 'RestElement') {
Expand All @@ -32,7 +40,7 @@ const extractors: Extractors = {
}
},

RestElement(names: string[], param: import('estree').RestElement) {
RestElement(names: string[], param: RestElement) {
extractors[param.argument.type](names, param.argument);
}
};
Expand Down
5 changes: 3 additions & 2 deletions packages/pluginutils/test/attachScopes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as estree from 'estree';
import type * as estree from 'estree';

import test from 'ava';
import { parse } from 'acorn';

import { attachScopes, AttachedScope } from '../';
import type { AttachedScope } from '../';
import { attachScopes } from '../';

test('attaches a scope to the top level', (t) => {
const ast = parse('var foo;', { ecmaVersion: 2020, sourceType: 'module' });
Expand Down
2 changes: 1 addition & 1 deletion packages/pluginutils/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseNode } from 'estree';
import type { BaseNode } from 'estree';

export interface AttachedScope {
parent?: AttachedScope;
Expand Down
2 changes: 1 addition & 1 deletion packages/replace/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { dirname } from 'path';

import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import replace from '..';

Expand Down
4 changes: 2 additions & 2 deletions packages/replace/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

type Replacement = string | ((id: string) => string);

Expand Down
5 changes: 3 additions & 2 deletions packages/run/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChildProcess, fork } from 'child_process';
import type { ChildProcess } from 'child_process';
import { fork } from 'child_process';
import { resolve, join, dirname } from 'path';

import { Plugin, RenderedChunk } from 'rollup';
import type { Plugin, RenderedChunk } from 'rollup';

import type { RollupRunOptions } from '../types';

Expand Down
4 changes: 2 additions & 2 deletions packages/run/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ForkOptions } from 'child_process';
import type { ForkOptions } from 'child_process';

import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export interface RollupRunOptions extends ForkOptions {
args?: readonly string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/strip/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from 'rollup';
import type { RollupOptions } from 'rollup';

import strip from '../types/index';

Expand Down
4 changes: 2 additions & 2 deletions packages/strip/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';

interface RollupStripOptions {
/**
Expand Down
Loading

0 comments on commit a2e582a

Please sign in to comment.