eslint-webpack-plugin
Advanced tools
Comparing version 2.4.3 to 2.5.0
@@ -5,2 +5,28 @@ # Changelog | ||
## [2.5.0](https://github.com/webpack-contrib/eslint-webpack-plugin/compare/v2.4.3...v2.5.0) (2021-02-04) | ||
### ⚠ BREAKING CHANGES | ||
* Updates to emitError and emitWarning | ||
Setting only emitError to true will no longer exclusively print files with errors | ||
and disregard the files with warnings. Similarly, setting only emitWarning to true | ||
will no longer exclusively print files with warnings disregard the files with errors. | ||
* fix: use quiet to override emitError and emitWarning | ||
- quiet is essentially syntactic sugar for setting emitError to true | ||
and emitWarning to false | ||
### Bug Fixes | ||
* fails when `failOnError` or `failOnWarning` enabled ([#72](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/72)) ([8a72a8a](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/8a72a8ad26b8decb800f955d8f4d362f280c4d0f)) | ||
* lint dirty modules only ([#67](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/67)) ([f7f372e](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/f7f372e800e75fcd2928655648fee01266c6d158)) | ||
* threads multi-compiler ([#69](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/69)) ([cef4f74](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/cef4f7473707fb3f069ec44c54b5ed2d27d931f8)) | ||
* types ([#66](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/66)) ([4daddf5](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/4daddf5335b2c78203482d7e7f6d82a909277212)) | ||
* Fix emit warning error quiet (#46) ([d38165b](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/d38165bef1e2d73a9d53f42d80b926c9eab12707)), closes [#46](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/46) [#19](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/19) [#19](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/19) | ||
### [2.4.3](https://github.com/webpack-contrib/eslint-webpack-plugin/compare/v2.4.2...v2.4.3) (2021-01-19) | ||
@@ -11,4 +37,2 @@ | ||
* crash on `split` ([#62](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/62)) ([2038c32](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/2038c3285b4fbb65d9bc5c5a789dedbb72378ace)) | ||
* crash on `split` ([#62](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/62)) ([10c79c9](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/10c79c9709320203d1cb4eff36dae0715c0bc60e)) | ||
* crash on `split` ([#62](https://github.com/webpack-contrib/eslint-webpack-plugin/issues/62)) ([db38f61](https://github.com/webpack-contrib/eslint-webpack-plugin/commit/db38f611965cfdec83984364e0b982bbd7a678e0)) | ||
@@ -15,0 +39,0 @@ |
@@ -1,2 +0,3 @@ | ||
declare const _exports: typeof import('.').ESLintWebpackPlugin; | ||
declare const _exports: typeof plugin.default; | ||
export = _exports; | ||
import plugin = require('.'); |
@@ -1,2 +0,3 @@ | ||
export default class ESLintError { | ||
export default ESLintError; | ||
declare class ESLintError extends Error { | ||
/** | ||
@@ -6,4 +7,2 @@ * @param {string=} messages | ||
constructor(messages?: string | undefined); | ||
name: string; | ||
stack: string; | ||
} |
@@ -14,2 +14,3 @@ /** @typedef {import('eslint').ESLint} ESLint */ | ||
/** | ||
* @param {string|undefined} key | ||
* @param {number} poolSize | ||
@@ -19,8 +20,16 @@ * @param {Options} options | ||
*/ | ||
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; | ||
@@ -27,0 +36,0 @@ export type LintResult = import('eslint').ESLint.LintResult; |
@@ -1,2 +0,6 @@ | ||
export class ESLintWebpackPlugin { | ||
export default ESLintWebpackPlugin; | ||
export type Compiler = import('webpack').Compiler; | ||
export type Options = import('./options').PluginOptions & | ||
import('eslint').ESLint.Options; | ||
declare class ESLintWebpackPlugin { | ||
/** | ||
@@ -16,2 +20,3 @@ * @param {Options} options | ||
apply(compiler: Compiler): void; | ||
key: string | undefined; | ||
/** | ||
@@ -24,5 +29,1 @@ * | ||
} | ||
export default ESLintWebpackPlugin; | ||
export type Compiler = import('webpack').Compiler; | ||
export type Options = import('./options').PluginOptions & | ||
import('eslint').ESLint.Options; |
/** | ||
* @param {string|undefined} key | ||
* @param {Options} options | ||
@@ -7,2 +8,3 @@ * @param {Compilation} compilation | ||
export default function linter( | ||
key: string | undefined, | ||
options: Options, | ||
@@ -30,5 +32,3 @@ compilation: Compilation | ||
warnings?: ESLintError | undefined; | ||
generateReportAsset?: | ||
| ((compilation: Compilation) => Promise<void>) | ||
| undefined; | ||
generateReportAsset?: GenerateReport | undefined; | ||
}; | ||
@@ -35,0 +35,0 @@ export type Reporter = () => Promise<Report>; |
@@ -8,8 +8,3 @@ "use strict"; | ||
var _WebpackError = _interopRequireDefault(require("webpack/lib/WebpackError")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// @ts-ignore | ||
class ESLintError extends _WebpackError.default { | ||
class ESLintError extends Error { | ||
/** | ||
@@ -26,2 +21,3 @@ * @param {string=} messages | ||
exports.default = ESLintError; | ||
var _default = ESLintError; | ||
exports.default = _default; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _os = _interopRequireDefault(require("os")); | ||
var _os = require("os"); | ||
@@ -71,2 +71,3 @@ var _jestWorker = _interopRequireDefault(require("jest-worker")); | ||
/** | ||
* @param {string|undefined} key | ||
* @param {number} poolSize | ||
@@ -78,4 +79,4 @@ * @param {Options} options | ||
function loadESLintThreaded(poolSize, options) { | ||
const key = getCacheKey(options); | ||
function loadESLintThreaded(key, poolSize, options) { | ||
const cacheKey = getCacheKey(key, options); | ||
const { | ||
@@ -110,3 +111,3 @@ eslintPath = 'eslint' | ||
cleanup: async () => { | ||
cache[key] = local; | ||
cache[cacheKey] = local; | ||
@@ -124,2 +125,3 @@ context.lintFiles = files => local.lintFiles(files); | ||
/** | ||
* @param {string|undefined} key | ||
* @param {Options} options | ||
@@ -130,10 +132,10 @@ * @returns {Linter} | ||
function getESLint({ | ||
function getESLint(key, { | ||
threads, | ||
...options | ||
}) { | ||
const max = typeof threads !== 'number' ? threads ? _os.default.cpus().length - 1 : 1 : | ||
const max = typeof threads !== 'number' ? threads ? (0, _os.cpus)().length - 1 : 1 : | ||
/* istanbul ignore next */ | ||
threads; | ||
const key = getCacheKey({ | ||
const cacheKey = getCacheKey(key, { | ||
threads, | ||
@@ -143,9 +145,10 @@ ...options | ||
if (!cache[key]) { | ||
cache[key] = max > 1 ? loadESLintThreaded(max, options) : loadESLint(options); | ||
if (!cache[cacheKey]) { | ||
cache[cacheKey] = max > 1 ? loadESLintThreaded(key, max, options) : loadESLint(options); | ||
} | ||
return cache[key]; | ||
return cache[cacheKey]; | ||
} | ||
/** | ||
* @param {string|undefined} key | ||
* @param {Options} options | ||
@@ -156,4 +159,7 @@ * @returns {string} | ||
function getCacheKey(options) { | ||
return JSON.stringify(options, _utils.jsonStringifyReplacerSortKeys); | ||
function getCacheKey(key, options) { | ||
return JSON.stringify({ | ||
key, | ||
options | ||
}, _utils.jsonStringifyReplacerSortKeys); | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.ESLintWebpackPlugin = void 0; | ||
exports.default = void 0; | ||
@@ -13,3 +13,3 @@ var _path = require("path"); | ||
var _micromatch = _interopRequireDefault(require("micromatch")); | ||
var _micromatch = require("micromatch"); | ||
@@ -24,2 +24,4 @@ var _options = require("./options"); | ||
// @ts-ignore | ||
/** @typedef {import('webpack').Compiler} Compiler */ | ||
@@ -29,2 +31,3 @@ | ||
const ESLINT_PLUGIN = 'ESLintWebpackPlugin'; | ||
let counter = 0; | ||
@@ -46,2 +49,7 @@ class ESLintWebpackPlugin { | ||
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) { | ||
@@ -55,3 +63,11 @@ compiler.hooks.run.tapPromise(ESLINT_PLUGIN, this.run); | ||
compiler.hooks.watchRun.tapPromise(ESLINT_PLUGIN, this.run); | ||
let isFirstRun = this.options.lintDirtyModulesOnly; | ||
compiler.hooks.watchRun.tapPromise(ESLINT_PLUGIN, c => { | ||
if (isFirstRun) { | ||
isFirstRun = false; | ||
return Promise.resolve(); | ||
} | ||
return this.run(c); | ||
}); | ||
} | ||
@@ -91,25 +107,32 @@ /** | ||
report | ||
} = (0, _linter.default)(options, compilation)); | ||
} = (0, _linter.default)(this.key, options, compilation)); | ||
} catch (e) { | ||
compilation.errors.push(e); | ||
return; | ||
} // @ts-ignore | ||
} // Gather Files to lint | ||
const processModule = module => { | ||
if (module.resource) { | ||
const file = module.resource.split('?')[0]; | ||
compilation.hooks.finishModules.tap(ESLINT_PLUGIN, modules => { | ||
/** @type {string[]} */ | ||
const files = []; // @ts-ignore | ||
if (file && _micromatch.default.isMatch(file, wanted) && !_micromatch.default.isMatch(file, exclude)) { | ||
// Queue file for linting. | ||
lint(file); | ||
for (const { | ||
resource | ||
} of modules) { | ||
if (resource) { | ||
const [file] = resource.split('?'); | ||
if (file && !files.includes(file) && (0, _micromatch.isMatch)(file, wanted) && !(0, _micromatch.isMatch)(file, exclude)) { | ||
files.push(file); | ||
} | ||
} | ||
} | ||
}; // Gather Files to lint | ||
if (files.length > 0) { | ||
lint(files); | ||
} | ||
}); // await and interpret results | ||
compilation.hooks.succeedModule.tap(ESLINT_PLUGIN, processModule); // await and interpret results | ||
compilation.hooks.additionalAssets.tapPromise(ESLINT_PLUGIN, processResults); | ||
compilation.hooks.afterSeal.tapPromise(ESLINT_PLUGIN, processResults); | ||
async function processResults() { | ||
@@ -122,8 +145,11 @@ const { | ||
if (warnings) { | ||
if (warnings && !options.failOnWarning) { | ||
// @ts-ignore | ||
compilation.warnings.push(warnings); | ||
} else if (warnings && options.failOnWarning) { | ||
// @ts-ignore | ||
compilation.errors.push(warnings); | ||
} | ||
if (errors) { | ||
if (errors && options.failOnError) { | ||
// @ts-ignore | ||
@@ -160,4 +186,3 @@ compilation.errors.push(errors); | ||
exports.ESLintWebpackPlugin = ESLintWebpackPlugin; | ||
var _default = ESLintWebpackPlugin; | ||
exports.default = _default; |
@@ -45,2 +45,3 @@ "use strict"; | ||
/** | ||
* @param {string|undefined} key | ||
* @param {Options} options | ||
@@ -51,3 +52,3 @@ * @param {Compilation} compilation | ||
function linter(options, compilation) { | ||
function linter(key, options, compilation) { | ||
/** @type {ESLint} */ | ||
@@ -71,3 +72,3 @@ let eslint; | ||
cleanup | ||
} = (0, _getESLint.default)(options)); | ||
} = (0, _getESLint.default)(key, options)); | ||
} catch (e) { | ||
@@ -117,9 +118,2 @@ throw new _ESLintError.default(e.message); | ||
} = formatResults(formatter, parseResults(options, results)); | ||
if (options.failOnError && errors) { | ||
throw errors; | ||
} else if (options.failOnWarning && warnings) { | ||
throw warnings; | ||
} | ||
return { | ||
@@ -140,5 +134,11 @@ errors, | ||
outputReport | ||
} = options; // @ts-ignore | ||
} = options; | ||
/** | ||
* @param {string} name | ||
* @param {string | Buffer} content | ||
*/ | ||
const save = (name, content) => new Promise((finish, bail) => { | ||
const save = (name, content) => | ||
/** @type {Promise<void>} */ | ||
new Promise((finish, bail) => { | ||
const { | ||
@@ -154,7 +154,6 @@ mkdir, | ||
/* istanbul ignore if */ | ||
if (err) bail(err); // @ts-ignore | ||
else writeFile(name, content, err2 => { | ||
/* istanbul ignore if */ | ||
if (err2) bail(err2);else finish(); | ||
}); | ||
if (err) bail(err);else writeFile(name, content, err2 => { | ||
/* istanbul ignore if */ | ||
if (err2) bail(err2);else finish(); | ||
}); | ||
}); | ||
@@ -213,20 +212,27 @@ }); | ||
/** @type {LintResult[]} */ | ||
let errors = []; | ||
const errors = []; | ||
/** @type {LintResult[]} */ | ||
let warnings = []; | ||
const warnings = []; | ||
results.forEach(file => { | ||
if (fileHasErrors(file)) { | ||
const messages = file.messages.filter(message => options.emitError && message.severity === 2); | ||
if (options.emitError) { | ||
errors = results.filter(file => fileHasErrors(file) || fileHasWarnings(file)); | ||
} else if (options.emitWarning) { | ||
warnings = results.filter(file => fileHasErrors(file) || fileHasWarnings(file)); | ||
} else { | ||
warnings = results.filter(file => !fileHasErrors(file) && fileHasWarnings(file)); | ||
errors = results.filter(fileHasErrors); | ||
} | ||
if (messages.length > 0) { | ||
errors.push({ ...file, | ||
messages | ||
}); | ||
} | ||
} | ||
if (options.quiet && warnings.length > 0) { | ||
warnings = []; | ||
} | ||
if (fileHasWarnings(file)) { | ||
const messages = file.messages.filter(message => options.emitWarning && message.severity === 1); | ||
if (messages.length > 0) { | ||
warnings.push({ ...file, | ||
messages | ||
}); | ||
} | ||
} | ||
}); | ||
return { | ||
@@ -233,0 +239,0 @@ errors, |
@@ -15,2 +15,4 @@ "use strict"; | ||
// @ts-ignore | ||
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */ | ||
@@ -63,3 +65,10 @@ | ||
extensions: 'js', | ||
...pluginOptions | ||
emitError: true, | ||
emitWarning: true, | ||
failOnError: true, | ||
...pluginOptions, | ||
...(pluginOptions.quiet ? { | ||
emitError: true, | ||
emitWarning: false | ||
} : {}) | ||
}; // @ts-ignore | ||
@@ -93,6 +102,5 @@ | ||
delete eslintOptions[option]; | ||
} // @ts-ignore | ||
} | ||
return eslintOptions; | ||
} |
@@ -10,7 +10,7 @@ { | ||
"emitError": { | ||
"description": "Will always return errors, if set to `true`.", | ||
"description": "The errors found will always be emitted, to disable set to `false`.", | ||
"type": "boolean" | ||
}, | ||
"emitWarning": { | ||
"description": "Will always return warnings, if set to `true`.", | ||
"description": "The warnings found will always be emitted, to disable set to `false`.", | ||
"type": "boolean" | ||
@@ -27,3 +27,3 @@ }, | ||
"failOnError": { | ||
"description": "Will cause the module build to fail if there are any errors, if set to `true`.", | ||
"description": "Will cause the module build to fail if there are any errors, to disable set to `false`.", | ||
"type": "boolean" | ||
@@ -30,0 +30,0 @@ }, |
@@ -17,2 +17,3 @@ "use strict"; | ||
// @ts-ignore | ||
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g; | ||
@@ -26,3 +27,5 @@ /** | ||
function parseFiles(files, context) { | ||
return (0, _arrify.default)(files).map(file => `${replaceBackslashes(context).replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2')}/${replaceBackslashes(file)}`); | ||
return (0, _arrify.default)(files).map( | ||
/** @type {string} */ | ||
file => `${replaceBackslashes(context).replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2')}/${replaceBackslashes(file)}`); | ||
} | ||
@@ -48,4 +51,10 @@ /** | ||
const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', '']; | ||
const extensionsGlob = extensionsList.map(extension => extension.replace(/^\./u, '')).join(','); | ||
return (0, _arrify.default)(patterns).map(pattern => replaceBackslashes(pattern)).map(pattern => { | ||
const extensionsGlob = extensionsList.map( | ||
/** @type {string} */ | ||
extension => extension.replace(/^\./u, '')).join(','); | ||
return (0, _arrify.default)(patterns).map( | ||
/** @type {string} */ | ||
pattern => replaceBackslashes(pattern)).map( | ||
/** @type {string} */ | ||
pattern => { | ||
try { | ||
@@ -52,0 +61,0 @@ // The patterns are absolute because they are prepended with the context. |
{ | ||
"name": "eslint-webpack-plugin", | ||
"version": "2.4.3", | ||
"version": "2.5.0", | ||
"description": "A ESLint plugin for webpack", | ||
@@ -49,3 +49,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/eslint": "^7.2.4", | ||
"@types/eslint": "^7.2.6", | ||
"arrify": "^2.0.1", | ||
@@ -57,29 +57,29 @@ "jest-worker": "^26.6.2", | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.1", | ||
"@babel/core": "^7.12.3", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@types/fs-extra": "^9.0.4", | ||
"@types/fs-extra": "^9.0.6", | ||
"@types/micromatch": "^4.0.1", | ||
"@types/webpack": "^4.41.25", | ||
"@types/webpack": "^4.41.26", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^26.6.3", | ||
"chokidar": "^3.4.3", | ||
"cross-env": "^7.0.2", | ||
"chokidar": "^3.5.1", | ||
"cross-env": "^7.0.3", | ||
"del": "^6.0.0", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"fs-extra": "^9.0.1", | ||
"husky": "^4.3.0", | ||
"fs-extra": "^9.1.0", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"lint-staged": "^10.5.3", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.1.2", | ||
"standard-version": "^9.0.0", | ||
"typescript": "^4.0.5", | ||
"webpack": "^5.15.0" | ||
"prettier": "^2.2.1", | ||
"standard-version": "^9.1.0", | ||
"typescript": "^4.1.3", | ||
"webpack": "^5.19.0" | ||
}, | ||
@@ -86,0 +86,0 @@ "keywords": [ |
@@ -162,3 +162,3 @@ <div align="center"> | ||
#### `threads` | ||
### `threads` | ||
@@ -178,5 +178,5 @@ - Type: `Boolean | Number` | ||
- Type: `Boolean` | ||
- Default: `false` | ||
- Default: `true` | ||
Will always return errors, if set to `true`. | ||
The errors found will always be emitted, to disable set to `false`. | ||
@@ -186,5 +186,5 @@ #### `emitWarning` | ||
- Type: `Boolean` | ||
- Default: `false` | ||
- Default: `true` | ||
Will always return warnings, if set to `true`. | ||
The warnings found will always be emitted, to disable set to `false`. | ||
@@ -194,5 +194,5 @@ #### `failOnError` | ||
- Type: `Boolean` | ||
- Default: `false` | ||
- Default: `true` | ||
Will cause the module build to fail if there are any errors, if set to `true`. | ||
Will cause the module build to fail if there are any errors, to disable set to `false`. | ||
@@ -199,0 +199,0 @@ #### `failOnWarning` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51548
1054
Updated@types/eslint@^7.2.6