From ad8f496745536670b2cc67ec8cd405cc0d779789 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 27 Jun 2018 13:48:13 +0200 Subject: [PATCH] arrow functions, remove or improve eslint-disable comments --- bin/webpack.js | 9 +++++-- lib/Chunk.js | 2 +- lib/ChunkGroup.js | 2 +- lib/Compilation.js | 4 ++-- lib/ExtendedAPIPlugin.js | 12 ++++++---- lib/ExternalModuleFactoryPlugin.js | 2 +- lib/HotModuleReplacement.runtime.js | 13 ++++++---- lib/RuleSet.js | 6 ++--- lib/Stats.js | 3 ++- lib/UmdMainTemplatePlugin.js | 24 +++++++++---------- lib/WebpackOptionsValidationError.js | 1 - lib/debug/ProfilingPlugin.js | 10 ++++---- .../AMDDefineDependencyParserPlugin.js | 10 ++++---- ...AMDRequireDependenciesBlockParserPlugin.js | 2 -- lib/node/NodeMainTemplateAsync.runtime.js | 2 +- lib/util/SetHelpers.js | 8 +++---- lib/wasm/WasmMainTemplatePlugin.js | 8 +++---- lib/wasm/WebAssemblyGenerator.js | 24 +++++++++---------- lib/webpack.web.js | 4 ++-- 19 files changed, 76 insertions(+), 70 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index a34fba26b..977fe5c93 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -159,8 +159,13 @@ if (installedClis.length === 0) { } else if (installedClis.length === 1) { const path = require("path"); const pkgPath = require.resolve(`${installedClis[0].package}/package.json`); - const pkg = require(pkgPath); // eslint-disable-line - require(path.resolve(path.dirname(pkgPath), pkg.bin[installedClis[0].binName])); // eslint-disable-line + // eslint-disable-next-line node/no-missing-require + const pkg = require(pkgPath); + // eslint-disable-next-line node/no-missing-require + require(path.resolve( + path.dirname(pkgPath), + pkg.bin[installedClis[0].binName] + )); } else { console.warn( `You have installed ${installedClis diff --git a/lib/Chunk.js b/lib/Chunk.js index 774eb445a..3d2cea2f1 100644 --- a/lib/Chunk.js +++ b/lib/Chunk.js @@ -305,7 +305,7 @@ class Chunk { if (this._modules.size < otherChunk._modules.size) return 1; const a = this._modules[Symbol.iterator](); const b = otherChunk._modules[Symbol.iterator](); - // eslint-disable-next-line + // eslint-disable-next-line no-constant-condition while (true) { const aItem = a.next(); const bItem = b.next(); diff --git a/lib/ChunkGroup.js b/lib/ChunkGroup.js index 482800b7e..d84ac9d58 100644 --- a/lib/ChunkGroup.js +++ b/lib/ChunkGroup.js @@ -401,7 +401,7 @@ class ChunkGroup { if (this.chunks.length < otherGroup.chunks.length) return 1; const a = this.chunks[Symbol.iterator](); const b = otherGroup.chunks[Symbol.iterator](); - // eslint-disable-next-line + // eslint-disable-next-line no-constant-condition while (true) { const aItem = a.next(); const bItem = b.next(); diff --git a/lib/Compilation.js b/lib/Compilation.js index 1fd02ed4f..7d9540b78 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -89,11 +89,11 @@ const iterationOfArrayCallback = (arr, fn) => { } }; -function addAllToSet(set, otherSet) { +const addAllToSet = (set, otherSet) => { for (const item of otherSet) { set.add(item); } -} +}; class Compilation extends Tapable { constructor(compiler) { diff --git a/lib/ExtendedAPIPlugin.js b/lib/ExtendedAPIPlugin.js index a894a9faf..e41defb1f 100644 --- a/lib/ExtendedAPIPlugin.js +++ b/lib/ExtendedAPIPlugin.js @@ -10,12 +10,16 @@ const ParserHelpers = require("./ParserHelpers"); const NullFactory = require("./NullFactory"); const REPLACEMENTS = { - __webpack_hash__: "__webpack_require__.h", // eslint-disable-line camelcase - __webpack_chunkname__: "__webpack_require__.cn" // eslint-disable-line camelcase + // eslint-disable-next-line camelcase + __webpack_hash__: "__webpack_require__.h", + // eslint-disable-next-line camelcase + __webpack_chunkname__: "__webpack_require__.cn" }; const REPLACEMENT_TYPES = { - __webpack_hash__: "string", // eslint-disable-line camelcase - __webpack_chunkname__: "string" // eslint-disable-line camelcase + // eslint-disable-next-line camelcase + __webpack_hash__: "string", + // eslint-disable-next-line camelcase + __webpack_chunkname__: "string" }; class ExtendedAPIPlugin { diff --git a/lib/ExternalModuleFactoryPlugin.js b/lib/ExternalModuleFactoryPlugin.js index 40c215660..390e30523 100644 --- a/lib/ExternalModuleFactoryPlugin.js +++ b/lib/ExternalModuleFactoryPlugin.js @@ -64,7 +64,7 @@ class ExternalModuleFactoryPlugin { asyncFlag = true; if (i >= externals.length) return callback(); handleExternals(externals[i++], handleExternalsAndCallback); - } while (!asyncFlag); // eslint-disable-line keyword-spacing + } while (!asyncFlag); asyncFlag = false; }; diff --git a/lib/HotModuleReplacement.runtime.js b/lib/HotModuleReplacement.runtime.js index 4afddedc9..917ef45ba 100644 --- a/lib/HotModuleReplacement.runtime.js +++ b/lib/HotModuleReplacement.runtime.js @@ -5,12 +5,15 @@ /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */ module.exports = function() { var hotApplyOnUpdate = true; - var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars + // eslint-disable-next-line no-unused-vars + var hotCurrentHash = $hash$; var hotRequestTimeout = $requestTimeout$; var hotCurrentModuleData = {}; - var hotCurrentChildModule; // eslint-disable-line no-unused-vars - var hotCurrentParents = []; // eslint-disable-line no-unused-vars - var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars + var hotCurrentChildModule; + // eslint-disable-next-line no-unused-vars + var hotCurrentParents = []; + // eslint-disable-next-line no-unused-vars + var hotCurrentParentsTemp = []; // eslint-disable-next-line no-unused-vars function hotCreateRequire(moduleId) { @@ -199,8 +202,8 @@ module.exports = function() { }); hotUpdate = {}; /*foreachInstalledChunks*/ + // eslint-disable-next-line no-lone-blocks { - // eslint-disable-line no-lone-blocks /*globals chunkId */ hotEnsureUpdateChunk(chunkId); } diff --git a/lib/RuleSet.js b/lib/RuleSet.js index abc44c1a9..7ed8eba6f 100644 --- a/lib/RuleSet.js +++ b/lib/RuleSet.js @@ -75,13 +75,13 @@ normalized: "use strict"; const notMatcher = matcher => { - return function(str) { + return str => { return !matcher(str); }; }; const orMatcher = items => { - return function(str) { + return str => { for (let i = 0; i < items.length; i++) { if (items[i](str)) return true; } @@ -90,7 +90,7 @@ const orMatcher = items => { }; const andMatcher = items => { - return function(str) { + return str => { for (let i = 0; i < items.length; i++) { if (!items[i](str)) return false; } diff --git a/lib/Stats.js b/lib/Stats.js index 5179c8108..b6db2396c 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -108,10 +108,11 @@ class Stats { if (typeof item === "string") { const regExp = new RegExp( `[\\\\/]${item.replace( + // eslint-disable-next-line no-useless-escape /[-[\]{}()*+?.\\^$|]/g, "\\$&" )}([\\\\/]|$|!|\\?)` - ); // eslint-disable-line no-useless-escape + ); return ident => regExp.test(ident); } if (item && typeof item === "object" && typeof item.test === "function") { diff --git a/lib/UmdMainTemplatePlugin.js b/lib/UmdMainTemplatePlugin.js index 795ae2782..bb2e46629 100644 --- a/lib/UmdMainTemplatePlugin.js +++ b/lib/UmdMainTemplatePlugin.js @@ -107,14 +107,14 @@ class UmdMainTemplatePlugin { requiredExternals = externals; } - function replaceKeys(str) { + const replaceKeys = str => { return mainTemplate.getAssetPath(str, { hash, chunk }); - } + }; - function externalsDepsArray(modules) { + const externalsDepsArray = modules => { return `[${replaceKeys( modules .map(m => @@ -124,9 +124,9 @@ class UmdMainTemplatePlugin { ) .join(", ") )}]`; - } + }; - function externalsRootArray(modules) { + const externalsRootArray = modules => { return replaceKeys( modules .map(m => { @@ -136,9 +136,9 @@ class UmdMainTemplatePlugin { }) .join(", ") ); - } + }; - function externalsRequireArray(type) { + const externalsRequireArray = type => { return replaceKeys( externals .map(m => { @@ -166,20 +166,20 @@ class UmdMainTemplatePlugin { }) .join(", ") ); - } + }; - function externalsArguments(modules) { + const externalsArguments = modules => { return modules .map( m => `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__` ) .join(", "); - } + }; - function libraryName(library) { + const libraryName = library => { return JSON.stringify(replaceKeys([].concat(library).pop())); - } + }; let amdFactory; if (optionalExternals.length > 0) { diff --git a/lib/WebpackOptionsValidationError.js b/lib/WebpackOptionsValidationError.js index 3fdbd0df6..d66cb2ccc 100644 --- a/lib/WebpackOptionsValidationError.js +++ b/lib/WebpackOptionsValidationError.js @@ -332,7 +332,6 @@ class WebpackOptionsValidationError extends WebpackError { } return baseMessage; } else { - // eslint-disable-line no-fallthrough return `${dataPath} ${err.message} (${JSON.stringify( err, null, diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index bd6202fdb..1cb962710 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -5,7 +5,8 @@ const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json"); let inspector = undefined; try { - inspector = require("inspector"); // eslint-disable-line node/no-missing-require + // eslint-disable-next-line node/no-missing-require + inspector = require("inspector"); } catch (e) { console.log("Unable to CPU profile in < node 8.0"); } @@ -84,7 +85,7 @@ class Profiler { * @param {string} outputPath The location where to write the log. * @returns {Trace} The trace object */ -function createTrace(outputPath) { +const createTrace = outputPath => { const trace = new Tracer({ noStream: true }); @@ -139,7 +140,7 @@ function createTrace(outputPath) { trace.destroy(); } }; -} +}; const pluginName = "ProfilingPlugin"; @@ -354,7 +355,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => { switch (type) { case "promise": return (...args) => { - // eslint-disable-line const id = ++tracer.counter; tracer.trace.begin({ name, @@ -373,7 +373,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => { }; case "async": return (...args) => { - // eslint-disable-line const id = ++tracer.counter; tracer.trace.begin({ name, @@ -392,7 +391,6 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => { }; case "sync": return (...args) => { - // eslint-disable-line const id = ++tracer.counter; // Do not instrument ourself due to the CPU // profile needing to be the last event in the trace. diff --git a/lib/dependencies/AMDDefineDependencyParserPlugin.js b/lib/dependencies/AMDDefineDependencyParserPlugin.js index c4cb5789a..95e862d12 100644 --- a/lib/dependencies/AMDDefineDependencyParserPlugin.js +++ b/lib/dependencies/AMDDefineDependencyParserPlugin.js @@ -23,17 +23,17 @@ const isBoundFunctionExpression = expr => { return true; }; -function isUnboundFunctionExpression(expr) { +const isUnboundFunctionExpression = expr => { if (expr.type === "FunctionExpression") return true; if (expr.type === "ArrowFunctionExpression") return true; return false; -} +}; -function isCallable(expr) { +const isCallable = expr => { if (isUnboundFunctionExpression(expr)) return true; if (isBoundFunctionExpression(expr)) return true; return false; -} +}; class AMDDefineDependencyParserPlugin { constructor(options) { @@ -80,7 +80,6 @@ class AMDDefineDependencyParserPlugin { request )) ) { - // eslint-disable-line no-cond-assign dep = new LocalModuleDependency(localModule, undefined, false); dep.loc = expr.loc; parser.state.current.addDependency(dep); @@ -121,7 +120,6 @@ class AMDDefineDependencyParserPlugin { namedModule )) ) { - // eslint-disable-line no-cond-assign dep = new LocalModuleDependency(localModule, param.range, false); } else { dep = this.newRequireItemDependency(param.string, param.range); diff --git a/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js b/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js index 1173f982e..e6826722e 100644 --- a/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +++ b/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js @@ -79,7 +79,6 @@ class AMDRequireDependenciesBlockParserPlugin { request )) ) { - // eslint-disable-line no-cond-assign dep = new LocalModuleDependency(localModule, undefined, false); dep.loc = expr.loc; parser.state.current.addDependency(dep); @@ -127,7 +126,6 @@ class AMDRequireDependenciesBlockParserPlugin { param.string )) ) { - // eslint-disable-line no-cond-assign dep = new LocalModuleDependency(localModule, param.range, false); } else { dep = this.newRequireItemDependency(param.string, param.range); diff --git a/lib/node/NodeMainTemplateAsync.runtime.js b/lib/node/NodeMainTemplateAsync.runtime.js index bcdd57dab..35eb47b66 100644 --- a/lib/node/NodeMainTemplateAsync.runtime.js +++ b/lib/node/NodeMainTemplateAsync.runtime.js @@ -37,7 +37,7 @@ module.exports = function() { }); } - //eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars function hotDisposeChunk(chunkId) { delete installedChunks[chunkId]; } diff --git a/lib/util/SetHelpers.js b/lib/util/SetHelpers.js index 8833415f8..96c063c7e 100644 --- a/lib/util/SetHelpers.js +++ b/lib/util/SetHelpers.js @@ -5,7 +5,7 @@ * @param {Set[]} sets an array of sets being checked for shared elements * @returns {Set} returns a new Set containing the intersecting items */ -function intersect(sets) { +const intersect = sets => { if (sets.length === 0) return new Set(); if (sets.length === 1) return new Set(sets[0]); let minSize = Infinity; @@ -28,7 +28,7 @@ function intersect(sets) { } } return current; -} +}; /** * Checks if a set is the subset of another set @@ -36,13 +36,13 @@ function intersect(sets) { * @param {Set} smallSet the set whos elements might be contained inside of bigSet * @returns {boolean} returns true if smallSet contains all elements inside of the bigSet */ -function isSubset(bigSet, smallSet) { +const isSubset = (bigSet, smallSet) => { if (bigSet.size < smallSet.size) return false; for (const item of smallSet) { if (!bigSet.has(item)) return false; } return true; -} +}; exports.intersect = intersect; exports.isSubset = isSubset; diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index b946c4e00..061087df6 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -10,7 +10,7 @@ const WebAssemblyUtils = require("./WebAssemblyUtils"); /** @typedef {import("../Module")} Module */ // Get all wasm modules -function getAllWasmModules(chunk) { +const getAllWasmModules = chunk => { const wasmModules = chunk.getAllAsyncChunks(); const array = []; for (const chunk of wasmModules) { @@ -22,7 +22,7 @@ function getAllWasmModules(chunk) { } return array; -} +}; /** * generates the import object function for a module @@ -30,7 +30,7 @@ function getAllWasmModules(chunk) { * @param {boolean} mangle mangle imports * @returns {string} source code */ -function generateImportObject(module, mangle) { +const generateImportObject = (module, mangle) => { const waitForInstances = new Map(); const properties = []; const usedWasmDependencies = WebAssemblyUtils.getUsedDependencies( @@ -151,7 +151,7 @@ function generateImportObject(module, mangle) { "}," ]); } -} +}; class WasmMainTemplatePlugin { constructor({ generateLoadBinaryCode, supportsStreaming, mangleImports }) { diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index d5fb13c4e..beafd9c46 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -32,21 +32,21 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly * @param {ArrayBuffer} ab - original binary * @returns {ArrayBufferTransform} transform */ -function preprocess(ab) { +const preprocess = ab => { const optBin = shrinkPaddedLEB128(new Uint8Array(ab)); return optBin.buffer; -} +}; /** * @template T * @param {Function[]} fns transforms * @returns {Function} composed transform */ -function compose(...fns) { +const compose = (...fns) => { return fns.reduce((prevFn, nextFn) => { return value => nextFn(prevFn(value)); }, value => value); -} +}; // TODO replace with @callback @@ -70,7 +70,7 @@ const removeStartFunc = state => bin => { * @param {Object} ast - Module's AST * @returns {Array} - nodes */ -function getImportedGlobals(ast) { +const getImportedGlobals = ast => { const importedGlobals = []; t.traverse(ast, { @@ -82,9 +82,9 @@ function getImportedGlobals(ast) { }); return importedGlobals; -} +}; -function getCountImportedFunc(ast) { +const getCountImportedFunc = ast => { let count = 0; t.traverse(ast, { @@ -96,7 +96,7 @@ function getCountImportedFunc(ast) { }); return count; -} +}; /** * Get next type index @@ -104,7 +104,7 @@ function getCountImportedFunc(ast) { * @param {Object} ast - Module's AST * @returns {t.Index} - index */ -function getNextTypeIndex(ast) { +const getNextTypeIndex = ast => { const typeSectionMetadata = t.getSectionMetadata(ast, "type"); if (typeof typeSectionMetadata === "undefined") { @@ -112,7 +112,7 @@ function getNextTypeIndex(ast) { } return t.indexLiteral(typeSectionMetadata.vectorOfSize.value); -} +}; /** * Get next func index @@ -125,7 +125,7 @@ function getNextTypeIndex(ast) { * @param {Number} countImportedFunc - number of imported funcs * @returns {t.Index} - index */ -function getNextFuncIndex(ast, countImportedFunc) { +const getNextFuncIndex = (ast, countImportedFunc) => { const funcSectionMetadata = t.getSectionMetadata(ast, "func"); if (typeof funcSectionMetadata === "undefined") { @@ -135,7 +135,7 @@ function getNextFuncIndex(ast, countImportedFunc) { const vectorOfSize = funcSectionMetadata.vectorOfSize.value; return t.indexLiteral(vectorOfSize + countImportedFunc); -} +}; /** * Create a init instruction for a global diff --git a/lib/webpack.web.js b/lib/webpack.web.js index 365aa06ad..1f60eab7f 100644 --- a/lib/webpack.web.js +++ b/lib/webpack.web.js @@ -9,7 +9,7 @@ const WebEnvironmentPlugin = require("./web/WebEnvironmentPlugin"); const WebpackOptionsApply = require("./WebpackOptionsApply"); const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter"); -function webpack(options, callback) { +const webpack = (options, callback) => { new WebpackOptionsDefaulter().process(options); const compiler = new Compiler(); @@ -22,7 +22,7 @@ function webpack(options, callback) { compiler.run(callback); } return compiler; -} +}; module.exports = webpack; webpack.WebpackOptionsDefaulter = WebpackOptionsDefaulter;