diff options
author | Rich Trott <rtrott@gmail.com> | 2016-02-15 14:45:53 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-02-18 10:13:13 -0800 |
commit | d7aa8fa088f3b8a31c7d85c6d71824c8c60e7c17 (patch) | |
tree | 739f4a86de562584f10eba7f1a06a406d8d66366 /tools/eslint/lib/config.js | |
parent | d3c3a928c3a2f9e961881b47ef0796e57ae8d429 (diff) | |
download | node-new-d7aa8fa088f3b8a31c7d85c6d71824c8c60e7c17.tar.gz |
tools: update ESLint to version 2.1.0
Update ESLint to 2.1.0. ESLint has a number of potentially-useful new
features but this change attempts to be minimal in its changes.
However, some things could not be avoided reasonably.
ESLint 2.1.0 found a few lint issues that ESLing 1.x missed with
template strings that did not take advantage of any features of
template strings, and `let` declarations where `const` sufficed.
Additionally, ESLint 2.1.0 removes some granularity around enabling ES6
features. Some features (e.g., spread operator) that had been turned off
in our configuration for ESLint 1.x are now permitted.
PR-URL: https://github.com/nodejs/node/pull/5214
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'tools/eslint/lib/config.js')
-rw-r--r-- | tools/eslint/lib/config.js | 80 |
1 files changed, 14 insertions, 66 deletions
diff --git a/tools/eslint/lib/config.js b/tools/eslint/lib/config.js index 3eb174e72d..6f445a44a5 100644 --- a/tools/eslint/lib/config.js +++ b/tools/eslint/lib/config.js @@ -1,7 +1,7 @@ /** * @fileoverview Responsible for loading config files * @author Seth McLaughlin - * @copyright 2014 Nicholas C. Zakas. All rights reserved. + * @copyright 2014-2016 Nicholas C. Zakas. All rights reserved. * @copyright 2014 Michael McLaughlin. All rights reserved. * @copyright 2013 Seth McLaughlin. All rights reserved. * See LICENSE in root directory for full license. @@ -15,7 +15,7 @@ var path = require("path"), ConfigOps = require("./config/config-ops"), ConfigFile = require("./config/config-file"), - util = require("./util"), + Plugins = require("./config/plugins"), FileFinder = require("./file-finder"), debug = require("debug"), userHome = require("user-home"), @@ -26,14 +26,7 @@ var path = require("path"), // Constants //------------------------------------------------------------------------------ -var PACKAGE_CONFIG_FILENAME = "package.json", - PERSONAL_CONFIG_DIR = userHome || null; - -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ - -var loadedPlugins = Object.create(null); +var PERSONAL_CONFIG_DIR = userHome || null; //------------------------------------------------------------------------------ // Helpers @@ -80,47 +73,6 @@ function loadConfig(configToLoad) { } /** - * Load configuration for all plugins provided. - * @param {string[]} pluginNames An array of plugin names which should be loaded. - * @returns {Object} all plugin configurations merged together - */ -function getPluginsConfig(pluginNames) { - var pluginConfig = {}; - - pluginNames.forEach(function(pluginName) { - var pluginNamespace = util.getNamespace(pluginName), - pluginNameWithoutNamespace = util.removeNameSpace(pluginName), - pluginNameWithoutPrefix = util.removePluginPrefix(pluginNameWithoutNamespace), - plugin = {}, - rules = {}; - - if (!loadedPlugins[pluginNameWithoutPrefix]) { - try { - plugin = require(pluginNamespace + util.PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix); - loadedPlugins[pluginNameWithoutPrefix] = plugin; - } catch (err) { - debug("Failed to load plugin configuration for " + pluginNameWithoutPrefix + ". Proceeding without it."); - plugin = { rulesConfig: {}}; - } - } else { - plugin = loadedPlugins[pluginNameWithoutPrefix]; - } - - if (!plugin.rulesConfig) { - plugin.rulesConfig = {}; - } - - Object.keys(plugin.rulesConfig).forEach(function(item) { - rules[pluginNameWithoutPrefix + "/" + item] = plugin.rulesConfig[item]; - }); - - pluginConfig = ConfigOps.merge(pluginConfig, rules); - }); - - return {rules: pluginConfig}; -} - -/** * Get personal config object from ~/.eslintrc. * @returns {Object} the personal config object (empty object if there is no personal config) * @private @@ -156,7 +108,7 @@ function getLocalConfig(thisConfig, directory) { localConfigFiles = thisConfig.findLocalConfigFiles(directory), numFiles = localConfigFiles.length, rootPath, - projectConfigPath = ConfigFile.getFilenameForDirectory(process.cwd()); + projectConfigPath = ConfigFile.getFilenameForDirectory(thisConfig.options.cwd); for (i = 0; i < numFiles; i++) { @@ -192,7 +144,7 @@ function getLocalConfig(thisConfig, directory) { } // Use the personal config file if there are no other local config files found. - return found ? config : ConfigOps.merge(config, getPersonalConfig()); + return found || thisConfig.useSpecificConfig ? config : ConfigOps.merge(config, getPersonalConfig()); } //------------------------------------------------------------------------------ @@ -204,7 +156,6 @@ function getLocalConfig(thisConfig, directory) { * @constructor * @class Config * @param {Object} options Options to be passed in - * @param {string} [cwd] current working directory. Defaults to process.cwd() */ function Config(options) { var useConfig; @@ -240,7 +191,7 @@ function Config(options) { if (isResolvable(useConfig) || isResolvable("eslint-config-" + useConfig) || useConfig.charAt(0) === "@") { this.useSpecificConfig = loadConfig(useConfig); } else { - this.useSpecificConfig = loadConfig(path.resolve(process.cwd(), useConfig)); + this.useSpecificConfig = loadConfig(path.resolve(this.options.cwd, useConfig)); } } } @@ -254,8 +205,7 @@ function Config(options) { Config.prototype.getConfig = function(filePath) { var config, userConfig, - directory = filePath ? path.dirname(filePath) : process.cwd(), - pluginConfig; + directory = filePath ? path.dirname(filePath) : this.options.cwd; debug("Constructing config for " + (filePath ? filePath : "text")); @@ -266,7 +216,7 @@ Config.prototype.getConfig = function(filePath) { return config; } - // Step 1: Determine user-specified config from .eslintrc and package.json files + // Step 1: Determine user-specified config from .eslintrc.* and package.json files if (this.useEslintrc) { debug("Using .eslintrc and package.json files"); userConfig = getLocalConfig(this, directory); @@ -287,10 +237,9 @@ Config.prototype.getConfig = function(filePath) { config = ConfigOps.merge(config, this.useSpecificConfig); } - // Step 5: Merge in command line environments debug("Merging command line environment settings"); - config = ConfigOps.merge(config, ConfigOps.createEnvironmentConfig(this.env)); + config = ConfigOps.merge(config, { env: this.env }); // Step 6: Merge in command line rules if (this.options.rules) { @@ -304,14 +253,13 @@ Config.prototype.getConfig = function(filePath) { // Step 8: Merge in command line plugins if (this.options.plugins) { debug("Merging command line plugins"); - pluginConfig = getPluginsConfig(this.options.plugins); + Plugins.loadAll(this.options.plugins); config = ConfigOps.merge(config, { plugins: this.options.plugins }); } - // Step 9: Merge in plugin specific rules in reverse - if (config.plugins) { - pluginConfig = getPluginsConfig(config.plugins); - config = ConfigOps.merge(pluginConfig, config); + // Step 9: Apply environments to the config if present + if (config.env) { + config = ConfigOps.applyEnvironments(config); } this.cache[directory] = config; @@ -327,7 +275,7 @@ Config.prototype.getConfig = function(filePath) { Config.prototype.findLocalConfigFiles = function(directory) { if (!this.localConfigFinder) { - this.localConfigFinder = new FileFinder(ConfigFile.CONFIG_FILES, PACKAGE_CONFIG_FILENAME); + this.localConfigFinder = new FileFinder(ConfigFile.CONFIG_FILES, this.options.cwd); } return this.localConfigFinder.findAllInDirectoryAndParents(directory); |