Skip to content

Commit

Permalink
feat: threads (#39)
Browse files Browse the repository at this point in the history
* fix: handle exceptions from eslint

* fix: prevent ts from trying&failing to overwrite js files

* feat: use jest-worker
  • Loading branch information
jsg2021 committed Nov 20, 2020
1 parent 43119b9 commit 1e38fc7
Show file tree
Hide file tree
Showing 16 changed files with 2,056 additions and 18,073 deletions.
40 changes: 33 additions & 7 deletions declarations/getESLint.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/** @typedef {import('eslint').ESLint} ESLint */
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
/** @typedef {import('./options').Options} Options */
/** @typedef {() => Promise<void>} AsyncTask */
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
/**
* @param {Options} options
* @returns {{ESLint: ESLint, eslint: ESLint}}
* @returns {Linter}
*/
export default function getESLint(
options: Options
): {
ESLint: import('eslint').ESLint;
eslint: import('eslint').ESLint;
};
export function loadESLint(options: Options): Linter;
/**
* @param {number} poolSize
* @param {Options} options
* @returns {Linter}
*/
export function loadESLintThreaded(poolSize: number, options: Options): Linter;
/**
* @param {Options} options
* @returns {Linter}
*/
export default function getESLint({ threads, ...options }: Options): Linter;
export type ESLint = import('eslint').ESLint;
export type LintResult = import('eslint').ESLint.LintResult;
export type Options = {
context?: string | undefined;
emitError?: boolean | undefined;
Expand All @@ -26,4 +38,18 @@ export type Options = {
lintDirtyModulesOnly?: boolean | undefined;
quiet?: boolean | undefined;
outputReport?: import('./options').OutputReport | undefined;
threads?: number | boolean | undefined;
};
export type AsyncTask = () => Promise<void>;
export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
export type Worker = JestWorker & {
lintFiles: LintTask;
};
export type Linter = {
threads: number;
ESLint: ESLint;
eslint: ESLint;
lintFiles: LintTask;
cleanup: AsyncTask;
};
import JestWorker from 'jest-worker';
1 change: 1 addition & 0 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export type Options = {
lintDirtyModulesOnly?: boolean | undefined;
quiet?: boolean | undefined;
outputReport?: import('./options').OutputReport | undefined;
threads?: number | boolean | undefined;
};
5 changes: 4 additions & 1 deletion declarations/linter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
/** @typedef {(files: string|string[]) => void} Linter */
/**
* @param {Options} options
* @param {Compilation} compilation
* @returns {{lint: Linter, report: Reporter}}
*/
export default function linter(
options: Options
options: Options,
compilation: Compilation
): {
lint: Linter;
report: Reporter;
Expand All @@ -41,6 +43,7 @@ export type Options = {
lintDirtyModulesOnly?: boolean | undefined;
quiet?: boolean | undefined;
outputReport?: import('./options').OutputReport | undefined;
threads?: number | boolean | undefined;
};
export type FormatterFunction = (
results: import('eslint').ESLint.LintResult[],
Expand Down
2 changes: 2 additions & 0 deletions declarations/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @property {boolean=} lintDirtyModulesOnly
* @property {boolean=} quiet
* @property {OutputReport=} outputReport
* @property {number|boolean=} threads
*/
/**
* @param {Options} pluginOptions
Expand Down Expand Up @@ -65,4 +66,5 @@ export type Options = {
lintDirtyModulesOnly?: boolean | undefined;
quiet?: boolean | undefined;
outputReport?: OutputReport | undefined;
threads?: (number | boolean) | undefined;
};
12 changes: 12 additions & 0 deletions declarations/worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type setupOptions = {
/**
* - import path of eslint
*/
eslintPath?: string | undefined;
/**
* - linter options
*/
eslintOptions?: ESLintOptions | undefined;
};
export type ESLint = import('eslint').ESLint;
export type ESLintOptions = import('eslint').ESLint.Options;

0 comments on commit 1e38fc7

Please sign in to comment.