Skip to content

Commit 1e38fc7

Browse files
authored
feat: threads (#39)
* fix: handle exceptions from eslint * fix: prevent ts from trying&failing to overwrite js files * feat: use jest-worker
1 parent 43119b9 commit 1e38fc7

16 files changed

+2056
-18073
lines changed

declarations/getESLint.d.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
/** @typedef {import('eslint').ESLint} ESLint */
2+
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
23
/** @typedef {import('./options').Options} Options */
4+
/** @typedef {() => Promise<void>} AsyncTask */
5+
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
6+
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
7+
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
38
/**
49
* @param {Options} options
5-
* @returns {{ESLint: ESLint, eslint: ESLint}}
10+
* @returns {Linter}
611
*/
7-
export default function getESLint(
8-
options: Options
9-
): {
10-
ESLint: import('eslint').ESLint;
11-
eslint: import('eslint').ESLint;
12-
};
12+
export function loadESLint(options: Options): Linter;
13+
/**
14+
* @param {number} poolSize
15+
* @param {Options} options
16+
* @returns {Linter}
17+
*/
18+
export function loadESLintThreaded(poolSize: number, options: Options): Linter;
19+
/**
20+
* @param {Options} options
21+
* @returns {Linter}
22+
*/
23+
export default function getESLint({ threads, ...options }: Options): Linter;
1324
export type ESLint = import('eslint').ESLint;
25+
export type LintResult = import('eslint').ESLint.LintResult;
1426
export type Options = {
1527
context?: string | undefined;
1628
emitError?: boolean | undefined;
@@ -26,4 +38,18 @@ export type Options = {
2638
lintDirtyModulesOnly?: boolean | undefined;
2739
quiet?: boolean | undefined;
2840
outputReport?: import('./options').OutputReport | undefined;
41+
threads?: number | boolean | undefined;
42+
};
43+
export type AsyncTask = () => Promise<void>;
44+
export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
45+
export type Worker = JestWorker & {
46+
lintFiles: LintTask;
47+
};
48+
export type Linter = {
49+
threads: number;
50+
ESLint: ESLint;
51+
eslint: ESLint;
52+
lintFiles: LintTask;
53+
cleanup: AsyncTask;
2954
};
55+
import JestWorker from 'jest-worker';

declarations/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ export type Options = {
3737
lintDirtyModulesOnly?: boolean | undefined;
3838
quiet?: boolean | undefined;
3939
outputReport?: import('./options').OutputReport | undefined;
40+
threads?: number | boolean | undefined;
4041
};

declarations/linter.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
/** @typedef {(files: string|string[]) => void} Linter */
1313
/**
1414
* @param {Options} options
15+
* @param {Compilation} compilation
1516
* @returns {{lint: Linter, report: Reporter}}
1617
*/
1718
export default function linter(
18-
options: Options
19+
options: Options,
20+
compilation: Compilation
1921
): {
2022
lint: Linter;
2123
report: Reporter;
@@ -41,6 +43,7 @@ export type Options = {
4143
lintDirtyModulesOnly?: boolean | undefined;
4244
quiet?: boolean | undefined;
4345
outputReport?: import('./options').OutputReport | undefined;
46+
threads?: number | boolean | undefined;
4447
};
4548
export type FormatterFunction = (
4649
results: import('eslint').ESLint.LintResult[],

declarations/options.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @property {boolean=} lintDirtyModulesOnly
2929
* @property {boolean=} quiet
3030
* @property {OutputReport=} outputReport
31+
* @property {number|boolean=} threads
3132
*/
3233
/**
3334
* @param {Options} pluginOptions
@@ -65,4 +66,5 @@ export type Options = {
6566
lintDirtyModulesOnly?: boolean | undefined;
6667
quiet?: boolean | undefined;
6768
outputReport?: OutputReport | undefined;
69+
threads?: (number | boolean) | undefined;
6870
};

declarations/worker.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type setupOptions = {
2+
/**
3+
* - import path of eslint
4+
*/
5+
eslintPath?: string | undefined;
6+
/**
7+
* - linter options
8+
*/
9+
eslintOptions?: ESLintOptions | undefined;
10+
};
11+
export type ESLint = import('eslint').ESLint;
12+
export type ESLintOptions = import('eslint').ESLint.Options;

0 commit comments

Comments
 (0)