Skip to content

Commit a0ad06f

Browse files
authored
refactor: add eslint rules to enforce import order (#671)
1 parent 871bfe8 commit a0ad06f

File tree

93 files changed

+813
-342
lines changed

Some content is hidden

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

93 files changed

+813
-342
lines changed

.eslintrc.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
4-
plugins: ['@typescript-eslint'],
4+
plugins: ['@typescript-eslint', 'import', 'prettier'],
55
extends: [
66
'eslint:recommended',
77
'plugin:@typescript-eslint/recommended',
88
'plugin:node/recommended',
9-
'prettier',
109
],
1110
settings: {
1211
node: {
1312
tryExtensions: ['.js', '.json', '.ts', '.d.ts'],
1413
},
14+
'import/extensions': ['.js', '.json', '.ts', '.d.ts'],
15+
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
16+
'import/parsers': {
17+
'@typescript-eslint/parser': ['.ts'],
18+
},
19+
'import/resolver': {
20+
node: {
21+
extensions: ['.js', '.json', '.ts', '.d.ts'],
22+
},
23+
},
24+
},
25+
rules: {
26+
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
27+
'import/order': [
28+
'error',
29+
{
30+
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
31+
'newlines-between': 'always',
32+
alphabetize: {
33+
order: 'asc',
34+
caseInsensitive: true,
35+
},
36+
},
37+
],
38+
'import/no-cycle': ['error'],
39+
'prettier/prettier': 'error',
1540
},
1641
overrides: [
1742
{

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
"tapable": "^2.0.0"
7070
},
7171
"peerDependencies": {
72-
"webpack": "^5.11.0",
73-
"typescript": ">3.6.0"
72+
"typescript": ">3.6.0",
73+
"webpack": "^5.11.0"
7474
},
7575
"devDependencies": {
7676
"@commitlint/config-conventional": "^13.1.0",
@@ -89,19 +89,20 @@
8989
"@types/node": "^16.4.13",
9090
"@types/rimraf": "^3.0.1",
9191
"@types/semver": "^7.3.8",
92-
"@typescript-eslint/eslint-plugin": "^4.29.0",
93-
"@typescript-eslint/parser": "^4.29.0",
92+
"@typescript-eslint/eslint-plugin": "^5.1.0",
93+
"@typescript-eslint/parser": "^5.1.0",
9494
"commitlint": "^13.1.0",
9595
"cross-env": "^7.0.3",
9696
"eslint": "^7.32.0",
97-
"eslint-config-prettier": "^8.3.0",
97+
"eslint-plugin-import": "^2.25.2",
9898
"eslint-plugin-node": "^11.1.0",
99-
"eslint-plugin-prettier": "^3.4.0",
99+
"eslint-plugin-prettier": "^4.0.0",
100100
"git-cz": "^4.7.6",
101101
"husky": "^7.0.0",
102102
"jest": "^27.0.6",
103103
"jest-circus": "^27.0.6",
104104
"jest-environment-node": "^27.0.6",
105+
"json-schema": "^0.3.0",
105106
"karton": "^0.4.1",
106107
"lint-staged": "^11.1.2",
107108
"mock-fs": "^5.0.0",

src/ForkTsCheckerWebpackPlugin.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import webpack from 'webpack';
1+
import { cosmiconfigSync } from 'cosmiconfig';
2+
import merge from 'deepmerge';
3+
import type { JSONSchema7 } from 'json-schema';
24
import { validate } from 'schema-utils';
5+
import type webpack from 'webpack';
36
// type only dependency
47
// eslint-disable-next-line node/no-extraneous-import
5-
import type { JSONSchema7 } from 'json-schema';
6-
import { cosmiconfigSync } from 'cosmiconfig';
7-
import merge from 'deepmerge';
8-
import schema from './ForkTsCheckerWebpackPluginOptions.json';
9-
import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
8+
109
import { createForkTsCheckerWebpackPluginConfiguration } from './ForkTsCheckerWebpackPluginConfiguration';
10+
import type { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
11+
import schema from './ForkTsCheckerWebpackPluginOptions.json';
1112
import { createForkTsCheckerWebpackPluginState } from './ForkTsCheckerWebpackPluginState';
12-
import { assertTypeScriptSupport } from './typescript-reporter/TypeScriptSupport';
13-
import { createTypeScriptReporterRpcClient } from './typescript-reporter/reporter/TypeScriptReporterRpcClient';
14-
import { tapStartToConnectAndRunReporter } from './hooks/tapStartToConnectAndRunReporter';
15-
import { tapStopToDisconnectReporter } from './hooks/tapStopToDisconnectReporter';
16-
import { tapAfterCompileToAddDependencies } from './hooks/tapAfterCompileToAddDependencies';
17-
import { tapErrorToLogMessage } from './hooks/tapErrorToLogMessage';
1813
import { getForkTsCheckerWebpackPluginHooks } from './hooks/pluginHooks';
14+
import { dependenciesPool, issuesPool } from './hooks/pluginPools';
15+
import { tapAfterCompileToAddDependencies } from './hooks/tapAfterCompileToAddDependencies';
1916
import { tapAfterEnvironmentToPatchWatching } from './hooks/tapAfterEnvironmentToPatchWatching';
20-
import { createPool, Pool } from './utils/async/pool';
21-
import os from 'os';
17+
import { tapErrorToLogMessage } from './hooks/tapErrorToLogMessage';
18+
import { tapStartToConnectAndRunReporter } from './hooks/tapStartToConnectAndRunReporter';
19+
import { tapStopToDisconnectReporter } from './hooks/tapStopToDisconnectReporter';
20+
import { createTypeScriptReporterRpcClient } from './typescript-reporter/reporter/TypeScriptReporterRpcClient';
21+
import { assertTypeScriptSupport } from './typescript-reporter/TypeScriptSupport';
2222

2323
class ForkTsCheckerWebpackPlugin {
2424
/**
@@ -28,16 +28,13 @@ class ForkTsCheckerWebpackPlugin {
2828
/**
2929
* Default pools for the plugin concurrency limit
3030
*/
31-
static readonly issuesPool: Pool = createPool(Math.max(1, os.cpus().length));
32-
static readonly dependenciesPool: Pool = createPool(Math.max(1, os.cpus().length));
31+
static readonly issuesPool = issuesPool;
32+
static readonly dependenciesPool = dependenciesPool;
3333

3434
/**
3535
* @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
3636
*/
37-
static get pool(): Pool {
38-
// for backward compatibility
39-
return ForkTsCheckerWebpackPlugin.issuesPool;
40-
}
37+
static readonly pool = issuesPool;
4138

4239
private readonly options: ForkTsCheckerWebpackPluginOptions;
4340

src/ForkTsCheckerWebpackPluginConfiguration.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import webpack from 'webpack';
2-
import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
3-
import { createIssueConfiguration, IssueConfiguration } from './issue/IssueConfiguration';
4-
import { createFormatterConfiguration, FormatterConfiguration } from './formatter';
5-
import {
6-
createTypeScriptReporterConfiguration,
7-
TypeScriptReporterConfiguration,
8-
} from './typescript-reporter/TypeScriptReporterConfiguration';
9-
import { createLoggerConfiguration, LoggerConfiguration } from './logger/LoggerConfiguration';
1+
import type webpack from 'webpack';
2+
3+
import type { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
4+
import type { FormatterConfiguration } from './formatter';
5+
import { createFormatterConfiguration } from './formatter';
6+
import type { IssueConfiguration } from './issue/IssueConfiguration';
7+
import { createIssueConfiguration } from './issue/IssueConfiguration';
8+
import type { LoggerConfiguration } from './logger/LoggerConfiguration';
9+
import { createLoggerConfiguration } from './logger/LoggerConfiguration';
10+
import type { TypeScriptReporterConfiguration } from './typescript-reporter/TypeScriptReporterConfiguration';
11+
import { createTypeScriptReporterConfiguration } from './typescript-reporter/TypeScriptReporterConfiguration';
1012

1113
interface ForkTsCheckerWebpackPluginConfiguration {
1214
async: boolean;

src/ForkTsCheckerWebpackPluginOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { TypeScriptReporterOptions } from './typescript-reporter/TypeScriptReporterOptions';
2-
import { IssueOptions } from './issue/IssueOptions';
3-
import { FormatterOptions } from './formatter';
4-
import LoggerOptions from './logger/LoggerOptions';
1+
import type { FormatterOptions } from './formatter';
2+
import type { IssueOptions } from './issue/IssueOptions';
3+
import type LoggerOptions from './logger/LoggerOptions';
4+
import type { TypeScriptReporterOptions } from './typescript-reporter/TypeScriptReporterOptions';
55

66
interface ForkTsCheckerWebpackPluginOptions {
77
async?: boolean;

src/ForkTsCheckerWebpackPluginState.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { FullTap } from 'tapable';
2-
import { FilesMatch, Report } from './reporter';
3-
import { Issue } from './issue';
1+
import type { FullTap } from 'tapable';
2+
3+
import type { Issue } from './issue';
4+
import type { FilesMatch, Report } from './reporter';
45

56
interface ForkTsCheckerWebpackPluginState {
67
issuesReportPromise: Promise<Report | undefined>;

src/formatter/BasicFormatter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk';
2-
import { Formatter } from './Formatter';
2+
3+
import type { Formatter } from './Formatter';
34

45
function createBasicFormatter(): Formatter {
56
return function basicFormatter(issue) {

src/formatter/CodeFrameFormatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os from 'os';
2-
import fs from 'fs-extra';
2+
33
import { codeFrameColumns } from '@babel/code-frame';
4-
import { Formatter } from './Formatter';
4+
import fs from 'fs-extra';
5+
56
import { createBasicFormatter } from './BasicFormatter';
7+
import type { Formatter } from './Formatter';
68
import { BabelCodeFrameOptions } from './types/babel__code-frame';
79

810
function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter {

src/formatter/Formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Issue } from '../issue';
1+
import type { Issue } from '../issue';
22

33
type Formatter = (issue: Issue) => string;
44

src/formatter/FormatterConfiguration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';
2-
import { Formatter } from './Formatter';
31
import { createBasicFormatter } from './BasicFormatter';
42
import { createCodeFrameFormatter } from './CodeFrameFormatter';
3+
import type { Formatter } from './Formatter';
4+
import type { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';
55

66
type FormatterConfiguration = Formatter;
77

0 commit comments

Comments
 (0)