diff options
Diffstat (limited to 'tools/eslint/lib/config')
-rw-r--r-- | tools/eslint/lib/config/autoconfig.js | 62 | ||||
-rw-r--r-- | tools/eslint/lib/config/config-file.js | 51 | ||||
-rw-r--r-- | tools/eslint/lib/config/config-initializer.js | 78 | ||||
-rw-r--r-- | tools/eslint/lib/config/config-ops.js | 24 | ||||
-rw-r--r-- | tools/eslint/lib/config/config-rule.js | 31 | ||||
-rw-r--r-- | tools/eslint/lib/config/config-validator.js | 13 | ||||
-rw-r--r-- | tools/eslint/lib/config/environments.js | 2 | ||||
-rw-r--r-- | tools/eslint/lib/config/plugins.js | 17 |
8 files changed, 127 insertions, 151 deletions
diff --git a/tools/eslint/lib/config/autoconfig.js b/tools/eslint/lib/config/autoconfig.js index 2cd753e95d..d8f29d5a0d 100644 --- a/tools/eslint/lib/config/autoconfig.js +++ b/tools/eslint/lib/config/autoconfig.js @@ -9,26 +9,25 @@ // Requirements //------------------------------------------------------------------------------ -let lodash = require("lodash"), - debug = require("debug"), +const lodash = require("lodash"), eslint = require("../eslint"), configRule = require("./config-rule"), ConfigOps = require("./config-ops"), recConfig = require("../../conf/eslint.json"); +const debug = require("debug")("eslint:autoconfig"); + //------------------------------------------------------------------------------ // Data //------------------------------------------------------------------------------ -let MAX_CONFIG_COMBINATIONS = 17, // 16 combinations + 1 for severity only +const MAX_CONFIG_COMBINATIONS = 17, // 16 combinations + 1 for severity only RECOMMENDED_CONFIG_NAME = "eslint:recommended"; //------------------------------------------------------------------------------ // Private //------------------------------------------------------------------------------ -debug = debug("eslint:autoconfig"); - /** * Information about a rule configuration, in the context of a Registry. * @@ -89,7 +88,7 @@ Registry.prototype = { * @returns {void} */ populateFromCoreRules: function() { - let rulesConfig = configRule.createCoreRuleConfigs(); + const rulesConfig = configRule.createCoreRuleConfigs(); this.rules = makeRegistryItems(rulesConfig); }, @@ -109,8 +108,8 @@ Registry.prototype = { * @returns {Object[]} "rules" configurations to use for linting */ buildRuleSets: function() { - let idx = 0, - ruleIds = Object.keys(this.rules), + let idx = 0; + const ruleIds = Object.keys(this.rules), ruleSets = []; /** @@ -122,7 +121,7 @@ Registry.prototype = { * @param {string} rule The ruleId to add. * @returns {void} */ - let addRuleToRuleSet = function(rule) { + const addRuleToRuleSet = function(rule) { /* * This check ensures that there is a rule configuration and that @@ -130,7 +129,7 @@ Registry.prototype = { * If it has too many configs, we will only use the most basic of * the possible configurations. */ - let hasFewCombos = (this.rules[rule].length <= MAX_CONFIG_COMBINATIONS); + const hasFewCombos = (this.rules[rule].length <= MAX_CONFIG_COMBINATIONS); if (this.rules[rule][idx] && (hasFewCombos || this.rules[rule][idx].specificity <= 2)) { @@ -170,12 +169,12 @@ Registry.prototype = { * @returns {void} */ stripFailingConfigs: function() { - let ruleIds = Object.keys(this.rules), + const ruleIds = Object.keys(this.rules), newRegistry = new Registry(); - newRegistry.rules = lodash.assign({}, this.rules); + newRegistry.rules = Object.assign({}, this.rules); ruleIds.forEach(function(ruleId) { - let errorFreeItems = newRegistry.rules[ruleId].filter(function(registryItem) { + const errorFreeItems = newRegistry.rules[ruleId].filter(function(registryItem) { return (registryItem.errorCount === 0); }); @@ -195,10 +194,10 @@ Registry.prototype = { * @returns {void} */ stripExtraConfigs: function() { - let ruleIds = Object.keys(this.rules), + const ruleIds = Object.keys(this.rules), newRegistry = new Registry(); - newRegistry.rules = lodash.assign({}, this.rules); + newRegistry.rules = Object.assign({}, this.rules); ruleIds.forEach(function(ruleId) { newRegistry.rules[ruleId] = newRegistry.rules[ruleId].filter(function(registryItem) { return (typeof registryItem.errorCount !== "undefined"); @@ -216,11 +215,11 @@ Registry.prototype = { * @returns {Registry} A registry of failing rules. */ getFailingRulesRegistry: function() { - let ruleIds = Object.keys(this.rules), + const ruleIds = Object.keys(this.rules), failingRegistry = new Registry(); ruleIds.forEach(function(ruleId) { - let failingConfigs = this.rules[ruleId].filter(function(registryItem) { + const failingConfigs = this.rules[ruleId].filter(function(registryItem) { return (registryItem.errorCount > 0); }); @@ -239,7 +238,7 @@ Registry.prototype = { * @returns {Object} An eslint config with rules section populated */ createConfig: function() { - let ruleIds = Object.keys(this.rules), + const ruleIds = Object.keys(this.rules), config = {rules: {}}; ruleIds.forEach(function(ruleId) { @@ -258,10 +257,10 @@ Registry.prototype = { * @returns {Registry} A registry of rules */ filterBySpecificity: function(specificity) { - let ruleIds = Object.keys(this.rules), + const ruleIds = Object.keys(this.rules), newRegistry = new Registry(); - newRegistry.rules = lodash.assign({}, this.rules); + newRegistry.rules = Object.assign({}, this.rules); ruleIds.forEach(function(ruleId) { newRegistry.rules[ruleId] = this.rules[ruleId].filter(function(registryItem) { return (registryItem.specificity === specificity); @@ -280,25 +279,20 @@ Registry.prototype = { * @returns {Registry} New registry with errorCount populated */ lintSourceCode: function(sourceCodes, config, cb) { - let totalFilesLinting, - lintConfig, - ruleSets, - ruleSetIdx, - filenames, + let ruleSetIdx, lintedRegistry; lintedRegistry = new Registry(); - lintedRegistry.rules = lodash.assign({}, this.rules); + lintedRegistry.rules = Object.assign({}, this.rules); - ruleSets = lintedRegistry.buildRuleSets(); + const ruleSets = lintedRegistry.buildRuleSets(); lintedRegistry = lintedRegistry.stripExtraConfigs(); debug("Linting with all possible rule combinations"); - filenames = Object.keys(sourceCodes); - - totalFilesLinting = filenames.length * ruleSets.length; + const filenames = Object.keys(sourceCodes); + const totalFilesLinting = filenames.length * ruleSets.length; filenames.forEach(function(filename) { debug("Linting file: " + filename); @@ -306,8 +300,8 @@ Registry.prototype = { ruleSetIdx = 0; ruleSets.forEach(function(ruleSet) { - lintConfig = lodash.assign({}, config, {rules: ruleSet}); - let lintResults = eslint.verify(sourceCodes[filename], lintConfig); + const lintConfig = Object.assign({}, config, {rules: ruleSet}); + const lintResults = eslint.verify(sourceCodes[filename], lintConfig); lintResults.forEach(function(result) { @@ -344,11 +338,11 @@ Registry.prototype = { * @returns {Object} config object using `"extends": "eslint:recommended"` */ function extendFromRecommended(config) { - let newConfig = lodash.assign({}, config); + const newConfig = Object.assign({}, config); ConfigOps.normalizeToStrings(newConfig); - let recRules = Object.keys(recConfig.rules).filter(function(ruleId) { + const recRules = Object.keys(recConfig.rules).filter(function(ruleId) { return ConfigOps.isErrorSeverity(recConfig.rules[ruleId]); }); diff --git a/tools/eslint/lib/config/config-file.js b/tools/eslint/lib/config/config-file.js index 9120c12f3c..ca46575120 100644 --- a/tools/eslint/lib/config/config-file.js +++ b/tools/eslint/lib/config/config-file.js @@ -11,9 +11,9 @@ // Requirements //------------------------------------------------------------------------------ -let debug = require("debug"), - fs = require("fs"), +const fs = require("fs"), path = require("path"), + shell = require("shelljs"), ConfigOps = require("./config-ops"), validator = require("./config-validator"), Plugins = require("./plugins"), @@ -26,6 +26,7 @@ let debug = require("debug"), defaultOptions = require("../../conf/eslint.json"), requireUncached = require("require-uncached"); +const debug = require("debug")("eslint:config-file"); //------------------------------------------------------------------------------ // Helpers @@ -48,7 +49,7 @@ function sortByKey(a, b) { // Private //------------------------------------------------------------------------------ -let CONFIG_FILES = [ +const CONFIG_FILES = [ ".eslintrc.js", ".eslintrc.yaml", ".eslintrc.yml", @@ -57,9 +58,7 @@ let CONFIG_FILES = [ "package.json" ]; -let resolver = new ModuleResolver(); - -debug = debug("eslint:config-file"); +const resolver = new ModuleResolver(); /** * Convenience wrapper for synchronously reading file contents. @@ -94,7 +93,7 @@ function loadYAMLConfigFile(filePath) { debug("Loading YAML config file: " + filePath); // lazy load YAML to improve performance when not used - let yaml = require("js-yaml"); + const yaml = require("js-yaml"); try { @@ -137,7 +136,7 @@ function loadLegacyConfigFile(filePath) { debug("Loading config file: " + filePath); // lazy load YAML to improve performance when not used - let yaml = require("js-yaml"); + const yaml = require("js-yaml"); try { return yaml.safeLoad(stripComments(readFile(filePath))) || /* istanbul ignore next */ {}; @@ -192,8 +191,8 @@ function loadPackageJSONConfigFile(filePath) { * @private */ function loadConfigFile(file) { - let config, - filePath = file.filePath; + const filePath = file.filePath; + let config; switch (path.extname(filePath)) { case ".js": @@ -236,7 +235,7 @@ function loadConfigFile(file) { function writeJSONConfigFile(config, filePath) { debug("Writing JSON config file: " + filePath); - let content = stringify(config, {cmp: sortByKey, space: 4}); + const content = stringify(config, {cmp: sortByKey, space: 4}); fs.writeFileSync(filePath, content, "utf8"); } @@ -252,9 +251,9 @@ function writeYAMLConfigFile(config, filePath) { debug("Writing YAML config file: " + filePath); // lazy load YAML to improve performance when not used - let yaml = require("js-yaml"); + const yaml = require("js-yaml"); - let content = yaml.safeDump(config, {sortKeys: true}); + const content = yaml.safeDump(config, {sortKeys: true}); fs.writeFileSync(filePath, content, "utf8"); } @@ -269,7 +268,7 @@ function writeYAMLConfigFile(config, filePath) { function writeJSConfigFile(config, filePath) { debug("Writing JS config file: " + filePath); - let content = "module.exports = " + stringify(config, {cmp: sortByKey, space: 4}) + ";"; + const content = "module.exports = " + stringify(config, {cmp: sortByKey, space: 4}) + ";"; fs.writeFileSync(filePath, content, "utf8"); } @@ -313,7 +312,7 @@ function write(config, filePath) { function getBaseDir(configFilePath) { // calculates the path of the project including ESLint as dependency - let projectPath = path.resolve(__dirname, "../../../"); + const projectPath = path.resolve(__dirname, "../../../"); if (configFilePath && pathIsInside(configFilePath, projectPath)) { @@ -336,7 +335,7 @@ function getBaseDir(configFilePath) { * @private */ function getLookupPath(configFilePath) { - let basedir = getBaseDir(configFilePath); + const basedir = getBaseDir(configFilePath); return path.join(basedir, "node_modules"); } @@ -431,7 +430,7 @@ function normalizePackageName(name, prefix) { * it's a scoped package * package name is "eslint-config", or just a username */ - let scopedPackageShortcutRegex = new RegExp("^(@[^\/]+)(?:\/(?:" + prefix + ")?)?$"), + const scopedPackageShortcutRegex = new RegExp("^(@[^\/]+)(?:\/(?:" + prefix + ")?)?$"), scopedPackageNameRegex = new RegExp("^" + prefix + "(-|$)"); if (scopedPackageShortcutRegex.test(name)) { @@ -466,8 +465,8 @@ function resolve(filePath, relativeTo) { let normalizedPackageName; if (filePath.indexOf("plugin:") === 0) { - let packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7); - let configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1); + const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7); + const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1); normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin"); debug("Attempting to resolve " + normalizedPackageName); @@ -493,10 +492,10 @@ function resolve(filePath, relativeTo) { * @private */ function load(filePath, applyEnvironments, relativeTo) { - let resolvedPath = resolve(filePath, relativeTo), + const resolvedPath = resolve(filePath, relativeTo), dirname = path.dirname(resolvedPath.filePath), - lookupPath = getLookupPath(dirname), - config = loadConfigFile(resolvedPath); + lookupPath = getLookupPath(dirname); + let config = loadConfigFile(resolvedPath); if (config) { @@ -564,12 +563,10 @@ module.exports = { * or null if there is no configuration file in the directory. */ getFilenameForDirectory: function(directory) { - - let filename; - for (let i = 0, len = CONFIG_FILES.length; i < len; i++) { - filename = path.join(directory, CONFIG_FILES[i]); - if (fs.existsSync(filename)) { + const filename = path.join(directory, CONFIG_FILES[i]); + + if (shell.test("-f", filename)) { return filename; } } diff --git a/tools/eslint/lib/config/config-initializer.js b/tools/eslint/lib/config/config-initializer.js index ca52a06c65..36b641147e 100644 --- a/tools/eslint/lib/config/config-initializer.js +++ b/tools/eslint/lib/config/config-initializer.js @@ -9,9 +9,7 @@ // Requirements //------------------------------------------------------------------------------ -let util = require("util"), - debug = require("debug"), - lodash = require("lodash"), +const util = require("util"), inquirer = require("inquirer"), ProgressBar = require("progress"), autoconfig = require("./autoconfig.js"), @@ -22,7 +20,7 @@ let util = require("util"), recConfig = require("../../conf/eslint.json"), log = require("../logging"); -debug = debug("eslint:config-initializer"); +const debug = require("debug")("eslint:config-initializer"); //------------------------------------------------------------------------------ // Private @@ -60,9 +58,7 @@ function writeFile(config, format) { * @returns {void} */ function installModules(config) { - let modules = [], - installStatus, - modulesToInstall; + let modules = []; // Create a list of modules which should be installed based on config if (config.plugins) { @@ -82,11 +78,11 @@ function installModules(config) { // Add eslint to list in case user does not have it installed locally modules.unshift("eslint"); - installStatus = npmUtil.checkDevDeps(modules); + const installStatus = npmUtil.checkDevDeps(modules); // Install packages which aren't already installed - modulesToInstall = Object.keys(installStatus).filter(function(module) { - let notInstalled = installStatus[module] === false; + const modulesToInstall = Object.keys(installStatus).filter(function(module) { + const notInstalled = installStatus[module] === false; if (module === "eslint" && notInstalled) { log.info("Local ESLint installation not found."); @@ -113,31 +109,24 @@ function installModules(config) { * @returns {Object} config object with configured rules */ function configureRules(answers, config) { - let BAR_TOTAL = 20, - BAR_SOURCE_CODE_TOTAL = 4; - - let newConfig = lodash.assign({}, config), - bar, - patterns, - sourceCodes, - fileQty, - registry, - failingRegistry, - disabledConfigs = {}, - singleConfigs, - specTwoConfigs, - specThreeConfigs, - defaultConfigs; + const BAR_TOTAL = 20, + BAR_SOURCE_CODE_TOTAL = 4, + newConfig = Object.assign({}, config), + disabledConfigs = {}; + let sourceCodes, + registry; // Set up a progress bar, as this process can take a long time - bar = new ProgressBar("Determining Config: :percent [:bar] :elapseds elapsed, eta :etas ", { + const bar = new ProgressBar("Determining Config: :percent [:bar] :elapseds elapsed, eta :etas ", { width: 30, total: BAR_TOTAL }); + bar.tick(0); // Shows the progress bar // Get the SourceCode of all chosen files - patterns = answers.patterns.split(/[\s]+/); + const patterns = answers.patterns.split(/[\s]+/); + try { sourceCodes = getSourceCodeOfFiles(patterns, { baseConfig: newConfig, useEslintrc: false }, function(total) { bar.tick((BAR_SOURCE_CODE_TOTAL / total)); @@ -146,7 +135,8 @@ function configureRules(answers, config) { log.info("\n"); throw e; } - fileQty = Object.keys(sourceCodes).length; + const fileQty = Object.keys(sourceCodes).length; + if (fileQty === 0) { log.info("\n"); throw new Error("Automatic Configuration failed. No files were able to be parsed."); @@ -163,12 +153,12 @@ function configureRules(answers, config) { debug("\nRegistry: " + util.inspect(registry.rules, {depth: null})); // Create a list of recommended rules, because we don't want to disable them - let recRules = Object.keys(recConfig.rules).filter(function(ruleId) { + const recRules = Object.keys(recConfig.rules).filter(function(ruleId) { return ConfigOps.isErrorSeverity(recConfig.rules[ruleId]); }); // Find and disable rules which had no error-free configuration - failingRegistry = registry.getFailingRulesRegistry(); + const failingRegistry = registry.getFailingRulesRegistry(); Object.keys(failingRegistry.rules).forEach(function(ruleId) { @@ -181,33 +171,33 @@ function configureRules(answers, config) { // If there is only one config that results in no errors for a rule, we should use it. // createConfig will only add rules that have one configuration in the registry. - singleConfigs = registry.createConfig().rules; + const singleConfigs = registry.createConfig().rules; // The "sweet spot" for number of options in a config seems to be two (severity plus one option). // Very often, a third option (usually an object) is available to address // edge cases, exceptions, or unique situations. We will prefer to use a config with // specificity of two. - specTwoConfigs = registry.filterBySpecificity(2).createConfig().rules; + const specTwoConfigs = registry.filterBySpecificity(2).createConfig().rules; // Maybe a specific combination using all three options works - specThreeConfigs = registry.filterBySpecificity(3).createConfig().rules; + const specThreeConfigs = registry.filterBySpecificity(3).createConfig().rules; // If all else fails, try to use the default (severity only) - defaultConfigs = registry.filterBySpecificity(1).createConfig().rules; + const defaultConfigs = registry.filterBySpecificity(1).createConfig().rules; // Combine configs in reverse priority order (later take precedence) - newConfig.rules = lodash.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs); + newConfig.rules = Object.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs); // Make sure progress bar has finished (floating point rounding) bar.update(BAR_TOTAL); // Log out some stats to let the user know what happened - let finalRuleIds = Object.keys(newConfig.rules), - totalRules = finalRuleIds.length; - let enabledRules = finalRuleIds.filter(function(ruleId) { + const finalRuleIds = Object.keys(newConfig.rules); + const totalRules = finalRuleIds.length; + const enabledRules = finalRuleIds.filter(function(ruleId) { return (newConfig.rules[ruleId] !== 0); }).length; - let resultMessage = [ + const resultMessage = [ "\nEnabled " + enabledRules + " out of " + totalRules, "rules based on " + fileQty, "file" + ((fileQty === 1) ? "." : "s.") @@ -275,9 +265,9 @@ function processAnswers(answers) { * @returns {Object} config object */ function getConfigForStyleGuide(guide) { - let guides = { + const guides = { google: {extends: "google"}, - airbnb: {extends: "airbnb", plugins: ["react"]}, + airbnb: {extends: "airbnb", plugins: ["react", "jsx-a11y", "import"]}, standard: {extends: "standard", plugins: ["standard", "promise"]} }; @@ -419,7 +409,7 @@ function promptUser(callback) { // early exit if you are using automatic style generation if (earlyAnswers.source === "auto") { try { - let combinedAnswers = lodash.assign({}, earlyAnswers, secondAnswers); + const combinedAnswers = Object.assign({}, earlyAnswers, secondAnswers); config = processAnswers(combinedAnswers); installModules(config); @@ -469,7 +459,7 @@ function promptUser(callback) { } ], function(answers) { try { - let totalAnswers = lodash.assign({}, earlyAnswers, secondAnswers, answers); + const totalAnswers = Object.assign({}, earlyAnswers, secondAnswers, answers); config = processAnswers(totalAnswers); installModules(config); @@ -488,7 +478,7 @@ function promptUser(callback) { // Public Interface //------------------------------------------------------------------------------ -let init = { +const init = { getConfigForStyleGuide: getConfigForStyleGuide, processAnswers: processAnswers, initializeConfig: /* istanbul ignore next */ function(callback) { diff --git a/tools/eslint/lib/config/config-ops.js b/tools/eslint/lib/config/config-ops.js index 2e0c29a752..7a52f983f9 100644 --- a/tools/eslint/lib/config/config-ops.js +++ b/tools/eslint/lib/config/config-ops.js @@ -9,17 +9,15 @@ // Requirements //------------------------------------------------------------------------------ -let lodash = require("lodash"), - debug = require("debug"), - Environments = require("./environments"); +const Environments = require("./environments"); + +const debug = require("debug")("eslint:config-ops"); //------------------------------------------------------------------------------ // Private //------------------------------------------------------------------------------ -debug = debug("eslint:config-ops"); - -let RULE_SEVERITY_STRINGS = ["off", "warn", "error"], +const RULE_SEVERITY_STRINGS = ["off", "warn", "error"], RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce(function(map, value, index) { map[value] = index; return map; @@ -53,7 +51,7 @@ module.exports = { */ createEnvironmentConfig: function(env) { - let envConfig = this.createEmptyConfig(); + const envConfig = this.createEmptyConfig(); if (env) { @@ -62,16 +60,16 @@ module.exports = { Object.keys(env).filter(function(name) { return env[name]; }).forEach(function(name) { - let environment = Environments.get(name); + const environment = Environments.get(name); if (environment) { debug("Creating config for environment " + name); if (environment.globals) { - lodash.assign(envConfig.globals, environment.globals); + Object.assign(envConfig.globals, environment.globals); } if (environment.parserOptions) { - lodash.assign(envConfig.parserOptions, environment.parserOptions); + Object.assign(envConfig.parserOptions, environment.parserOptions); } } }); @@ -134,7 +132,7 @@ module.exports = { * (https://github.com/KyleAMathews/deepmerge) * and modified to meet our needs. */ - let array = Array.isArray(src) || Array.isArray(target); + const array = Array.isArray(src) || Array.isArray(target); let dst = array && [] || {}; combine = !!combine; @@ -202,7 +200,7 @@ module.exports = { if (config.rules) { Object.keys(config.rules).forEach(function(ruleId) { - let ruleConfig = config.rules[ruleId]; + const ruleConfig = config.rules[ruleId]; if (typeof ruleConfig === "string") { config.rules[ruleId] = RULE_SEVERITY[ruleConfig.toLowerCase()] || 0; @@ -224,7 +222,7 @@ module.exports = { if (config.rules) { Object.keys(config.rules).forEach(function(ruleId) { - let ruleConfig = config.rules[ruleId]; + const ruleConfig = config.rules[ruleId]; if (typeof ruleConfig === "number") { config.rules[ruleId] = RULE_SEVERITY_STRINGS[ruleConfig] || RULE_SEVERITY_STRINGS[0]; diff --git a/tools/eslint/lib/config/config-rule.js b/tools/eslint/lib/config/config-rule.js index f4c2803ff7..ea8162d42d 100644 --- a/tools/eslint/lib/config/config-rule.js +++ b/tools/eslint/lib/config/config-rule.js @@ -9,7 +9,7 @@ // Requirements //------------------------------------------------------------------------------ -let rules = require("../rules"), +const rules = require("../rules"), loadRules = require("../load-rules"); @@ -41,7 +41,7 @@ function explodeArray(xs) { * @returns {array} A mixture of the elements of the first and second arrays. */ function combineArrays(arr1, arr2) { - let res = []; + const res = []; if (arr1.length === 0) { return explodeArray(arr2); @@ -78,8 +78,8 @@ function combineArrays(arr1, arr2) { * @returns {Array[]} Array of arrays of objects grouped by property */ function groupByProperty(objects) { - let groupedObj = objects.reduce(function(accumulator, obj) { - let prop = Object.keys(obj)[0]; + const groupedObj = objects.reduce(function(accumulator, obj) { + const prop = Object.keys(obj)[0]; accumulator[prop] = accumulator[prop] ? accumulator[prop].concat(obj) : [obj]; return accumulator; @@ -144,7 +144,7 @@ function groupByProperty(objects) { * @returns {Object[]} Combined objects for each combination of input properties and values */ function combinePropertyObjects(objArr1, objArr2) { - let res = []; + const res = []; if (objArr1.length === 0) { return objArr2; @@ -154,9 +154,9 @@ function combinePropertyObjects(objArr1, objArr2) { } objArr1.forEach(function(obj1) { objArr2.forEach(function(obj2) { - let combinedObj = {}; - let obj1Props = Object.keys(obj1); - let obj2Props = Object.keys(obj2); + const combinedObj = {}; + const obj1Props = Object.keys(obj1); + const obj2Props = Object.keys(obj2); obj1Props.forEach(function(prop1) { combinedObj[prop1] = obj1[prop1]; @@ -229,13 +229,12 @@ RuleConfigSet.prototype = { * @returns {void} */ addObject: function(obj) { - let objectConfigSet = { + const objectConfigSet = { objectConfigs: [], add: function(property, values) { - let optionObj; - for (let idx = 0; idx < values.length; idx++) { - optionObj = {}; + const optionObj = {}; + optionObj[property] = values[idx]; this.objectConfigs.push(optionObj); } @@ -274,7 +273,7 @@ RuleConfigSet.prototype = { * @returns {array[]} Valid rule configurations */ function generateConfigsFromSchema(schema) { - let configSet = new RuleConfigSet(); + const configSet = new RuleConfigSet(); if (Array.isArray(schema)) { schema.forEach(function(opt) { @@ -301,11 +300,11 @@ function generateConfigsFromSchema(schema) { * @returns {rulesConfig} Hash of rule names and arrays of possible configurations */ function createCoreRuleConfigs() { - let ruleList = loadRules(); + const ruleList = loadRules(); return Object.keys(ruleList).reduce(function(accumulator, id) { - let rule = rules.get(id); - let schema = (typeof rule === "function") ? rule.schema : rule.meta.schema; + const rule = rules.get(id); + const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema; accumulator[id] = generateConfigsFromSchema(schema); return accumulator; diff --git a/tools/eslint/lib/config/config-validator.js b/tools/eslint/lib/config/config-validator.js index 6695260a23..8bd1e28d82 100644 --- a/tools/eslint/lib/config/config-validator.js +++ b/tools/eslint/lib/config/config-validator.js @@ -9,12 +9,12 @@ // Requirements //------------------------------------------------------------------------------ -let rules = require("../rules"), +const rules = require("../rules"), Environments = require("./environments"), schemaValidator = require("is-my-json-valid"), util = require("util"); -let validators = { +const validators = { rules: Object.create(null) }; @@ -28,7 +28,7 @@ let validators = { * @returns {Object} JSON Schema for the rule's options. */ function getRuleOptionsSchema(id) { - let rule = rules.get(id), + const rule = rules.get(id), schema = rule && rule.schema || rule && rule.meta && rule.meta.schema; // Given a tuple of schemas, insert warning level at the beginning @@ -61,11 +61,10 @@ function getRuleOptionsSchema(id) { * @returns {void} */ function validateRuleOptions(id, options, source) { + const schema = getRuleOptionsSchema(id); let validateRule = validators.rules[id], - message, severity, localOptions, - schema = getRuleOptionsSchema(id), validSeverity = true; if (!validateRule && schema) { @@ -92,7 +91,7 @@ function validateRuleOptions(id, options, source) { } if ((validateRule && validateRule.errors) || !validSeverity) { - message = [ + const message = [ source, ":\n", "\tConfiguration for rule \"", id, "\" is invalid:\n" ]; @@ -137,7 +136,7 @@ function validateEnvironment(environment, source) { if (typeof environment === "object") { Object.keys(environment).forEach(function(env) { if (!Environments.get(env)) { - let message = [ + const message = [ source, ":\n", "\tEnvironment key \"", env, "\" is unknown\n" ]; diff --git a/tools/eslint/lib/config/environments.js b/tools/eslint/lib/config/environments.js index 9a5defbfc2..072d07b63c 100644 --- a/tools/eslint/lib/config/environments.js +++ b/tools/eslint/lib/config/environments.js @@ -8,7 +8,7 @@ // Requirements //------------------------------------------------------------------------------ -let envs = require("../../conf/environments"); +const envs = require("../../conf/environments"); //------------------------------------------------------------------------------ // Private diff --git a/tools/eslint/lib/config/plugins.js b/tools/eslint/lib/config/plugins.js index 7065045c12..9b813f3c14 100644 --- a/tools/eslint/lib/config/plugins.js +++ b/tools/eslint/lib/config/plugins.js @@ -8,19 +8,18 @@ // Requirements //------------------------------------------------------------------------------ -let debug = require("debug"), - Environments = require("./environments"), +const Environments = require("./environments"), rules = require("../rules"); +const debug = require("debug")("eslint:plugins"); + //------------------------------------------------------------------------------ // Private //------------------------------------------------------------------------------ -debug = debug("eslint:plugins"); - let plugins = Object.create(null); -let PLUGIN_NAME_PREFIX = "eslint-plugin-", +const PLUGIN_NAME_PREFIX = "eslint-plugin-", NAMESPACE_REGEX = /^@.*\//i; /** @@ -67,7 +66,7 @@ module.exports = { * @returns {void} */ define: function(pluginName, plugin) { - let pluginNameWithoutNamespace = removeNamespace(pluginName), + const pluginNameWithoutNamespace = removeNamespace(pluginName), pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace); plugins[pluginNameWithoutPrefix] = plugin; @@ -104,10 +103,10 @@ module.exports = { * @throws {Error} If the plugin cannot be loaded. */ load: function(pluginName) { - let pluginNamespace = getNamespace(pluginName), + const pluginNamespace = getNamespace(pluginName), pluginNameWithoutNamespace = removeNamespace(pluginName), - pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace), - plugin = null; + pluginNameWithoutPrefix = removePrefix(pluginNameWithoutNamespace); + let plugin = null; if (!plugins[pluginNameWithoutPrefix]) { try { |