Skip to content

Commit a2e582a

Browse files
authored
chore(repo): enable consistent-type-imports for typescript files (#1325)
* refactor: distinguish between types of import * add consistent-type-import into the eslint config * fix: change the import method of non compliant rules
1 parent fd93b71 commit a2e582a

File tree

72 files changed

+153
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+153
-135
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
'sort-keys': 'off',
1010
'typescript-sort-keys/interface': 'off',
1111
'import/extensions': 'off',
12-
'import/no-unresolved': 'off'
12+
'import/no-unresolved': 'off',
13+
'@typescript-eslint/consistent-type-imports': 'error'
1314
},
1415
overrides: [
1516
{

packages/alias/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

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

packages/alias/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, PluginHooks } from 'rollup';
1+
import type { Plugin, PluginHooks } from 'rollup';
22

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

packages/auto-install/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mod from 'module';
44
import { exec } from 'child_process';
55
import { promisify } from 'util';
66

7-
import { Plugin } from 'rollup';
7+
import type { Plugin } from 'rollup';
88

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

packages/auto-install/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
export interface RollupAutoInstallOptions {
44
/**

packages/babel/test/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** eslint-disable @typescript-eslint/no-unused-vars */
2+
import type { RollupOptions } from 'rollup';
23

34
import babelPlugin, {
45
babel,
@@ -8,7 +9,7 @@ import babelPlugin, {
89
createBabelOutputPluginFactory
910
} from '../types';
1011

11-
const rollupConfig: import('rollup').RollupOptions = {
12+
const rollupConfig: RollupOptions = {
1213
input: 'main.js',
1314
output: {
1415
file: 'bundle.js',

packages/babel/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Plugin, PluginContext, TransformPluginContext } from 'rollup';
2-
import { FilterPattern, CreateFilter } from '@rollup/pluginutils';
3-
import * as babelCore from '@babel/core';
1+
import type { Plugin, PluginContext, TransformPluginContext } from 'rollup';
2+
import type { FilterPattern, CreateFilter } from '@rollup/pluginutils';
3+
import type * as babelCore from '@babel/core';
44

55
export interface RollupBabelInputPluginOptions
66
extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {

packages/beep/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
/**
44
* 🍣 A Rollup plugin that beeps when a build ends with errors.

packages/buble/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { transform } from 'buble';
2-
import { Plugin } from 'rollup';
2+
import type { Plugin } from 'rollup';
33
import { createFilter } from '@rollup/pluginutils';
44

55
import type { RollupBubleOptions } from '../types';

packages/buble/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import buble from '..';
44

packages/buble/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { TransformOptions } from 'buble';
3-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { TransformOptions } from 'buble';
3+
import type { Plugin } from 'rollup';
44

55
export interface RollupBubleOptions extends TransformOptions {
66
/**

packages/commonjs/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
type RequireReturnsDefaultOption = boolean | 'auto' | 'preferred' | 'namespace';
55
type DefaultIsModuleExportsOption = boolean | 'auto';

packages/data-uri/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { URL } from 'url';
22

3-
import { Plugin, RollupError } from 'rollup';
3+
import type { Plugin, RollupError } from 'rollup';
44

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

packages/data-uri/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
/**
44
* A Rollup plugin which imports modules from Data URIs.

packages/dsv/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import dsv from '..';
44

packages/dsv/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { DSVRowString } from 'd3-dsv';
2-
import { FilterPattern } from '@rollup/pluginutils';
3-
import { Plugin } from 'rollup';
1+
import type { DSVRowString } from 'd3-dsv';
2+
import type { FilterPattern } from '@rollup/pluginutils';
3+
import type { Plugin } from 'rollup';
44

55
interface RollupDsvOptions {
66
/**

packages/dynamic-import-vars/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

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

packages/dynamic-import-vars/types/index.d.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
3+
import type { BaseNode } from 'estree';
34

45
interface RollupDynamicImportVariablesOptions {
56
/**
@@ -24,10 +25,7 @@ interface RollupDynamicImportVariablesOptions {
2425

2526
export class VariableDynamicImportError extends Error {}
2627

27-
export function dynamicImportToGlob(
28-
node: import('estree').BaseNode,
29-
sourceString: string
30-
): null | string;
28+
export function dynamicImportToGlob(node: BaseNode, sourceString: string): null | string;
3129

3230
/**
3331
* Support variables in dynamic imports in Rollup.

packages/eslint/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { relative, resolve, sep } from 'path';
22

3-
import { Plugin } from 'rollup';
3+
import type { Plugin } from 'rollup';
44
import { createFilter } from '@rollup/pluginutils';
55
import { ESLint } from 'eslint';
66

packages/eslint/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Plugin } from 'rollup';
2-
import { CLIEngine, ESLint } from 'eslint';
3-
import { CreateFilter } from '@rollup/pluginutils';
1+
import type { Plugin } from 'rollup';
2+
import type { CLIEngine, ESLint } from 'eslint';
3+
import type { CreateFilter } from '@rollup/pluginutils';
44

55
export interface RollupEslintOptions extends ESLint.Options {
66
/**

packages/graphql/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import graphql from '..';
44

packages/graphql/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
export interface RollupGraphqlOptions {
55
/**

packages/html/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { extname } from 'path';
22

3-
import { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup';
3+
import type { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup';
44

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

packages/html/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';
1+
import type { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup';
22

33
export interface RollupHtmlTemplateOptions {
44
title: string;

packages/image/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import image from '..';
44

packages/image/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
interface RollupImageOptions {
55
/**

packages/inject/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import inject from '..';
44

packages/inject/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
type Injectment = string | [string, string];
44

packages/json/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import json from '..';
44

packages/json/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
export interface RollupJsonOptions {
55
/**

packages/legacy/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import legacy from '..';
44

packages/legacy/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
interface RollupLegacyOptions {
44
[key: string]: string | { [key: string]: string };

packages/multi-entry/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

33
import multiEntry from '..';
44

packages/multi-entry/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
interface RollupMultiEntryOptions {
55
/**

packages/node-resolve/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'rollup';
1+
import type { Plugin } from 'rollup';
22

33
export const DEFAULTS: {
44
customResolveOptions: {};

packages/pluginutils/src/attachScopes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as estree from 'estree';
1+
import type * as estree from 'estree';
22

33
import { walk } from 'estree-walker';
44

packages/pluginutils/src/extractAssignedNames.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1+
import type {
2+
ArrayPattern,
3+
AssignmentPattern,
4+
Identifier,
5+
ObjectPattern,
6+
RestElement
7+
} from 'estree';
8+
19
import type { ExtractAssignedNames } from '../types';
210

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

715
const extractors: Extractors = {
8-
ArrayPattern(names: string[], param: import('estree').ArrayPattern) {
16+
ArrayPattern(names: string[], param: ArrayPattern) {
917
for (const element of param.elements) {
1018
if (element) extractors[element.type](names, element);
1119
}
1220
},
1321

14-
AssignmentPattern(names: string[], param: import('estree').AssignmentPattern) {
22+
AssignmentPattern(names: string[], param: AssignmentPattern) {
1523
extractors[param.left.type](names, param.left);
1624
},
1725

18-
Identifier(names: string[], param: import('estree').Identifier) {
26+
Identifier(names: string[], param: Identifier) {
1927
names.push(param.name);
2028
},
2129

2230
MemberExpression() {},
2331

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

35-
RestElement(names: string[], param: import('estree').RestElement) {
43+
RestElement(names: string[], param: RestElement) {
3644
extractors[param.argument.type](names, param.argument);
3745
}
3846
};

packages/pluginutils/test/attachScopes.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import * as estree from 'estree';
1+
import type * as estree from 'estree';
22

33
import test from 'ava';
44
import { parse } from 'acorn';
55

6-
import { attachScopes, AttachedScope } from '../';
6+
import type { AttachedScope } from '../';
7+
import { attachScopes } from '../';
78

89
test('attaches a scope to the top level', (t) => {
910
const ast = parse('var foo;', { ecmaVersion: 2020, sourceType: 'module' });

packages/pluginutils/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseNode } from 'estree';
1+
import type { BaseNode } from 'estree';
22

33
export interface AttachedScope {
44
parent?: AttachedScope;

packages/replace/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
import { dirname } from 'path';
33

4-
import { RollupOptions } from 'rollup';
4+
import type { RollupOptions } from 'rollup';
55

66
import replace from '..';
77

packages/replace/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

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

packages/run/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ChildProcess, fork } from 'child_process';
1+
import type { ChildProcess } from 'child_process';
2+
import { fork } from 'child_process';
23
import { resolve, join, dirname } from 'path';
34

4-
import { Plugin, RenderedChunk } from 'rollup';
5+
import type { Plugin, RenderedChunk } from 'rollup';
56

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

packages/run/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ForkOptions } from 'child_process';
1+
import type { ForkOptions } from 'child_process';
22

3-
import { Plugin } from 'rollup';
3+
import type { Plugin } from 'rollup';
44

55
export interface RollupRunOptions extends ForkOptions {
66
args?: readonly string[];

packages/strip/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupOptions } from 'rollup';
1+
import type { RollupOptions } from 'rollup';
22

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

packages/strip/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FilterPattern } from '@rollup/pluginutils';
2-
import { Plugin } from 'rollup';
1+
import type { FilterPattern } from '@rollup/pluginutils';
2+
import type { Plugin } from 'rollup';
33

44
interface RollupStripOptions {
55
/**

0 commit comments

Comments
 (0)