From 40151be78e6e1a98c2664c4d60f1e9c926b70945 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Wed, 31 Jul 2024 10:37:05 +0300 Subject: [PATCH] refactor: improve code --- bin/webpack.js | 8 ++--- eslint.config.js | 36 ++++++++++++++++++- lib/Compilation.js | 28 +++++++-------- lib/Compiler.js | 10 +++--- lib/DllReferencePlugin.js | 7 ++-- lib/FileSystemInfo.js | 16 ++++----- lib/NormalModule.js | 10 +++--- lib/NormalModuleFactory.js | 8 ++--- lib/RuntimeModule.js | 2 +- lib/asset/AssetModulesPlugin.js | 6 ++-- lib/cache/PackFileCacheStrategy.js | 24 ++++++------- lib/config/defaults.js | 10 +++--- lib/css/CssModulesPlugin.js | 6 ++-- lib/css/CssParser.js | 2 +- lib/debug/ProfilingPlugin.js | 6 ++-- .../JavascriptHotModuleReplacement.runtime.js | 6 ++-- lib/javascript/JavascriptModulesPlugin.js | 18 +++++----- lib/javascript/JavascriptParser.js | 16 ++++----- lib/json/JsonParser.js | 6 ++-- lib/optimize/ConcatenatedModule.js | 6 ++-- lib/rules/RuleSetCompiler.js | 2 +- lib/schemes/HttpUriPlugin.js | 2 +- lib/serialization/ObjectMiddleware.js | 24 ++++++------- lib/sharing/utils.js | 6 ++-- lib/util/fs.js | 4 +-- .../AsyncWebAssemblyModulesPlugin.js | 6 ++-- package.json | 1 + setup/setup.js | 6 ++-- test/BannerPlugin.test.js | 6 ++-- test/BenchmarkTestCases.benchmark.js | 6 ++-- test/ConfigTestCases.template.js | 6 ++-- test/HotModuleReplacementPlugin.test.js | 16 ++++----- test/JavascriptParser.unittest.js | 2 +- test/MemoryLimitTestCases.test.js | 2 +- test/MultiCompiler.test.js | 12 +++---- test/MultiStats.test.js | 4 +-- test/StatsTestCases.basictest.js | 2 +- test/TestCases.template.js | 8 ++--- test/WatchDetection.test.js | 8 ++--- test/WatchSuspend.test.js | 8 ++--- test/WatchTestCases.template.js | 2 +- .../asset-modules/http-url/test.config.js | 4 +-- test/configCases/clean/link/test.filter.js | 2 +- .../css/webpack.config.js | 4 +-- .../no-source-map/webpack.config.js | 6 ++-- test/helpers/createLazyTestEnv.js | 6 ++-- test/helpers/supportDefaultAssignment.js | 2 +- .../supportsArrowFunctionExpression.js | 2 +- test/helpers/supportsBlockScoping.js | 2 +- test/helpers/supportsClassFields.js | 2 +- test/helpers/supportsClassStaticBlock.js | 2 +- test/helpers/supportsDefaultArgs.js | 2 +- test/helpers/supportsES6.js | 2 +- test/helpers/supportsForOf.js | 2 +- test/helpers/supportsIteratorDestructuring.js | 2 +- test/helpers/supportsLogicalAssignment.js | 2 +- test/helpers/supportsNullishCoalescing.js | 2 +- test/helpers/supportsObjectDestructuring.js | 2 +- test/helpers/supportsOptionalCatchBinding.js | 2 +- test/helpers/supportsOptionalChaining.js | 2 +- test/helpers/supportsSpread.js | 2 +- test/helpers/supportsTemplateStrings.js | 2 +- test/helpers/supportsWebAssembly.js | 2 +- test/helpers/warmup-webpack.js | 4 +-- test/setupTestFramework.js | 8 ++--- 65 files changed, 236 insertions(+), 196 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 5f4e23781..cbb748f7e 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -80,8 +80,8 @@ const runCli = cli => { if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) { import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch( - error => { - console.error(error); + err => { + console.error(err); process.exitCode = 1; } ); @@ -177,8 +177,8 @@ if (!cli.installed) { .then(() => { runCli(cli); }) - .catch(error => { - console.error(error); + .catch(err => { + console.error(err); process.exitCode = 1; }); }); diff --git a/eslint.config.js b/eslint.config.js index fd135fb68..601f02d44 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -6,6 +6,7 @@ const jsdoc = require("eslint-plugin-jsdoc"); const prettierConfig = require("eslint-config-prettier"); const globals = require("globals"); const stylistic = require("@stylistic/eslint-plugin"); +const unicorn = require("eslint-plugin-unicorn"); const nodeConfig = n.configs["flat/recommended"]; const jsdocConfig = jsdoc.configs["flat/recommended-typescript-flavor-error"]; @@ -78,7 +79,7 @@ module.exports = [ varsIgnorePattern: "^_", args: "none", argsIgnorePattern: "^_", - caughtErrors: "none", + caughtErrors: "all", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true } @@ -197,9 +198,42 @@ module.exports = [ "prefer-spread": "error", "no-sequences": "error", // TODO Enable + "id-length": "off", "prefer-destructuring": "off" } }, + { + plugins: { + unicorn + }, + rules: { + "unicorn/catch-error-name": [ + "error", + { name: "err", ignore: [/(^_|[0-9]+$)/i] } + ], + // TODO Enable + "unicorn/prefer-spread": "off", + "unicorn/prefer-string-slice": "off", + "unicorn/explicit-length-check": "off", + "unicorn/no-lonely-if": "off", + "unicorn/prefer-ternary": "off", + "unicorn/no-useless-undefined": "off", + "unicorn/no-hex-escape": "off", + "unicorn/escape-case": "off", + "unicorn/prefer-negative-index": "off", + "unicorn/no-array-for-each": "off", + "unicorn/prefer-number-properties": "off", + "unicorn/prefer-default-parameters": "off", + "unicorn/prefer-regexp-test": "off", + "unicorn/prefer-includes": "off", + "unicorn/prefer-math-trunc": "off", + "unicorn/prefer-array-find": "off", + "unicorn/prefer-native-coercion-functions": "off", + "unicorn/no-useless-switch-case": "off", + "unicorn/prefer-string-starts-ends-with": "off", + "unicorn/no-zero-fractions": "off" + } + }, { plugins: { "@stylistic": stylistic diff --git a/lib/Compilation.js b/lib/Compilation.js index b07d09bce..20503fbf3 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -483,8 +483,8 @@ class Compilation { fn: (assets, callback) => { try { fn(assets); - } catch (e) { - return callback(e); + } catch (err) { + return callback(err); } if (processedAssets !== undefined) processedAssets.add(this.assets); @@ -1644,8 +1644,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si }); return; } - } catch (e) { - console.error(e); + } catch (err) { + console.error(err); } } processDependencyForResolving(dep); @@ -1737,8 +1737,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si for (const b of block.blocks) queue.push(b); } } while (queue.length !== 0); - } catch (e) { - return callback(e); + } catch (err) { + return callback(err); } if (--inProgressSorting === 0) onDependenciesSorted(); @@ -5240,14 +5240,14 @@ This prevents using hashes of each other and should be avoided.`); ); moduleObject.loaded = true; return moduleObject.exports; - } catch (e) { + } catch (execErr) { if (strictModuleExceptionHandling) { if (id) delete moduleCache[id]; } else if (strictModuleErrorHandling) { - moduleObject.error = e; + moduleObject.error = execErr; } - if (!e.module) e.module = module; - throw e; + if (!execErr.module) execErr.module = module; + throw execErr; } }; @@ -5260,14 +5260,14 @@ This prevents using hashes of each other and should be avoided.`); ); } exports = __webpack_require__(module.identifier()); - } catch (e) { + } catch (execErr) { const err = new WebpackError( `Execution of module code from module graph (${module.readableIdentifier( this.requestShortener - )}) failed: ${e.message}` + )}) failed: ${execErr.message}` ); - err.stack = e.stack; - err.module = e.module; + err.stack = execErr.stack; + err.module = execErr.module; return callback(err); } diff --git a/lib/Compiler.js b/lib/Compiler.js index ab9fc51e7..75b82d5aa 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -619,11 +619,11 @@ class Compiler { const finalCallback = (err, entries, compilation) => { try { callback(err, entries, compilation); - } catch (e) { + } catch (runAsChildErr) { const err = new WebpackError( - `compiler.runAsChild callback error: ${e}` + `compiler.runAsChild callback error: ${runAsChildErr}` ); - err.details = /** @type {Error} */ (e).stack; + err.details = /** @type {Error} */ (runAsChildErr).stack; /** @type {Compilation} */ (this.parentCompilation).errors.push(err); } @@ -1137,10 +1137,10 @@ ${other}`); this.records = parseJson( /** @type {Buffer} */ (content).toString("utf-8") ); - } catch (e) { + } catch (parseErr) { return callback( new Error( - `Cannot parse records: ${/** @type {Error} */ (e).message}` + `Cannot parse records: ${/** @type {Error} */ (parseErr).message}` ) ); } diff --git a/lib/DllReferencePlugin.js b/lib/DllReferencePlugin.js index 58039aac8..f8b8ab890 100644 --- a/lib/DllReferencePlugin.js +++ b/lib/DllReferencePlugin.js @@ -75,7 +75,7 @@ class DllReferencePlugin { data.data = parseJson( /** @type {Buffer} */ (result).toString("utf-8") ); - } catch (e) { + } catch (parseErr) { // Store the error in the params so that it can // be added as a compilation error later on. const manifestPath = makePathsRelative( @@ -83,7 +83,10 @@ class DllReferencePlugin { manifest, compiler.root ); - data.error = new DllManifestError(manifestPath, e.message); + data.error = new DllManifestError( + manifestPath, + parseErr.message + ); } this._compilationData.set(params, data); return callback(); diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index 24b9e64f3..73eefa45e 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -1770,7 +1770,7 @@ class FileSystemInfo { expected: imp.d > -1 ? false : undefined, issuer: job }); - } catch (e) { + } catch (err1) { this.logger.warn( `Parsing of ${path} for build dependencies failed at 'import(${source.substring( imp.s, @@ -1779,15 +1779,15 @@ class FileSystemInfo { "Build dependencies behind this expression are ignored and might cause incorrect cache invalidation." ); this.logger.debug(pathToString(job)); - this.logger.debug(e.stack); + this.logger.debug(err1.stack); } } - } catch (e) { + } catch (err2) { this.logger.warn( `Parsing of ${path} for build dependencies failed and all dependencies of this file are ignored, which might cause incorrect cache invalidation..` ); this.logger.debug(pathToString(job)); - this.logger.debug(e.stack); + this.logger.debug(err2.stack); } process.nextTick(callback); }); @@ -1830,8 +1830,8 @@ class FileSystemInfo { let packageData; try { packageData = JSON.parse(content.toString("utf-8")); - } catch (e) { - return callback(e); + } catch (parseErr) { + return callback(parseErr); } const depsObject = packageData.dependencies; const optionalDepsObject = packageData.optionalDependencies; @@ -3616,8 +3616,8 @@ class FileSystemInfo { let data; try { data = JSON.parse(/** @type {Buffer} */ (content).toString("utf-8")); - } catch (e) { - return callback(e); + } catch (parseErr) { + return callback(parseErr); } if (!data.name) { /** @type {Logger} */ diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 988c6e297..f8e55798e 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -615,8 +615,8 @@ class NormalModule extends Module { if (options.startsWith("{") && options.endsWith("}")) { try { options = parseJson(options); - } catch (e) { - throw new Error(`Cannot parse string options: ${e.message}`); + } catch (err) { + throw new Error(`Cannot parse string options: ${err.message}`); } } else { options = querystring.parse(options, "&", "=", { @@ -1161,7 +1161,7 @@ class NormalModule extends Module { : deps ).add(absolute); } - } catch (e) { + } catch (_err) { // ignore } } @@ -1237,8 +1237,8 @@ class NormalModule extends Module { compilation, options }); - } catch (e) { - handleParseError(/** @type {Error} */ (e)); + } catch (parseErr) { + handleParseError(/** @type {Error} */ (parseErr)); return; } handleParseResult(); diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 0a166eb30..4cdbff5e3 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -535,8 +535,8 @@ class NormalModuleFactory extends ModuleFactory { item.ident = ident; } } - } catch (e) { - return callback(/** @type {Error} */ (e)); + } catch (identErr) { + return callback(/** @type {Error} */ (identErr)); } if (!resourceData) { @@ -685,8 +685,8 @@ class NormalModuleFactory extends ModuleFactory { generatorOptions: settings.generator, resolveOptions }); - } catch (e) { - return callback(/** @type {Error} */ (e)); + } catch (createDataErr) { + return callback(/** @type {Error} */ (createDataErr)); } callback(); }); diff --git a/lib/RuntimeModule.js b/lib/RuntimeModule.js index d1ae314b0..34ca2c19b 100644 --- a/lib/RuntimeModule.js +++ b/lib/RuntimeModule.js @@ -159,7 +159,7 @@ class RuntimeModule extends Module { try { const source = this.getGeneratedCode(); return source ? source.length : 0; - } catch (e) { + } catch (_err) { return 0; } } diff --git a/lib/asset/AssetModulesPlugin.js b/lib/asset/AssetModulesPlugin.js index 5a49989d3..56442f09a 100644 --- a/lib/asset/AssetModulesPlugin.js +++ b/lib/asset/AssetModulesPlugin.js @@ -207,10 +207,10 @@ class AssetModulesPlugin { module.buildInfo.fullContentHash || codeGenResult.data.get("fullContentHash") }); - } catch (e) { - /** @type {Error} */ (e).message += + } catch (err) { + /** @type {Error} */ (err).message += `\nduring rendering of asset ${module.identifier()}`; - throw e; + throw err; } } } diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index 0921f45d7..7958be36a 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -676,16 +676,16 @@ class PackContentItems { logger.log(`Serialization of '${key}': ${duration} ms`); else logger.debug(`Serialization of '${key}': ${duration} ms`); } - } catch (e) { + } catch (err) { rollback(s); - if (e === NOT_SERIALIZABLE) continue; + if (err === NOT_SERIALIZABLE) continue; const msg = "Skipped not serializable cache item"; - if (e.message.includes("ModuleBuildError")) { - logger.log(`${msg} (in build error): ${e.message}`); - logger.debug(`${msg} '${key}' (in build error): ${e.stack}`); + if (err.message.includes("ModuleBuildError")) { + logger.log(`${msg} (in build error): ${err.message}`); + logger.debug(`${msg} '${key}' (in build error): ${err.stack}`); } else { - logger.warn(`${msg}: ${e.message}`); - logger.debug(`${msg} '${key}': ${e.stack}`); + logger.warn(`${msg}: ${err.message}`); + logger.debug(`${msg} '${key}': ${err.stack}`); } } } @@ -697,7 +697,7 @@ class PackContentItems { try { write(true); write(this.map); - } catch (e) { + } catch (_err) { rollback(s); // Try to serialize each item on it's own @@ -707,13 +707,13 @@ class PackContentItems { try { write(key); write(value); - } catch (e) { + } catch (err) { rollback(s); - if (e === NOT_SERIALIZABLE) continue; + if (err === NOT_SERIALIZABLE) continue; logger.warn( - `Skipped not serializable cache item '${key}': ${e.message}` + `Skipped not serializable cache item '${key}': ${err.message}` ); - logger.debug(e.stack); + logger.debug(err.stack); } } write(null); diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 921858764..c1341fa29 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -411,7 +411,7 @@ const applyCacheDefaults = ( try { if (fs.statSync(path.join(dir, "package.json")).isFile()) break; // eslint-disable-next-line no-empty - } catch (e) {} + } catch (_err) {} const parent = path.dirname(dir); if (dir === parent) { dir = undefined; @@ -908,12 +908,12 @@ const applyOutputDefaults = ( try { const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8")); return packageInfo.name || ""; - } catch (e) { - if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") { + } catch (err) { + if (/** @type {Error & { code: string }} */ (err).code !== "ENOENT") { /** @type {Error & { code: string }} */ - (e).message += + (err).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`; - throw e; + throw err; } return ""; } diff --git a/lib/css/CssModulesPlugin.js b/lib/css/CssModulesPlugin.js index 8278ae040..36f9fcd0b 100644 --- a/lib/css/CssModulesPlugin.js +++ b/lib/css/CssModulesPlugin.js @@ -758,10 +758,10 @@ class CssModulesPlugin { module }); source.add(moduleSource); - } catch (e) { + } catch (err) { /** @type {Error} */ - (e).message += `\nduring rendering of css ${module.identifier()}`; - throw e; + (err).message += `\nduring rendering of css ${module.identifier()}`; + throw err; } } const metaDataStr = metaData.join(","); diff --git a/lib/css/CssParser.js b/lib/css/CssParser.js index 0e31c8d74..2a6b3cbe5 100644 --- a/lib/css/CssParser.js +++ b/lib/css/CssParser.js @@ -73,7 +73,7 @@ const normalizeUrl = (str, isString) => { // Convert `url('%2E/img.png')` -> `url('./img.png')` try { str = decodeURIComponent(str); - } catch (error) { + } catch (_err) { // Ignore } } diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index cb0db5e58..8291efd3c 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -41,7 +41,7 @@ let inspector; try { // eslint-disable-next-line n/no-unsupported-features/node-builtins inspector = require("inspector"); -} catch (e) { +} catch (_err) { console.log("Unable to CPU profile in < node 8.0"); } @@ -474,13 +474,13 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => { let r; try { r = fn(...args); - } catch (error) { + } catch (err) { tracer.trace.end({ name, id, cat: defaultCategory }); - throw error; + throw err; } tracer.trace.end({ name, diff --git a/lib/hmr/JavascriptHotModuleReplacement.runtime.js b/lib/hmr/JavascriptHotModuleReplacement.runtime.js index c16c872c0..baa4f7012 100644 --- a/lib/hmr/JavascriptHotModuleReplacement.runtime.js +++ b/lib/hmr/JavascriptHotModuleReplacement.runtime.js @@ -376,17 +376,17 @@ module.exports = function () { moduleId: moduleId, module: $moduleCache$[moduleId] }); - } catch (err2) { + } catch (err1) { if (options.onErrored) { options.onErrored({ type: "self-accept-error-handler-errored", moduleId: moduleId, - error: err2, + error: err1, originalError: err }); } if (!options.ignoreErrored) { - reportError(err2); + reportError(err1); reportError(err); } } diff --git a/lib/javascript/JavascriptModulesPlugin.js b/lib/javascript/JavascriptModulesPlugin.js index 19b4c3e2f..3a74c1434 100644 --- a/lib/javascript/JavascriptModulesPlugin.js +++ b/lib/javascript/JavascriptModulesPlugin.js @@ -448,12 +448,12 @@ class JavascriptModulesPlugin { moduleObject.exports, context.__webpack_require__ ); - } catch (e) { - e.stack += printGeneratedCodeForStack( + } catch (err) { + err.stack += printGeneratedCodeForStack( options.module, /** @type {string} */ (code) ); - throw e; + throw err; } }); compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => { @@ -472,9 +472,9 @@ class JavascriptModulesPlugin { try { // eslint-disable-next-line no-useless-call fn.call(null, context.__webpack_require__); - } catch (e) { - e.stack += printGeneratedCodeForStack(options.module, code); - throw e; + } catch (err) { + err.stack += printGeneratedCodeForStack(options.module, code); + throw err; } }); } @@ -603,9 +603,9 @@ class JavascriptModulesPlugin { ), "JavascriptModulesPlugin.getCompilationHooks().renderModulePackage" ); - } catch (e) { - e.module = module; - throw e; + } catch (err) { + err.module = module; + throw err; } } diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 252e3e40c..4c60371f3 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -4056,8 +4056,8 @@ class JavascriptParser extends Parser { return result; } } - } catch (e) { - console.warn(e); + } catch (err) { + console.warn(err); // ignore error } return new BasicEvaluatedExpression() @@ -4594,9 +4594,9 @@ class JavascriptParser extends Parser { } options[key] = val; } - } catch (e) { - const newErr = new Error(String(e.message)); - newErr.stack = String(e.stack); + } catch (err) { + const newErr = new Error(String(err.message)); + newErr.stack = String(err.stack); Object.assign(newErr, { comment }); errors.push(newErr); } @@ -4749,8 +4749,8 @@ class JavascriptParser extends Parser { let threw = false; try { ast = /** @type {AnyNode} */ (parser.parse(code, parserOptions)); - } catch (e) { - error = e; + } catch (err) { + error = err; threw = true; } @@ -4765,7 +4765,7 @@ class JavascriptParser extends Parser { try { ast = /** @type {AnyNode} */ (parser.parse(code, parserOptions)); threw = false; - } catch (e) { + } catch (_err) { // we use the error from first parse try // so nothing to do here } diff --git a/lib/json/JsonParser.js b/lib/json/JsonParser.js index a68662e77..5466fa3d5 100644 --- a/lib/json/JsonParser.js +++ b/lib/json/JsonParser.js @@ -50,8 +50,10 @@ class JsonParser extends Parser { typeof source === "object" ? source : parseFn(source[0] === "\ufeff" ? source.slice(1) : source); - } catch (e) { - throw new Error(`Cannot parse JSON: ${/** @type {Error} */ (e).message}`); + } catch (err) { + throw new Error( + `Cannot parse JSON: ${/** @type {Error} */ (err).message}` + ); } const jsonData = new JsonData(/** @type {Buffer | RawJsonData} */ (data)); const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo); diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index cc08b9f88..649d74ee0 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -1488,11 +1488,11 @@ class ConcatenatedModule extends Module { return `/* ${ exportInfo.isReexport() ? "reexport" : "binding" } */ ${finalName}`; - } catch (e) { + } catch (err) { /** @type {Error} */ - (e).message += + (err).message += `\nwhile generating the root export '${name}' (used name: '${used}')`; - throw e; + throw err; } }); } diff --git a/lib/rules/RuleSetCompiler.js b/lib/rules/RuleSetCompiler.js index f63701a2d..bc706b90b 100644 --- a/lib/rules/RuleSetCompiler.js +++ b/lib/rules/RuleSetCompiler.js @@ -236,7 +236,7 @@ class RuleSetCompiler { matchWhenEmpty: condition(""), fn: condition }; - } catch (err) { + } catch (_err) { throw this.error( path, condition, diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index d8e7e5e8b..4f3805a4a 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -938,7 +938,7 @@ Remove this line from the lockfile to force upgrading.` contentWithChangedEol, entry.integrity ); - } catch (e) { + } catch (_err) { // ignore } if (isEolChanged) { diff --git a/lib/serialization/ObjectMiddleware.js b/lib/serialization/ObjectMiddleware.js index 59a035e31..ba6b2084f 100644 --- a/lib/serialization/ObjectMiddleware.js +++ b/lib/serialization/ObjectMiddleware.js @@ -383,7 +383,7 @@ class ObjectMiddleware extends SerializerMiddleware { if (request) { return `${request}${name ? `.${name}` : ""}`; } - } catch (e) { + } catch (_err) { // ignore -> fallback } if (typeof item === "object" && item !== null) { @@ -406,8 +406,8 @@ class ObjectMiddleware extends SerializerMiddleware { } try { return `${item}`; - } catch (e) { - return `(${e.message})`; + } catch (err) { + return `(${err.message})`; } }) .join(" -> "); @@ -417,16 +417,16 @@ class ObjectMiddleware extends SerializerMiddleware { write(value, key) { try { process(value); - } catch (e) { - if (e !== NOT_SERIALIZABLE) { + } catch (err) { + if (err !== NOT_SERIALIZABLE) { if (hasDebugInfoAttached === undefined) hasDebugInfoAttached = new WeakSet(); - if (!hasDebugInfoAttached.has(e)) { - e.message += `\nwhile serializing ${stackToString(value)}`; - hasDebugInfoAttached.add(e); + if (!hasDebugInfoAttached.has(err)) { + err.message += `\nwhile serializing ${stackToString(value)}`; + hasDebugInfoAttached.add(err); } } - throw e; + throw err; } }, setCircularReference(ref) { @@ -571,10 +571,10 @@ class ObjectMiddleware extends SerializerMiddleware { process(item); } return result; - } catch (e) { - if (e === NOT_SERIALIZABLE) return null; + } catch (err) { + if (err === NOT_SERIALIZABLE) return null; - throw e; + throw err; } finally { // Get rid of these references to avoid leaking memory // This happens because the optimized code v8 generates diff --git a/lib/sharing/utils.js b/lib/sharing/utils.js index 4554632cd..dc8b19bdc 100644 --- a/lib/sharing/utils.js +++ b/lib/sharing/utils.js @@ -166,7 +166,7 @@ function getCommithash(urlParsed) { try { hash = decodeURIComponent(hash); // eslint-disable-next-line no-empty - } catch (e) {} + } catch (_err) {} if ( extractCommithashByDomain[ @@ -236,7 +236,7 @@ function getVersionFromHash(hash) { function canBeDecoded(str) { try { decodeURIComponent(str); - } catch (e) { + } catch (_err) { return false; } @@ -264,7 +264,7 @@ function getGitUrlVersion(gitUrl) { try { parsed = new URL(gitUrl); // eslint-disable-next-line no-empty - } catch (e) {} + } catch (_err) {} if (!parsed) { return ""; diff --git a/lib/util/fs.js b/lib/util/fs.js index 4fef12eab..f7ca80719 100644 --- a/lib/util/fs.js +++ b/lib/util/fs.js @@ -597,8 +597,8 @@ const readJson = (fs, p, callback) => { let data; try { data = JSON.parse(/** @type {Buffer} */ (buf).toString("utf-8")); - } catch (e) { - return callback(/** @type {Error} */ (e)); + } catch (err1) { + return callback(/** @type {Error} */ (err1)); } return callback(null, data); }); diff --git a/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js b/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js index 6da3c93df..74a612757 100644 --- a/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +++ b/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js @@ -208,9 +208,9 @@ class AsyncWebAssemblyModulesPlugin { hooks.renderModuleContent.call(moduleSource, module, renderContext), "AsyncWebAssemblyModulesPlugin.getCompilationHooks().renderModuleContent" ); - } catch (e) { - /** @type {WebpackError} */ (e).module = module; - throw e; + } catch (err) { + /** @type {WebpackError} */ (err).module = module; + throw err; } } } diff --git a/package.json b/package.json index 2db831ab6..818554f27 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "eslint-plugin-jsdoc": "^48.10.1", "eslint-plugin-n": "^17.8.1", "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-unicorn": "^55.0.0", "file-loader": "^6.0.0", "fork-ts-checker-webpack-plugin": "^9.0.2", "globals": "^15.4.0", diff --git a/setup/setup.js b/setup/setup.js index ba653b2b5..44dae38e2 100644 --- a/setup/setup.js +++ b/setup/setup.js @@ -21,8 +21,8 @@ function setup() { .then(() => { process.exitCode = 0; }) - .catch(e => { - console.error(e); + .catch(err => { + console.error(err); process.exitCode = 1; }); } @@ -54,7 +54,7 @@ async function ensureYarnInstalledAsync() { try { const stdout = await execGetOutput("yarn", ["-v"], "Check yarn version"); hasYarn = semverPattern.test(stdout); - } catch (e) { + } catch (_err) { hasYarn = false; } if (!hasYarn) await installYarnAsync(); diff --git a/test/BannerPlugin.test.js b/test/BannerPlugin.test.js index 69798d28e..335d6b006 100644 --- a/test/BannerPlugin.test.js +++ b/test/BannerPlugin.test.js @@ -16,7 +16,7 @@ it("should cache assets", done => { fs.mkdirSync(path.join(pluginDir), { recursive: true }); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ @@ -53,7 +53,7 @@ it("can place banner as footer", done => { fs.mkdirSync(path.join(pluginDir), { recursive: true }); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ @@ -87,7 +87,7 @@ it("should allow to change stage", done => { fs.mkdirSync(path.join(pluginDir), { recursive: true }); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ diff --git a/test/BenchmarkTestCases.benchmark.js b/test/BenchmarkTestCases.benchmark.js index 6d7f0dd67..a7a8c9ec7 100644 --- a/test/BenchmarkTestCases.benchmark.js +++ b/test/BenchmarkTestCases.benchmark.js @@ -20,10 +20,10 @@ describe("BenchmarkTestCases", function () { try { fs.mkdirSync(path.join(__dirname, "js")); - } catch (e) {} // eslint-disable-line no-empty + } catch (_err) {} // eslint-disable-line no-empty try { fs.mkdirSync(baselinesPath); - } catch (e) {} // eslint-disable-line no-empty + } catch (_err) {} // eslint-disable-line no-empty beforeAll(function (done) { const git = require("simple-git"); @@ -40,7 +40,7 @@ describe("BenchmarkTestCases", function () { } else { try { fs.mkdirSync(baselinePath); - } catch (e) {} // eslint-disable-line no-empty + } catch (_err) {} // eslint-disable-line no-empty const gitIndex = path.resolve(rootPath, ".git/index"); const index = fs.readFileSync(gitIndex); git(rootPath).raw( diff --git a/test/ConfigTestCases.template.js b/test/ConfigTestCases.template.js index f56c2a032..d691f6247 100644 --- a/test/ConfigTestCases.template.js +++ b/test/ConfigTestCases.template.js @@ -154,7 +154,7 @@ const describeCases = config => { testConfig, require(path.join(testDirectory, "test.config.js")) ); - } catch (e) { + } catch (_err) { // ignored } if (testConfig.timeout) setDefaultTimeout(testConfig.timeout); @@ -712,8 +712,8 @@ const describeCases = config => { }); }); }); - } catch (e) { - handleFatalError(e, done); + } catch (err) { + handleFatalError(err, done); } } else { require("..")(options, onCompiled); diff --git a/test/HotModuleReplacementPlugin.test.js b/test/HotModuleReplacementPlugin.test.js index f2e36bf83..548a9be30 100644 --- a/test/HotModuleReplacementPlugin.test.js +++ b/test/HotModuleReplacementPlugin.test.js @@ -36,12 +36,12 @@ describe("HotModuleReplacementPlugin", () => { fs.mkdirSync(path.join(__dirname, "js", "HotModuleReplacementPlugin"), { recursive: true }); - } catch (e) { + } catch (_err) { // empty } try { fs.unlinkSync(recordsFile); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ @@ -107,7 +107,7 @@ describe("HotModuleReplacementPlugin", () => { let firstUpdate; try { fs.mkdirSync(outputPath, { recursive: true }); - } catch (e) { + } catch (_err) { // empty } fs.writeFileSync(entryFile, `${++step}`, "utf-8"); @@ -116,7 +116,7 @@ describe("HotModuleReplacementPlugin", () => { try { fs.statSync(path.join(outputPath, file)); return true; - } catch (err) { + } catch (_err) { return false; } }; @@ -188,12 +188,12 @@ describe("HotModuleReplacementPlugin", () => { const recordsFile = path.join(outputPath, "records.json"); try { fs.mkdirSync(outputPath, { recursive: true }); - } catch (e) { + } catch (_err) { // empty } try { fs.unlinkSync(recordsFile); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ @@ -271,12 +271,12 @@ describe("HotModuleReplacementPlugin", () => { recursive: true } ); - } catch (e) { + } catch (_err) { // empty } try { fs.unlinkSync(recordsFile); - } catch (e) { + } catch (_err) { // empty } const compiler = webpack({ diff --git a/test/JavascriptParser.unittest.js b/test/JavascriptParser.unittest.js index c7bdffb85..cd3644f4f 100644 --- a/test/JavascriptParser.unittest.js +++ b/test/JavascriptParser.unittest.js @@ -155,7 +155,7 @@ describe("JavascriptParser", () => { fgh.sub; fgh; } - } catch (e) { + } catch (err) { fgh.sub; fgh; } diff --git a/test/MemoryLimitTestCases.test.js b/test/MemoryLimitTestCases.test.js index d36647c29..1868eec1d 100644 --- a/test/MemoryLimitTestCases.test.js +++ b/test/MemoryLimitTestCases.test.js @@ -51,7 +51,7 @@ describe("MemoryLimitTestCases", () => { testConfig, require(path.join(base, testName, "test.config.js")) ); - } catch (e) { + } catch (_err) { // ignored } it(`should build ${JSON.stringify(testName)} with heap limit of ${toMiB( diff --git a/test/MultiCompiler.test.js b/test/MultiCompiler.test.js index b3e6e603d..1c7354147 100644 --- a/test/MultiCompiler.test.js +++ b/test/MultiCompiler.test.js @@ -451,9 +451,9 @@ describe("MultiCompiler", function () { setTimeout(() => { compiler.close(done); }, 1000); - } catch (e) { - console.error(e); - done(e); + } catch (err) { + console.error(err); + done(err); } }); }); @@ -530,9 +530,9 @@ describe("MultiCompiler", function () { setTimeout(() => { compiler.close(done); }, 1000); - } catch (e) { - console.error(e); - done(e); + } catch (err) { + console.error(err); + done(err); } }); }); diff --git a/test/MultiStats.test.js b/test/MultiStats.test.js index e36364975..df1265977 100644 --- a/test/MultiStats.test.js +++ b/test/MultiStats.test.js @@ -27,8 +27,8 @@ describe("MultiStats", () => { ); expect(statsObject.children).toHaveLength(2); done(); - } catch (e) { - done(e); + } catch (err) { + done(err); } }); }); diff --git a/test/StatsTestCases.basictest.js b/test/StatsTestCases.basictest.js index 91136aa09..1d0a283fc 100644 --- a/test/StatsTestCases.basictest.js +++ b/test/StatsTestCases.basictest.js @@ -65,7 +65,7 @@ describe("StatsTestCases", () => { testConfig, require(path.join(base, testName, "test.config.js")) ); - } catch (e) { + } catch (_err) { // ignored } diff --git a/test/TestCases.template.js b/test/TestCases.template.js index 1b490f735..08f435d68 100644 --- a/test/TestCases.template.js +++ b/test/TestCases.template.js @@ -447,10 +447,10 @@ const describeCases = config => { } }); cleanups.push(() => (esmContext.it = undefined)); - } catch (e) { - console.log(e); - e.message += `\nwhile parsing ${p}`; - throw e; + } catch (err) { + console.log(err); + err.message += `\nwhile parsing ${p}`; + throw err; } if (esmMode === "unlinked") return esm; return (async () => { diff --git a/test/WatchDetection.test.js b/test/WatchDetection.test.js index 8ba16223e..1d305c568 100644 --- a/test/WatchDetection.test.js +++ b/test/WatchDetection.test.js @@ -41,7 +41,7 @@ describe("WatchDetection", () => { beforeAll(() => { try { fs.mkdirSync(fixturePath); - } catch (e) { + } catch (_err) { // empty } fs.writeFileSync(filePath, "require('./file2')", "utf-8"); @@ -52,17 +52,17 @@ describe("WatchDetection", () => { setTimeout(() => { try { fs.unlinkSync(filePath); - } catch (e) { + } catch (_err) { // empty } try { fs.unlinkSync(file2Path); - } catch (e) { + } catch (_err) { // empty } try { fs.rmdirSync(fixturePath); - } catch (e) { + } catch (_err) { // empty } done(); diff --git a/test/WatchSuspend.test.js b/test/WatchSuspend.test.js index 3f6904d65..5e0d572e4 100644 --- a/test/WatchSuspend.test.js +++ b/test/WatchSuspend.test.js @@ -32,14 +32,14 @@ describe("WatchSuspend", () => { beforeAll(() => { try { fs.mkdirSync(fixturePath); - } catch (e) { + } catch (_err) { // skip } try { fs.writeFileSync(filePath, "'foo'", "utf-8"); fs.writeFileSync(file2Path, "'file2'", "utf-8"); fs.writeFileSync(file3Path, "'file3'", "utf-8"); - } catch (e) { + } catch (_err) { // skip } const webpack = require("../"); @@ -63,12 +63,12 @@ describe("WatchSuspend", () => { compiler = null; try { fs.unlinkSync(filePath); - } catch (e) { + } catch (_err) { // skip } try { fs.rmdirSync(fixturePath); - } catch (e) { + } catch (_err) { // skip } }); diff --git a/test/WatchTestCases.template.js b/test/WatchTestCases.template.js index a131247f6..95c65f4f9 100644 --- a/test/WatchTestCases.template.js +++ b/test/WatchTestCases.template.js @@ -335,7 +335,7 @@ const describeCases = config => { testConfig = require( path.join(testDirectory, "test.config.js") ); - } catch (e) { + } catch (_err) { // empty } diff --git a/test/configCases/asset-modules/http-url/test.config.js b/test/configCases/asset-modules/http-url/test.config.js index 5de02baa8..718aa51dc 100644 --- a/test/configCases/asset-modules/http-url/test.config.js +++ b/test/configCases/asset-modules/http-url/test.config.js @@ -5,14 +5,14 @@ module.exports = { beforeExecute() { try { fs.unlinkSync(path.join(__dirname, "dev-defaults.webpack.lock")); - } catch (e) { + } catch (_err) { // Empty } }, afterExecute() { try { fs.unlinkSync(path.join(__dirname, "dev-defaults.webpack.lock")); - } catch (e) { + } catch (_err) { // Empty } } diff --git a/test/configCases/clean/link/test.filter.js b/test/configCases/clean/link/test.filter.js index abb7722f5..e627dbe19 100644 --- a/test/configCases/clean/link/test.filter.js +++ b/test/configCases/clean/link/test.filter.js @@ -10,7 +10,7 @@ module.exports = () => { ); fs.unlinkSync(path.join(__dirname, ".testlink")); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/configCases/loader-import-module/css/webpack.config.js b/test/configCases/loader-import-module/css/webpack.config.js index 1c3381815..5e6e763f3 100644 --- a/test/configCases/loader-import-module/css/webpack.config.js +++ b/test/configCases/loader-import-module/css/webpack.config.js @@ -60,9 +60,9 @@ module.exports = { expect(auxiliaryFiles).toContain("assets/file.png"); expect(auxiliaryFiles).toContain("assets/file.png?1"); expect(auxiliaryFiles).toContain("assets/file.jpg"); - } catch (e) { + } catch (err) { console.log(stats.toString({ colors: true, orphanModules: true })); - throw e; + throw err; } }) ] diff --git a/test/configCases/source-map/no-source-map/webpack.config.js b/test/configCases/source-map/no-source-map/webpack.config.js index dcffa769f..23d83012d 100644 --- a/test/configCases/source-map/no-source-map/webpack.config.js +++ b/test/configCases/source-map/no-source-map/webpack.config.js @@ -5,9 +5,9 @@ const plugins = [ const result = asset.source.sourceAndMap(); try { expect(result.map).toBe(null); - } catch (e) { - e.message += `\nfor asset ${asset.name}`; - throw e; + } catch (err) { + err.message += `\nfor asset ${asset.name}`; + throw err; } } }); diff --git a/test/helpers/createLazyTestEnv.js b/test/helpers/createLazyTestEnv.js index 5190127f1..aca7860f9 100644 --- a/test/helpers/createLazyTestEnv.js +++ b/test/helpers/createLazyTestEnv.js @@ -60,10 +60,10 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => { state.hasStarted = false; try { fn(); - } catch (e) { + } catch (err) { // avoid leaking memory - e.stack; - throw e; + err.stack; + throw err; } state.currentDescribeBlock = oldCurrentDescribeBlock; state.currentlyRunningTest = oldCurrentlyRunningTest; diff --git a/test/helpers/supportDefaultAssignment.js b/test/helpers/supportDefaultAssignment.js index 4a714a488..58d317b8a 100644 --- a/test/helpers/supportDefaultAssignment.js +++ b/test/helpers/supportDefaultAssignment.js @@ -4,7 +4,7 @@ module.exports = function supportDefaultAssignment() { var E = eval("class E { toString() { return 'default' } }"); var f1 = eval("(function f1({a, b = E}) {return new b().toString();})"); return f1({ a: "test" }) === "default"; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsArrowFunctionExpression.js b/test/helpers/supportsArrowFunctionExpression.js index e325c3360..c60dc2ee9 100644 --- a/test/helpers/supportsArrowFunctionExpression.js +++ b/test/helpers/supportsArrowFunctionExpression.js @@ -4,7 +4,7 @@ module.exports = function supportArrowFunctionExpression() { "var foo = function(fn) {return fn.toString()}; foo(() => {return 'a'})" ); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsBlockScoping.js b/test/helpers/supportsBlockScoping.js index 86f7330c5..b8cba03d7 100644 --- a/test/helpers/supportsBlockScoping.js +++ b/test/helpers/supportsBlockScoping.js @@ -4,7 +4,7 @@ module.exports = function supportsBlockScoping() { "(function f() { const x = 1; if (true) { const x = 2; } return x; })" ); return f() === 1; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsClassFields.js b/test/helpers/supportsClassFields.js index 8b3e2bbc1..ebb848a46 100644 --- a/test/helpers/supportsClassFields.js +++ b/test/helpers/supportsClassFields.js @@ -2,7 +2,7 @@ module.exports = function supportsES6() { try { eval("class A { #field = 1 }"); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsClassStaticBlock.js b/test/helpers/supportsClassStaticBlock.js index e2ec05975..75c891caf 100644 --- a/test/helpers/supportsClassStaticBlock.js +++ b/test/helpers/supportsClassStaticBlock.js @@ -2,7 +2,7 @@ module.exports = function supportsClassStaticBLock() { try { eval("(function f({x, y}) { class Foo { static {} } })"); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsDefaultArgs.js b/test/helpers/supportsDefaultArgs.js index e74cd97ed..0e22c0d1e 100644 --- a/test/helpers/supportsDefaultArgs.js +++ b/test/helpers/supportsDefaultArgs.js @@ -2,7 +2,7 @@ module.exports = function supportsDefaultArgs() { try { var f = eval("(function f(a = 123) { return a; })"); return f() === 123; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsES6.js b/test/helpers/supportsES6.js index 15857d9f5..fc00740a4 100644 --- a/test/helpers/supportsES6.js +++ b/test/helpers/supportsES6.js @@ -2,7 +2,7 @@ module.exports = function supportsES6() { try { eval("class A {}"); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsForOf.js b/test/helpers/supportsForOf.js index 3411344fa..498935bf3 100644 --- a/test/helpers/supportsForOf.js +++ b/test/helpers/supportsForOf.js @@ -2,7 +2,7 @@ module.exports = function supportDefaultAssignment() { try { var f = eval("(function f() { for(var x of ['ok', 'fail']) return x; })"); return f() === "ok"; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsIteratorDestructuring.js b/test/helpers/supportsIteratorDestructuring.js index 8945732f3..62375d8d5 100644 --- a/test/helpers/supportsIteratorDestructuring.js +++ b/test/helpers/supportsIteratorDestructuring.js @@ -2,7 +2,7 @@ module.exports = function supportsIteratorDestructuring() { try { var f = eval("(function f([, x, ...y]) { return x; })"); return f([1, 2]) === 2; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsLogicalAssignment.js b/test/helpers/supportsLogicalAssignment.js index 72a36eafa..7a46156d9 100644 --- a/test/helpers/supportsLogicalAssignment.js +++ b/test/helpers/supportsLogicalAssignment.js @@ -4,7 +4,7 @@ module.exports = function supportsLogicalAssignment() { "(function f() { var x = null; x ??= true; x &&= true; return x ||= false; })" ); return f(); - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsNullishCoalescing.js b/test/helpers/supportsNullishCoalescing.js index 38dfb6d54..2514dedf7 100644 --- a/test/helpers/supportsNullishCoalescing.js +++ b/test/helpers/supportsNullishCoalescing.js @@ -2,7 +2,7 @@ module.exports = function supportsNullishCoalescing() { try { var f = eval("(function f() { return null ?? true; })"); return f(); - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsObjectDestructuring.js b/test/helpers/supportsObjectDestructuring.js index f60fcd520..bd6c32911 100644 --- a/test/helpers/supportsObjectDestructuring.js +++ b/test/helpers/supportsObjectDestructuring.js @@ -2,7 +2,7 @@ module.exports = function supportsObjectDestructuring() { try { var f = eval("(function f({x, y}) { return x + y; })"); return f({ x: 1, y: 2 }) === 3; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsOptionalCatchBinding.js b/test/helpers/supportsOptionalCatchBinding.js index 5fdeeca45..673ee5699 100644 --- a/test/helpers/supportsOptionalCatchBinding.js +++ b/test/helpers/supportsOptionalCatchBinding.js @@ -2,7 +2,7 @@ module.exports = function supportsOptionalCatchBinding() { try { eval("try {} catch {}"); return true; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsOptionalChaining.js b/test/helpers/supportsOptionalChaining.js index bd9df3d7f..36db35d0b 100644 --- a/test/helpers/supportsOptionalChaining.js +++ b/test/helpers/supportsOptionalChaining.js @@ -2,7 +2,7 @@ module.exports = function supportsOptionalChaining() { try { var f = eval("(function f() { return ({a: true}) ?.a })"); return f(); - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsSpread.js b/test/helpers/supportsSpread.js index e2e526f90..fa4072255 100644 --- a/test/helpers/supportsSpread.js +++ b/test/helpers/supportsSpread.js @@ -4,7 +4,7 @@ module.exports = function supportsSpread() { var y; eval("y = { ...x }"); return y !== x && y.a; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsTemplateStrings.js b/test/helpers/supportsTemplateStrings.js index abfefd0ec..e36021f3a 100644 --- a/test/helpers/supportsTemplateStrings.js +++ b/test/helpers/supportsTemplateStrings.js @@ -2,7 +2,7 @@ module.exports = function supportsTemplateStrings() { try { var f = eval("(function f() { return String.raw`a\\b`; })"); return f() === "a\\b"; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/supportsWebAssembly.js b/test/helpers/supportsWebAssembly.js index 6eaf5259b..0cdc04da3 100644 --- a/test/helpers/supportsWebAssembly.js +++ b/test/helpers/supportsWebAssembly.js @@ -1,7 +1,7 @@ module.exports = function supportsWebAssembly() { try { return typeof WebAssembly !== "undefined"; - } catch (e) { + } catch (_err) { return false; } }; diff --git a/test/helpers/warmup-webpack.js b/test/helpers/warmup-webpack.js index 5c8e89d32..5830603c2 100644 --- a/test/helpers/warmup-webpack.js +++ b/test/helpers/warmup-webpack.js @@ -17,8 +17,8 @@ describe("warmup", () => { try { expect(err).toBe(END); done(); - } catch (e) { - done(e); + } catch (doneErr) { + done(doneErr); } } ); diff --git a/test/setupTestFramework.js b/test/setupTestFramework.js index 21f34c88f..a0a983124 100644 --- a/test/setupTestFramework.js +++ b/test/setupTestFramework.js @@ -83,17 +83,17 @@ if (process.env.DEBUG_INFO) { process.stdout.write(`DONE OK ${name}\n`); return r; }, - e => { + err => { process.stdout.write(`DONE FAIL ${name}\n`); - throw e; + throw err; } ); } process.stdout.write(`DONE OK ${name}\n`); - } catch (e) { + } catch (err) { process.stdout.write(`DONE FAIL ${name}\n`); - throw e; + throw err; } }, timeout