Skip to content

Commit

Permalink
fix: set key in apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jan 22, 2021
1 parent a6f49ef commit 78307ea
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
13 changes: 11 additions & 2 deletions declarations/getESLint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@
*/
export function loadESLint(options: Options): Linter;
/**
* @param {string|undefined} key
* @param {number} poolSize
* @param {Options} options
* @returns {Linter}
*/
export function loadESLintThreaded(poolSize: number, options: Options): Linter;
export function loadESLintThreaded(
key: string | undefined,
poolSize: number,
options: Options
): Linter;
/**
* @param {string|undefined} key
* @param {Options} options
* @returns {Linter}
*/
export default function getESLint({ threads, ...options }: Options): Linter;
export default function getESLint(
key: string | undefined,
{ threads, ...options }: Options
): Linter;
export type ESLint = import('eslint').ESLint;
export type LintResult = import('eslint').ESLint.LintResult;
export type Options = import('./options').PluginOptions &
Expand Down
1 change: 1 addition & 0 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ESLintWebpackPlugin {
* @returns {void}
*/
apply(compiler: Compiler): void;
key: string | undefined;
/**
*
* @param {Compiler} compiler
Expand Down
2 changes: 2 additions & 0 deletions declarations/linter.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* @param {string|undefined} key
* @param {Options} options
* @param {Compilation} compilation
* @returns {{lint: Linter, report: Reporter}}
*/
export default function linter(
key: string | undefined,
options: Options,
compilation: Compilation
): {
Expand Down
6 changes: 3 additions & 3 deletions src/getESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function loadESLint(options) {
}

/**
* @param {string} key
* @param {string|undefined} key
* @param {number} poolSize
* @param {Options} options
* @returns {Linter}
Expand Down Expand Up @@ -88,7 +88,7 @@ export function loadESLintThreaded(key, poolSize, options) {
}

/**
* @param {string} key
* @param {string|undefined} key
* @param {Options} options
* @returns {Linter}
*/
Expand All @@ -110,7 +110,7 @@ export default function getESLint(key, { threads, ...options }) {
}

/**
* @param {string} key
* @param {string|undefined} key
* @param {Options} options
* @returns {string}
*/
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { parseFiles, parseFoldersToGlobs } from './utils';
/** @typedef {import('./options').Options} Options */

const ESLINT_PLUGIN = 'ESLintWebpackPlugin';
let counter = 0;

export class ESLintWebpackPlugin {
/**
* @param {Options} options
*/
constructor(options = {}) {
this.key = Math.random().toString();
this.options = getOptions(options);
this.run = this.run.bind(this);
}
Expand All @@ -27,6 +27,12 @@ export class ESLintWebpackPlugin {
* @returns {void}
*/
apply(compiler) {
// Generate key for each compilation,
// this differentiates one from the other when being cached.
this.key = compiler.name || `${ESLINT_PLUGIN}_${(counter += 1)}`;

// If `lintDirtyModulesOnly` is disabled,
// execute the linter on the build
if (!this.options.lintDirtyModulesOnly) {
compiler.hooks.run.tapPromise(ESLINT_PLUGIN, this.run);
}
Expand Down
2 changes: 1 addition & 1 deletion src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import getESLint from './getESLint';
const resultStorage = new WeakMap();

/**
* @param {string} key
* @param {string|undefined} key
* @param {Options} options
* @param {Compilation} compilation
* @returns {{lint: Linter, report: Reporter}}
Expand Down

0 comments on commit 78307ea

Please sign in to comment.