From aa8d01bf8d6201d4f6fc656a0b602ded0704b344 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Fri, 30 Dec 2016 09:43:49 -0600 Subject: [PATCH] refactor(eslint): Added no-unsed-vars, env specific .eslintrc's for buildin & hot (#3636) * refactor(eslint): Added no-unsed-vars, env specific .eslintrc's for buildin & hot * This change allows for buildin to now be part of the lint test by addition of an extra .eslintrc file which extends existing but sets es6 to false * Turned on no-unused-vars for eslint, and then removed all warnings from turning that feature on * Was getting notified of errors in "quote" property in eslintrc, so changed to correct value from error to 2. * beautify * swap invalid eslint config val --- .eslintrc | 2 +- bin/convert-argv.js | 7 ------- buildin/.eslintrc | 7 +++++++ buildin/amd-define.js | 4 +++- buildin/amd-options.js | 1 + buildin/global.js | 4 +++- buildin/module.js | 8 ++++++-- buildin/return-require.js | 5 ++++- hot/.eslintrc | 7 +++++++ hot/only-dev-server.js | 2 +- lib/CompatibilityPlugin.js | 1 - lib/Compilation.js | 4 ---- lib/Compiler.js | 1 - lib/FlagInitialModulesAsUsedPlugin.js | 3 --- lib/FunctionModuleTemplatePlugin.js | 1 - lib/JsonpChunkTemplatePlugin.js | 1 - lib/JsonpHotUpdateChunkTemplatePlugin.js | 1 - lib/JsonpMainTemplatePlugin.js | 2 -- lib/LibManifestPlugin.js | 1 - lib/Module.js | 1 - lib/OptionsDefaulter.js | 9 --------- lib/UseStrictPlugin.js | 1 - lib/WebpackOptionsValidationError.js | 9 --------- lib/dependencies/HarmonyImportSpecifierDependency.js | 1 - lib/dependencies/ImportPlugin.js | 5 ----- lib/dependencies/SystemPlugin.js | 4 ---- lib/dependencies/UnsupportedDependency.js | 1 - lib/node/NodeMainTemplate.runtime.js | 2 +- lib/node/NodeMainTemplateAsync.runtime.js | 2 +- lib/node/NodeMainTemplatePlugin.js | 1 - lib/node/NodeSourcePlugin.js | 1 - lib/optimize/AggressiveSplittingPlugin.js | 1 - lib/performance/SizeLimitsPlugin.js | 2 -- lib/web/WebEnvironmentPlugin.js | 1 - lib/webworker/WebWorkerMainTemplate.runtime.js | 2 +- lib/webworker/WebWorkerMainTemplatePlugin.js | 1 - package.json | 2 +- 37 files changed, 37 insertions(+), 71 deletions(-) create mode 100644 buildin/.eslintrc create mode 100644 hot/.eslintrc diff --git a/.eslintrc b/.eslintrc index 6ad1f7c9d..2945e6cfd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,7 +21,7 @@ "space-in-parens": "error", "no-trailing-spaces": "error", "no-use-before-define": "off", - "no-unused-vars": "off", + "no-unused-vars": ["error", {"args": "none"}], "key-spacing": "error", "space-infix-ops": "error", "no-unsafe-negation": "error", diff --git a/bin/convert-argv.js b/bin/convert-argv.js index 6f10c0e69..309add562 100644 --- a/bin/convert-argv.js +++ b/bin/convert-argv.js @@ -2,7 +2,6 @@ var path = require("path"); var fs = require("fs"); fs.existsSync = fs.existsSync || path.existsSync; var interpret = require("interpret"); -var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter"); module.exports = function(yargs, argv, convertOptions) { @@ -226,12 +225,6 @@ module.exports = function(yargs, argv, convertOptions) { }); } - function mapArgToPath(name, optionName) { - ifArg(name, function(str) { - options[optionName || name] = path.resolve(str); - }); - } - function loadPlugin(name) { var loadUtils = require("loader-utils"); var args = null; diff --git a/buildin/.eslintrc b/buildin/.eslintrc new file mode 100644 index 000000000..1e65e60cc --- /dev/null +++ b/buildin/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true, + "es6": false, + "browser": true + } +} diff --git a/buildin/amd-define.js b/buildin/amd-define.js index f820c1968..0d32606a1 100644 --- a/buildin/amd-define.js +++ b/buildin/amd-define.js @@ -1 +1,3 @@ -module.exports = function() { throw new Error("define cannot be used indirect"); }; +module.exports = function() { + throw new Error("define cannot be used indirect"); +}; diff --git a/buildin/amd-options.js b/buildin/amd-options.js index 26c88533b..f7dd47533 100644 --- a/buildin/amd-options.js +++ b/buildin/amd-options.js @@ -1 +1,2 @@ +/* globals __webpack_amd_options__ */ module.exports = __webpack_amd_options__; diff --git a/buildin/global.js b/buildin/global.js index 49202a920..8b23b86c7 100644 --- a/buildin/global.js +++ b/buildin/global.js @@ -1,7 +1,9 @@ var g; // This works in non-strict mode -g = (function() { return this; })(); +g = (function() { + return this; +})(); try { // This works if eval is allowed (see CSP) diff --git a/buildin/module.js b/buildin/module.js index 2871d6f04..cea487cfa 100644 --- a/buildin/module.js +++ b/buildin/module.js @@ -7,12 +7,16 @@ module.exports = function(module) { Object.defineProperty(module, "loaded", { enumerable: true, configurable: false, - get: function() { return module.l; } + get: function() { + return module.l; + } }); Object.defineProperty(module, "id", { enumerable: true, configurable: false, - get: function() { return module.i; } + get: function() { + return module.i; + } }); module.webpackPolyfill = 1; } diff --git a/buildin/return-require.js b/buildin/return-require.js index 52c29e2e3..a4eb3f4b8 100644 --- a/buildin/return-require.js +++ b/buildin/return-require.js @@ -1 +1,4 @@ -module.exports = function() { return __webpack_require__; }; \ No newline at end of file +/* globals __webpack_require__ */ +module.exports = function() { + return __webpack_require__; +}; diff --git a/hot/.eslintrc b/hot/.eslintrc new file mode 100644 index 000000000..1e65e60cc --- /dev/null +++ b/hot/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true, + "es6": false, + "browser": true + } +} diff --git a/hot/only-dev-server.js b/hot/only-dev-server.js index 413c3b874..c84b22ae0 100644 --- a/hot/only-dev-server.js +++ b/hot/only-dev-server.js @@ -2,7 +2,7 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -/*globals window __webpack_hash__ */ +/*globals __webpack_hash__ */ if(module.hot) { var lastHash; var upToDate = function upToDate() { diff --git a/lib/CompatibilityPlugin.js b/lib/CompatibilityPlugin.js index cc6f5d626..2feb5d0de 100644 --- a/lib/CompatibilityPlugin.js +++ b/lib/CompatibilityPlugin.js @@ -2,7 +2,6 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -var path = require("path"); var ConstDependency = require("./dependencies/ConstDependency"); var NullFactory = require("./NullFactory"); diff --git a/lib/Compilation.js b/lib/Compilation.js index 93a89a4c6..4fef31b8e 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -740,8 +740,6 @@ Compilation.prototype.assignIndex = function assignIndex(module) { }; Compilation.prototype.assignDepth = function assignDepth(module) { - var _this = this; - function assignDepthToModule(module, depth) { // enter module if(typeof module.depth === "number" && module.depth <= depth) return; @@ -760,8 +758,6 @@ Compilation.prototype.assignDepth = function assignDepth(module) { } function assignDepthToDependencyBlock(block, depth) { - var allDependencies = []; - function iteratorDependency(d) { assignDepthToDependency(d, depth); } diff --git a/lib/Compiler.js b/lib/Compiler.js index 7ae303ee0..302c2df36 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -6,7 +6,6 @@ var path = require("path"); var Tapable = require("tapable"); var Compilation = require("./Compilation"); -var Resolver = require("enhanced-resolve/lib/Resolver"); var NormalModuleFactory = require("./NormalModuleFactory"); var ContextModuleFactory = require("./ContextModuleFactory"); diff --git a/lib/FlagInitialModulesAsUsedPlugin.js b/lib/FlagInitialModulesAsUsedPlugin.js index eaa631e7b..5bb77688f 100644 --- a/lib/FlagInitialModulesAsUsedPlugin.js +++ b/lib/FlagInitialModulesAsUsedPlugin.js @@ -2,9 +2,6 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -var path = require("path"); -var async = require("async"); - function FlagInitialModulesAsUsedPlugin() {} module.exports = FlagInitialModulesAsUsedPlugin; FlagInitialModulesAsUsedPlugin.prototype.apply = function(compiler) { diff --git a/lib/FunctionModuleTemplatePlugin.js b/lib/FunctionModuleTemplatePlugin.js index 1714d7817..63eeaefdb 100644 --- a/lib/FunctionModuleTemplatePlugin.js +++ b/lib/FunctionModuleTemplatePlugin.js @@ -3,7 +3,6 @@ Author Tobias Koppers @sokra */ var ConcatSource = require("webpack-sources").ConcatSource; -var PrefixSource = require("webpack-sources").PrefixSource; function FunctionModuleTemplatePlugin() {} module.exports = FunctionModuleTemplatePlugin; diff --git a/lib/JsonpChunkTemplatePlugin.js b/lib/JsonpChunkTemplatePlugin.js index 4bd139a7d..bcdefc8be 100644 --- a/lib/JsonpChunkTemplatePlugin.js +++ b/lib/JsonpChunkTemplatePlugin.js @@ -3,7 +3,6 @@ Author Tobias Koppers @sokra */ var ConcatSource = require("webpack-sources").ConcatSource; -var Template = require("./Template"); function JsonpChunkTemplatePlugin() {} module.exports = JsonpChunkTemplatePlugin; diff --git a/lib/JsonpHotUpdateChunkTemplatePlugin.js b/lib/JsonpHotUpdateChunkTemplatePlugin.js index 09a01f1ff..77813b6d5 100644 --- a/lib/JsonpHotUpdateChunkTemplatePlugin.js +++ b/lib/JsonpHotUpdateChunkTemplatePlugin.js @@ -3,7 +3,6 @@ Author Tobias Koppers @sokra */ var ConcatSource = require("webpack-sources").ConcatSource; -var Template = require("./Template"); function JsonpHotUpdateChunkTemplatePlugin() {} module.exports = JsonpHotUpdateChunkTemplatePlugin; diff --git a/lib/JsonpMainTemplatePlugin.js b/lib/JsonpMainTemplatePlugin.js index 5f65db030..b5c859c1b 100644 --- a/lib/JsonpMainTemplatePlugin.js +++ b/lib/JsonpMainTemplatePlugin.js @@ -27,7 +27,6 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) { return source; }); mainTemplate.plugin("jsonp-script", function(_, chunk, hash) { - var filename = this.outputOptions.filename; var chunkFilename = this.outputOptions.chunkFilename; var chunkMaps = chunk.getChunkMaps(); var crossOriginLoading = this.outputOptions.crossOriginLoading; @@ -81,7 +80,6 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) { ]); }); mainTemplate.plugin("require-ensure", function(_, chunk, hash) { - var chunkFilename = this.outputOptions.chunkFilename; return this.asString([ "if(installedChunks[chunkId] === 0)", this.indent([ diff --git a/lib/LibManifestPlugin.js b/lib/LibManifestPlugin.js index c10206c92..cb8a851e2 100644 --- a/lib/LibManifestPlugin.js +++ b/lib/LibManifestPlugin.js @@ -4,7 +4,6 @@ */ var path = require("path"); var async = require("async"); -var HarmonyModulesHelpers = require("./dependencies/HarmonyModulesHelpers"); function LibManifestPlugin(options) { this.options = options; diff --git a/lib/Module.js b/lib/Module.js index 42a1290a1..f6969651d 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -5,7 +5,6 @@ var DependenciesBlock = require("./DependenciesBlock"); var ModuleReason = require("./ModuleReason"); var Template = require("./Template"); -var HarmonyModulesHelpers = require("./dependencies/HarmonyModulesHelpers"); var debugId = 1000; diff --git a/lib/OptionsDefaulter.js b/lib/OptionsDefaulter.js index 46ef9be8e..863f04fa9 100644 --- a/lib/OptionsDefaulter.js +++ b/lib/OptionsDefaulter.js @@ -27,15 +27,6 @@ function setProperty(obj, name, value) { obj[name.pop()] = value; } -function hasProperty(obj, name, value) { - name = name.split("."); - for(var i = 0; i < name.length - 1; i++) { - obj = obj[name[i]]; - if(typeof obj != "object" || !obj) return false; - } - return Object.prototype.hasOwnProperty.call(obj, name.pop()); -} - OptionsDefaulter.prototype.process = function(options) { var addItemTo = function addItemTo(list) { return function(item) { diff --git a/lib/UseStrictPlugin.js b/lib/UseStrictPlugin.js index 40ad1216f..8ee47ac32 100644 --- a/lib/UseStrictPlugin.js +++ b/lib/UseStrictPlugin.js @@ -5,7 +5,6 @@ "use strict" const ConstDependency = require("./dependencies/ConstDependency"); -const NullFactory = require("./NullFactory"); class UseStrictPlugin { apply(compiler) { diff --git a/lib/WebpackOptionsValidationError.js b/lib/WebpackOptionsValidationError.js index 7056f36ba..7307f403f 100644 --- a/lib/WebpackOptionsValidationError.js +++ b/lib/WebpackOptionsValidationError.js @@ -123,15 +123,6 @@ function getSchemaPart(path, parents, additionalPath) { return schemaPart; } -function getSchemaPartText2(path, parents, additionalPath) { - var schemaPart = getSchemaPart(path, parents, additionalPath); - while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref); - var schemaText = WebpackOptionsValidationError.formatSchema(schemaPart); - if(schemaPart.description) - schemaText += "\n" + schemaPart.description; - return schemaText; -} - function getSchemaPartText(schemaPart, additionalPath) { if(additionalPath) { for(var i = 0; i < additionalPath.length; i++) { diff --git a/lib/dependencies/HarmonyImportSpecifierDependency.js b/lib/dependencies/HarmonyImportSpecifierDependency.js index 25fc77848..47232f0df 100644 --- a/lib/dependencies/HarmonyImportSpecifierDependency.js +++ b/lib/dependencies/HarmonyImportSpecifierDependency.js @@ -3,7 +3,6 @@ Author Tobias Koppers @sokra */ var NullDependency = require("./NullDependency"); -var HarmonyModulesHelpers = require("./HarmonyModulesHelpers"); function HarmonyImportSpecifierDependency(importDependency, importedVar, id, name, range) { NullDependency.call(this); diff --git a/lib/dependencies/ImportPlugin.js b/lib/dependencies/ImportPlugin.js index da41f8f4d..5b19cf7af 100644 --- a/lib/dependencies/ImportPlugin.js +++ b/lib/dependencies/ImportPlugin.js @@ -4,11 +4,6 @@ */ var ImportDependency = require("./ImportDependency"); var ImportContextDependency = require("./ImportContextDependency"); - -var UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning"); -var ConstDependency = require("./ConstDependency"); -var BasicEvaluatedExpression = require("../BasicEvaluatedExpression"); - var ImportParserPlugin = require("./ImportParserPlugin"); function ImportPlugin(options) { diff --git a/lib/dependencies/SystemPlugin.js b/lib/dependencies/SystemPlugin.js index 154a4083a..b4a456dc7 100644 --- a/lib/dependencies/SystemPlugin.js +++ b/lib/dependencies/SystemPlugin.js @@ -12,11 +12,7 @@ function SystemPlugin(options) { module.exports = SystemPlugin; SystemPlugin.prototype.apply = function(compiler) { - var options = this.options; compiler.plugin("compilation", function(compilation, params) { - var normalModuleFactory = params.normalModuleFactory; - var contextModuleFactory = params.contextModuleFactory; - params.normalModuleFactory.plugin("parser", function(parser, parserOptions) { if(typeof parserOptions.system !== "undefined" && !parserOptions.system) diff --git a/lib/dependencies/UnsupportedDependency.js b/lib/dependencies/UnsupportedDependency.js index a90f426d6..ee40af5a4 100644 --- a/lib/dependencies/UnsupportedDependency.js +++ b/lib/dependencies/UnsupportedDependency.js @@ -3,7 +3,6 @@ Author Tobias Koppers @sokra */ var NullDependency = require("./NullDependency"); -var DepBlockHelpers = require("./DepBlockHelpers"); function UnsupportedDependency(request, range) { NullDependency.call(this); diff --git a/lib/node/NodeMainTemplate.runtime.js b/lib/node/NodeMainTemplate.runtime.js index f4d3230d6..8460325d8 100644 --- a/lib/node/NodeMainTemplate.runtime.js +++ b/lib/node/NodeMainTemplate.runtime.js @@ -18,7 +18,7 @@ module.exports = function() { return Promise.resolve(update); } - function hotDisposeChunk(chunkId) { + function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars delete installedChunks[chunkId]; } }; diff --git a/lib/node/NodeMainTemplateAsync.runtime.js b/lib/node/NodeMainTemplateAsync.runtime.js index cab55f22d..2d98d9ea7 100644 --- a/lib/node/NodeMainTemplateAsync.runtime.js +++ b/lib/node/NodeMainTemplateAsync.runtime.js @@ -34,7 +34,7 @@ module.exports = function() { }); } - function hotDisposeChunk(chunkId) { + function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars delete installedChunks[chunkId]; } }; diff --git a/lib/node/NodeMainTemplatePlugin.js b/lib/node/NodeMainTemplatePlugin.js index 0b87a6189..2914b25bb 100644 --- a/lib/node/NodeMainTemplatePlugin.js +++ b/lib/node/NodeMainTemplatePlugin.js @@ -46,7 +46,6 @@ NodeMainTemplatePlugin.prototype.apply = function(mainTemplate) { return source; }); mainTemplate.plugin("require-ensure", function(_, chunk, hash) { - var filename = this.outputOptions.filename; var chunkFilename = this.outputOptions.chunkFilename; var chunkMaps = chunk.getChunkMaps(); var insertMoreModules = [ diff --git a/lib/node/NodeSourcePlugin.js b/lib/node/NodeSourcePlugin.js index 0da0b4df4..cf0abaff0 100644 --- a/lib/node/NodeSourcePlugin.js +++ b/lib/node/NodeSourcePlugin.js @@ -76,7 +76,6 @@ NodeSourcePlugin.prototype.apply = function(compiler) { }); }); compiler.plugin("after-resolvers", function(compiler) { - var alias = {}; Object.keys(nodeLibsBrowser).forEach(function(lib) { if(options[lib] !== false) { compiler.resolvers.normal.apply( diff --git a/lib/optimize/AggressiveSplittingPlugin.js b/lib/optimize/AggressiveSplittingPlugin.js index 9b9649526..cc232d396 100644 --- a/lib/optimize/AggressiveSplittingPlugin.js +++ b/lib/optimize/AggressiveSplittingPlugin.js @@ -157,7 +157,6 @@ AggressiveSplittingPlugin.prototype.apply = function(compiler) { compilation.plugin("record-hash", function(records) { // 3. save to made splittings to records var minSize = _this.options.minSize; - var maxSize = _this.options.maxSize; if(!records.aggressiveSplits) records.aggressiveSplits = []; compilation.chunks.forEach(function(chunk) { if(chunk.hasEntryModule()) return; diff --git a/lib/performance/SizeLimitsPlugin.js b/lib/performance/SizeLimitsPlugin.js index c64e6c99e..e70cb7210 100644 --- a/lib/performance/SizeLimitsPlugin.js +++ b/lib/performance/SizeLimitsPlugin.js @@ -2,8 +2,6 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Sean Larkin @thelarkinn */ -var path = require("path"); - var EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning"); var AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning"); var NoAsyncChunksWarning = require("./NoAsyncChunksWarning"); diff --git a/lib/web/WebEnvironmentPlugin.js b/lib/web/WebEnvironmentPlugin.js index 03abf83a7..f55947671 100644 --- a/lib/web/WebEnvironmentPlugin.js +++ b/lib/web/WebEnvironmentPlugin.js @@ -8,6 +8,5 @@ function WebEnvironmentPlugin(inputFileSystem, outputFileSystem) { } module.exports = WebEnvironmentPlugin; WebEnvironmentPlugin.prototype.apply = function(compiler) { - var inputFileSystem = compiler.inputFileSystem = this.inputFileSystem; compiler.outputFileSystem = this.outputFileSystem; }; diff --git a/lib/webworker/WebWorkerMainTemplate.runtime.js b/lib/webworker/WebWorkerMainTemplate.runtime.js index 867ada06d..484574b40 100644 --- a/lib/webworker/WebWorkerMainTemplate.runtime.js +++ b/lib/webworker/WebWorkerMainTemplate.runtime.js @@ -51,7 +51,7 @@ module.exports = function() { }); } - function hotDisposeChunk(chunkId) { + function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars delete installedChunks[chunkId]; } }; diff --git a/lib/webworker/WebWorkerMainTemplatePlugin.js b/lib/webworker/WebWorkerMainTemplatePlugin.js index 8c37ecb04..df1fd6ebb 100644 --- a/lib/webworker/WebWorkerMainTemplatePlugin.js +++ b/lib/webworker/WebWorkerMainTemplatePlugin.js @@ -28,7 +28,6 @@ WebWorkerMainTemplatePlugin.prototype.apply = function(mainTemplate) { return source; }); mainTemplate.plugin("require-ensure", function(_, chunk, hash) { - var filename = this.outputOptions.filename; var chunkFilename = this.outputOptions.chunkFilename; return this.asString([ "// \"1\" is the signal for \"already loaded\"", diff --git a/package.json b/package.json index a7a9dfe8a..6b3c34398 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "build:examples": "cd examples && node buildAll.js", "pretest": "npm run lint-files", "lint-files": "npm run lint && npm run beautify-lint", - "lint": "eslint lib bin hot", + "lint": "eslint lib bin hot buildin", "beautify-lint": "beautify-lint 'lib/**/*.js' 'hot/**/*.js' 'bin/**/*.js' 'benchmark/*.js' 'test/*.js'", "nsp": "nsp check --output summary", "cover": "node --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha",