Skip to content

Commit

Permalink
refactor: add eslint rules to enforce import order (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-oles committed Oct 29, 2021
1 parent 871bfe8 commit a0ad06f
Show file tree
Hide file tree
Showing 93 changed files with 813 additions and 342 deletions.
29 changes: 27 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'import', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:node/recommended',
'prettier',
],
settings: {
node: {
tryExtensions: ['.js', '.json', '.ts', '.d.ts'],
},
'import/extensions': ['.js', '.json', '.ts', '.d.ts'],
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
node: {
extensions: ['.js', '.json', '.ts', '.d.ts'],
},
},
},
rules: {
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/no-cycle': ['error'],
'prettier/prettier': 'error',
},
overrides: [
{
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"tapable": "^2.0.0"
},
"peerDependencies": {
"webpack": "^5.11.0",
"typescript": ">3.6.0"
"typescript": ">3.6.0",
"webpack": "^5.11.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^13.1.0",
Expand All @@ -89,19 +89,20 @@
"@types/node": "^16.4.13",
"@types/rimraf": "^3.0.1",
"@types/semver": "^7.3.8",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"commitlint": "^13.1.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^4.0.0",
"git-cz": "^4.7.6",
"husky": "^7.0.0",
"jest": "^27.0.6",
"jest-circus": "^27.0.6",
"jest-environment-node": "^27.0.6",
"json-schema": "^0.3.0",
"karton": "^0.4.1",
"lint-staged": "^11.1.2",
"mock-fs": "^5.0.0",
Expand Down
37 changes: 17 additions & 20 deletions src/ForkTsCheckerWebpackPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import webpack from 'webpack';
import { cosmiconfigSync } from 'cosmiconfig';
import merge from 'deepmerge';
import type { JSONSchema7 } from 'json-schema';
import { validate } from 'schema-utils';
import type webpack from 'webpack';
// type only dependency
// eslint-disable-next-line node/no-extraneous-import
import type { JSONSchema7 } from 'json-schema';
import { cosmiconfigSync } from 'cosmiconfig';
import merge from 'deepmerge';
import schema from './ForkTsCheckerWebpackPluginOptions.json';
import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';

import { createForkTsCheckerWebpackPluginConfiguration } from './ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
import schema from './ForkTsCheckerWebpackPluginOptions.json';
import { createForkTsCheckerWebpackPluginState } from './ForkTsCheckerWebpackPluginState';
import { assertTypeScriptSupport } from './typescript-reporter/TypeScriptSupport';
import { createTypeScriptReporterRpcClient } from './typescript-reporter/reporter/TypeScriptReporterRpcClient';
import { tapStartToConnectAndRunReporter } from './hooks/tapStartToConnectAndRunReporter';
import { tapStopToDisconnectReporter } from './hooks/tapStopToDisconnectReporter';
import { tapAfterCompileToAddDependencies } from './hooks/tapAfterCompileToAddDependencies';
import { tapErrorToLogMessage } from './hooks/tapErrorToLogMessage';
import { getForkTsCheckerWebpackPluginHooks } from './hooks/pluginHooks';
import { dependenciesPool, issuesPool } from './hooks/pluginPools';
import { tapAfterCompileToAddDependencies } from './hooks/tapAfterCompileToAddDependencies';
import { tapAfterEnvironmentToPatchWatching } from './hooks/tapAfterEnvironmentToPatchWatching';
import { createPool, Pool } from './utils/async/pool';
import os from 'os';
import { tapErrorToLogMessage } from './hooks/tapErrorToLogMessage';
import { tapStartToConnectAndRunReporter } from './hooks/tapStartToConnectAndRunReporter';
import { tapStopToDisconnectReporter } from './hooks/tapStopToDisconnectReporter';
import { createTypeScriptReporterRpcClient } from './typescript-reporter/reporter/TypeScriptReporterRpcClient';
import { assertTypeScriptSupport } from './typescript-reporter/TypeScriptSupport';

class ForkTsCheckerWebpackPlugin {
/**
Expand All @@ -28,16 +28,13 @@ class ForkTsCheckerWebpackPlugin {
/**
* Default pools for the plugin concurrency limit
*/
static readonly issuesPool: Pool = createPool(Math.max(1, os.cpus().length));
static readonly dependenciesPool: Pool = createPool(Math.max(1, os.cpus().length));
static readonly issuesPool = issuesPool;
static readonly dependenciesPool = dependenciesPool;

/**
* @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
*/
static get pool(): Pool {
// for backward compatibility
return ForkTsCheckerWebpackPlugin.issuesPool;
}
static readonly pool = issuesPool;

private readonly options: ForkTsCheckerWebpackPluginOptions;

Expand Down
20 changes: 11 additions & 9 deletions src/ForkTsCheckerWebpackPluginConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
import { createIssueConfiguration, IssueConfiguration } from './issue/IssueConfiguration';
import { createFormatterConfiguration, FormatterConfiguration } from './formatter';
import {
createTypeScriptReporterConfiguration,
TypeScriptReporterConfiguration,
} from './typescript-reporter/TypeScriptReporterConfiguration';
import { createLoggerConfiguration, LoggerConfiguration } from './logger/LoggerConfiguration';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
import type { FormatterConfiguration } from './formatter';
import { createFormatterConfiguration } from './formatter';
import type { IssueConfiguration } from './issue/IssueConfiguration';
import { createIssueConfiguration } from './issue/IssueConfiguration';
import type { LoggerConfiguration } from './logger/LoggerConfiguration';
import { createLoggerConfiguration } from './logger/LoggerConfiguration';
import type { TypeScriptReporterConfiguration } from './typescript-reporter/TypeScriptReporterConfiguration';
import { createTypeScriptReporterConfiguration } from './typescript-reporter/TypeScriptReporterConfiguration';

interface ForkTsCheckerWebpackPluginConfiguration {
async: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/ForkTsCheckerWebpackPluginOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TypeScriptReporterOptions } from './typescript-reporter/TypeScriptReporterOptions';
import { IssueOptions } from './issue/IssueOptions';
import { FormatterOptions } from './formatter';
import LoggerOptions from './logger/LoggerOptions';
import type { FormatterOptions } from './formatter';
import type { IssueOptions } from './issue/IssueOptions';
import type LoggerOptions from './logger/LoggerOptions';
import type { TypeScriptReporterOptions } from './typescript-reporter/TypeScriptReporterOptions';

interface ForkTsCheckerWebpackPluginOptions {
async?: boolean;
Expand Down
7 changes: 4 additions & 3 deletions src/ForkTsCheckerWebpackPluginState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FullTap } from 'tapable';
import { FilesMatch, Report } from './reporter';
import { Issue } from './issue';
import type { FullTap } from 'tapable';

import type { Issue } from './issue';
import type { FilesMatch, Report } from './reporter';

interface ForkTsCheckerWebpackPluginState {
issuesReportPromise: Promise<Report | undefined>;
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/BasicFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk';
import { Formatter } from './Formatter';

import type { Formatter } from './Formatter';

function createBasicFormatter(): Formatter {
return function basicFormatter(issue) {
Expand Down
6 changes: 4 additions & 2 deletions src/formatter/CodeFrameFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os from 'os';
import fs from 'fs-extra';

import { codeFrameColumns } from '@babel/code-frame';
import { Formatter } from './Formatter';
import fs from 'fs-extra';

import { createBasicFormatter } from './BasicFormatter';
import type { Formatter } from './Formatter';
import { BabelCodeFrameOptions } from './types/babel__code-frame';

function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter {
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/Formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Issue } from '../issue';
import type { Issue } from '../issue';

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

Expand Down
4 changes: 2 additions & 2 deletions src/formatter/FormatterConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';
import { Formatter } from './Formatter';
import { createBasicFormatter } from './BasicFormatter';
import { createCodeFrameFormatter } from './CodeFrameFormatter';
import type { Formatter } from './Formatter';
import type { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';

type FormatterConfiguration = Formatter;

Expand Down
4 changes: 2 additions & 2 deletions src/formatter/FormatterOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Formatter } from './Formatter';
import { BabelCodeFrameOptions } from './types/babel__code-frame';
import type { Formatter } from './Formatter';
import type { BabelCodeFrameOptions } from './types/babel__code-frame';

type FormatterType = 'basic' | 'codeframe';

Expand Down
5 changes: 4 additions & 1 deletion src/formatter/WebpackFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os from 'os';

import chalk from 'chalk';
import { Formatter } from './Formatter';

import { formatIssueLocation } from '../issue';
import { relativeToContext } from '../utils/path/relativeToContext';

import type { Formatter } from './Formatter';

function createWebpackFormatter(formatter: Formatter): Formatter {
// mimics webpack error formatter
return function webpackFormatter(issue) {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/interceptDoneToGetWebpackDevServerTap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';

function interceptDoneToGetWebpackDevServerTap(
compiler: webpack.Compiler,
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/pluginHooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as webpack from 'webpack';
import { SyncHook, SyncWaterfallHook, AsyncSeriesWaterfallHook } from 'tapable';
import { FilesChange } from '../reporter';
import { Issue } from '../issue';
import type * as webpack from 'webpack';

import type { Issue } from '../issue';
import type { FilesChange } from '../reporter';

const compilerHookMap = new WeakMap<
webpack.Compiler | webpack.MultiCompiler,
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/pluginPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as os from 'os';

import type { Pool } from '../utils/async/pool';
import { createPool } from '../utils/async/pool';

const issuesPool: Pool = createPool(Math.max(1, os.cpus().length));
const dependenciesPool: Pool = createPool(Math.max(1, os.cpus().length));

export { issuesPool, dependenciesPool };
7 changes: 4 additions & 3 deletions src/hooks/tapAfterCompileToAddDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';

function tapAfterCompileToAddDependencies(
compiler: webpack.Compiler,
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/tapAfterCompileToGetIssues.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import type { Issue } from '../issue';
import { IssueWebpackError } from '../issue/IssueWebpackError';
import { Issue } from '../issue';

import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';

function tapAfterCompileToGetIssues(
compiler: webpack.Compiler,
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/tapAfterEnvironmentToPatchWatching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { InclusiveNodeWatchFileSystem } from '../watch/InclusiveNodeWatchFileSystem';
import { WatchFileSystem } from '../watch/WatchFileSystem';
import type { WatchFileSystem } from '../watch/WatchFileSystem';

function tapAfterEnvironmentToPatchWatching(
compiler: webpack.Compiler,
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/tapDoneToAsyncGetIssues.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import webpack from 'webpack';
import chalk from 'chalk';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { createWebpackFormatter } from '../formatter/WebpackFormatter';
import { Issue } from '../issue';
import type { Issue } from '../issue';
import { IssueWebpackError } from '../issue/IssueWebpackError';
import isPending from '../utils/async/isPending';
import wait from '../utils/async/wait';

import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';

function tapDoneToAsyncGetIssues(
compiler: webpack.Compiler,
configuration: ForkTsCheckerWebpackPluginConfiguration,
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/tapErrorToLogMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import webpack from 'webpack';
import { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
import { RpcIpcMessagePortClosedError } from '../rpc/rpc-ipc/error/RpcIpcMessagePortClosedError';
import chalk from 'chalk';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import { RpcIpcMessagePortClosedError } from '../rpc/rpc-ipc/error/RpcIpcMessagePortClosedError';

import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';

function tapErrorToLogMessage(
compiler: webpack.Compiler,
Expand Down

0 comments on commit a0ad06f

Please sign in to comment.