Skip to content

Commit

Permalink
Chore: use native Object.assign (refs #6407) (#6832)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyandeeps authored and alberto committed Aug 3, 2016
1 parent 579ec49 commit cdded07
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 68 deletions.
5 changes: 1 addition & 4 deletions lib/cli-engine.js
Expand Up @@ -17,9 +17,6 @@

const fs = require("fs"),
path = require("path"),

lodash = require("lodash"),

rules = require("./rules"),
eslint = require("./eslint"),
defaultOptions = require("../conf/cli-options"),
Expand Down Expand Up @@ -436,7 +433,7 @@ function getCacheFile(cacheFile, cwd) {
*/
function CLIEngine(options) {

options = lodash.assign(
options = Object.assign(
Object.create(null),
defaultOptions,
{cwd: process.cwd()},
Expand Down
12 changes: 6 additions & 6 deletions lib/config/autoconfig.js
Expand Up @@ -172,7 +172,7 @@ Registry.prototype = {
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) {
const errorFreeItems = newRegistry.rules[ruleId].filter(function(registryItem) {
return (registryItem.errorCount === 0);
Expand All @@ -197,7 +197,7 @@ Registry.prototype = {
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");
Expand Down Expand Up @@ -260,7 +260,7 @@ Registry.prototype = {
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);
Expand All @@ -283,7 +283,7 @@ Registry.prototype = {
lintedRegistry;

lintedRegistry = new Registry();
lintedRegistry.rules = lodash.assign({}, this.rules);
lintedRegistry.rules = Object.assign({}, this.rules);

const ruleSets = lintedRegistry.buildRuleSets();

Expand All @@ -300,7 +300,7 @@ Registry.prototype = {
ruleSetIdx = 0;

ruleSets.forEach(function(ruleSet) {
const lintConfig = lodash.assign({}, config, {rules: ruleSet});
const lintConfig = Object.assign({}, config, {rules: ruleSet});
const lintResults = eslint.verify(sourceCodes[filename], lintConfig);

lintResults.forEach(function(result) {
Expand Down Expand Up @@ -338,7 +338,7 @@ Registry.prototype = {
* @returns {Object} config object using `"extends": "eslint:recommended"`
*/
function extendFromRecommended(config) {
const newConfig = lodash.assign({}, config);
const newConfig = Object.assign({}, config);

ConfigOps.normalizeToStrings(newConfig);

Expand Down
9 changes: 4 additions & 5 deletions lib/config/config-initializer.js
Expand Up @@ -10,7 +10,6 @@
//------------------------------------------------------------------------------

const util = require("util"),
lodash = require("lodash"),
inquirer = require("inquirer"),
ProgressBar = require("progress"),
autoconfig = require("./autoconfig.js"),
Expand Down Expand Up @@ -112,7 +111,7 @@ function installModules(config) {
function configureRules(answers, config) {
const BAR_TOTAL = 20,
BAR_SOURCE_CODE_TOTAL = 4,
newConfig = lodash.assign({}, config),
newConfig = Object.assign({}, config),
disabledConfigs = {};
let sourceCodes,
registry;
Expand Down Expand Up @@ -187,7 +186,7 @@ function configureRules(answers, config) {
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);
Expand Down Expand Up @@ -410,7 +409,7 @@ function promptUser(callback) {
// early exit if you are using automatic style generation
if (earlyAnswers.source === "auto") {
try {
const combinedAnswers = lodash.assign({}, earlyAnswers, secondAnswers);
const combinedAnswers = Object.assign({}, earlyAnswers, secondAnswers);

config = processAnswers(combinedAnswers);
installModules(config);
Expand Down Expand Up @@ -460,7 +459,7 @@ function promptUser(callback) {
}
], function(answers) {
try {
const totalAnswers = lodash.assign({}, earlyAnswers, secondAnswers, answers);
const totalAnswers = Object.assign({}, earlyAnswers, secondAnswers, answers);

config = processAnswers(totalAnswers);
installModules(config);
Expand Down
7 changes: 3 additions & 4 deletions lib/config/config-ops.js
Expand Up @@ -9,8 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const lodash = require("lodash"),
Environments = require("./environments");
const Environments = require("./environments");

const debug = require("debug")("eslint:config-ops");

Expand Down Expand Up @@ -66,11 +65,11 @@ module.exports = {
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);
}
}
});
Expand Down
29 changes: 14 additions & 15 deletions lib/eslint.js
Expand Up @@ -13,7 +13,6 @@ const assert = require("assert"),
EventEmitter = require("events").EventEmitter,
escope = require("escope"),
levn = require("levn"),
lodash = require("lodash"),
blankScriptAST = require("../conf/blank-script.json"),
DEFAULT_PARSER = require("../conf/eslint.json").parser,
replacements = require("../conf/replacements.json"),
Expand Down Expand Up @@ -152,22 +151,22 @@ function addDeclaredGlobals(program, globalScope, config) {
explicitGlobals = {},
builtin = Environments.get("builtin");

lodash.assign(declaredGlobals, builtin);
Object.assign(declaredGlobals, builtin);

Object.keys(config.env).forEach(function(name) {
if (config.env[name]) {
const env = Environments.get(name),
environmentGlobals = env && env.globals;

if (environmentGlobals) {
lodash.assign(declaredGlobals, environmentGlobals);
Object.assign(declaredGlobals, environmentGlobals);
}
}
});

lodash.assign(exportedGlobals, config.exported);
lodash.assign(declaredGlobals, config.globals);
lodash.assign(explicitGlobals, config.astGlobals);
Object.assign(exportedGlobals, config.exported);
Object.assign(declaredGlobals, config.globals);
Object.assign(explicitGlobals, config.astGlobals);

Object.keys(declaredGlobals).forEach(function(name) {
let variable = globalScope.set.get(name);
Expand Down Expand Up @@ -325,16 +324,16 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
if (comment.type === "Block") {
switch (match[1]) {
case "exported":
lodash.assign(commentConfig.exported, parseBooleanConfig(value, comment));
Object.assign(commentConfig.exported, parseBooleanConfig(value, comment));
break;

case "globals":
case "global":
lodash.assign(commentConfig.astGlobals, parseBooleanConfig(value, comment));
Object.assign(commentConfig.astGlobals, parseBooleanConfig(value, comment));
break;

case "eslint-env":
lodash.assign(commentConfig.env, parseListConfig(value));
Object.assign(commentConfig.env, parseListConfig(value));
break;

case "eslint-disable":
Expand Down Expand Up @@ -379,7 +378,7 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
commentConfig = ConfigOps.merge(commentConfig, env);
}
});
lodash.assign(commentConfig.rules, commentRules);
Object.assign(commentConfig.rules, commentRules);

return ConfigOps.merge(config, commentConfig);
}
Expand Down Expand Up @@ -527,7 +526,7 @@ function findEslintEnv(text) {
eslintEnvPattern.lastIndex = 0;

while ((match = eslintEnvPattern.exec(text))) {
retv = lodash.assign(retv || {}, parseListConfig(match[1]));
retv = Object.assign(retv || {}, parseListConfig(match[1]));
}

return retv;
Expand Down Expand Up @@ -612,7 +611,7 @@ module.exports = (function() {

// merge in any additional parser options
if (config.parserOptions) {
parserOptions = lodash.assign({}, config.parserOptions, parserOptions);
parserOptions = Object.assign({}, config.parserOptions, parserOptions);
}

/*
Expand Down Expand Up @@ -740,10 +739,10 @@ module.exports = (function() {

if (envInFile) {
if (!config || !config.env) {
config = lodash.assign({}, config || {}, {env: envInFile});
config = Object.assign({}, config || {}, {env: envInFile});
} else {
config = lodash.assign({}, config);
config.env = lodash.assign({}, config.env, envInFile);
config = Object.assign({}, config);
config.env = Object.assign({}, config.env, envInFile);
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/ignored-paths.js
Expand Up @@ -9,8 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const lodash = require("lodash"),
fs = require("fs"),
const fs = require("fs"),
path = require("path"),
ignore = require("ignore"),
pathUtil = require("./util/path-util");
Expand Down Expand Up @@ -58,7 +57,7 @@ function findIgnoreFile(cwd) {
*/
function mergeDefaultOptions(options) {
options = (options || {});
return lodash.assign({}, DEFAULT_OPTIONS, options);
return Object.assign({}, DEFAULT_OPTIONS, options);
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/indent.js
Expand Up @@ -12,7 +12,6 @@
// Rule Definition
//------------------------------------------------------------------------------
const util = require("util");
const lodash = require("lodash");

module.exports = {
meta: {
Expand Down Expand Up @@ -123,7 +122,7 @@ module.exports = {
const: variableDeclaratorRules
};
} else if (typeof variableDeclaratorRules === "object") {
lodash.assign(options.VariableDeclarator, variableDeclaratorRules);
Object.assign(options.VariableDeclarator, variableDeclaratorRules);
}

if (typeof opts.outerIIFEBody === "number") {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/lines-around-comment.js
Expand Up @@ -108,7 +108,7 @@ module.exports = {

create: function(context) {

const options = context.options[0] ? lodash.assign({}, context.options[0]) : {};
const options = context.options[0] ? Object.assign({}, context.options[0]) : {};

options.beforeLineComment = options.beforeLineComment || false;
options.afterLineComment = options.afterLineComment || false;
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/new-cap.js
Expand Up @@ -9,8 +9,6 @@
// Requirements
//------------------------------------------------------------------------------

const lodash = require("lodash");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -115,7 +113,7 @@ module.exports = {

create: function(context) {

const config = context.options[0] ? lodash.assign({}, context.options[0]) : {};
const config = context.options[0] ? Object.assign({}, context.options[0]) : {};

config.newIsCap = config.newIsCap !== false;
config.capIsNew = config.capIsNew !== false;
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/operator-linebreak.js
Expand Up @@ -5,8 +5,7 @@

"use strict";

const lodash = require("lodash"),
astUtils = require("../ast-utils");
const astUtils = require("../ast-utils");

//------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -47,7 +46,7 @@ module.exports = {
const usedDefaultGlobal = !context.options[0];
const globalStyle = context.options[0] || "after";
const options = context.options[1] || {};
const styleOverrides = options.overrides ? lodash.assign({}, options.overrides) : {};
const styleOverrides = options.overrides ? Object.assign({}, options.overrides) : {};

if (usedDefaultGlobal && !styleOverrides["?"]) {
styleOverrides["?"] = "before";
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/require-jsdoc.js
Expand Up @@ -4,8 +4,6 @@
*/
"use strict";

const lodash = require("lodash");

module.exports = {
meta: {
docs: {
Expand Down Expand Up @@ -46,7 +44,7 @@ module.exports = {
MethodDefinition: false,
ClassDeclaration: false
};
const options = lodash.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});
const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require || {});

/**
* Report the error message
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/strict.js
Expand Up @@ -9,8 +9,6 @@
// Requirements
//------------------------------------------------------------------------------

const lodash = require("lodash");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -231,7 +229,7 @@ module.exports = {
};

if (mode === "function") {
lodash.assign(rule, {
Object.assign(rule, {

// Inside of class bodies are always strict mode.
ClassBody: function() {
Expand Down
5 changes: 2 additions & 3 deletions lib/util/module-resolver.js
Expand Up @@ -9,8 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const lodash = require("lodash"),
Module = require("module");
const Module = require("module");

//------------------------------------------------------------------------------
// Private
Expand Down Expand Up @@ -39,7 +38,7 @@ const DEFAULT_OPTIONS = {
function ModuleResolver(options) {
options = options || {};

this.options = lodash.assign({}, DEFAULT_OPTIONS, options);
this.options = Object.assign({}, DEFAULT_OPTIONS, options);
}

ModuleResolver.prototype = {
Expand Down

0 comments on commit cdded07

Please sign in to comment.