Skip to content
Permalink
Browse files

Update: Replace several dependencies with lodash (fixes #5012)

  • Loading branch information...
gajus committed Jan 20, 2016
1 parent 3e485cc commit 4e99924cc10351a406ceadbea33ecf6e589866e9
@@ -12,7 +12,8 @@

require("shelljs/make");

var checker = require("npm-license"),
var lodash = require("lodash"),
checker = require("npm-license"),
dateformat = require("dateformat"),
fs = require("fs"),
glob = require("glob"),
@@ -60,7 +61,7 @@ var NODE = "node ", // intentional extra space
MAKEFILE = "./Makefile.js",
PACKAGE = "./package.json",
JS_FILES = find("lib/").filter(fileType("js")).join(" "),
JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc",
JSON_FILES = find("conf/").filter(fileType("json")),
MARKDOWN_FILES_ARRAY = find("docs/").concat(ls(".")).filter(fileType("md")),
TEST_FILES = getTestFilePatterns(),
PERF_ESLINTRC = path.join(PERF_TMP_DIR, "eslintrc.yml"),
@@ -96,6 +97,20 @@ function getTestFilePatterns() {
}, [testLibPath + "rules/**/*.js", testLibPath + "*.js"]).join(" ");
}

/**
* Simple JSON file validation that relies on ES JSON parser.
* @param {string} filePath Path to JSON.
* @throws Error If file contents is invalid JSON.
* @returns {undefined}
*/
function validateJsonFile(filePath) {
var contents;

contents = fs.readFileSync(filePath, "utf8");

JSON.parse(contents);
}

/**
* Generates a function that matches files with a particular extension.
* @param {string} extension The file extension (i.e. "js")
@@ -584,10 +599,7 @@ target.lint = function() {
}

echo("Validating JSON Files");
lastReturn = nodeCLI.exec("jsonlint", "-q -c", JSON_FILES);
if (lastReturn.code !== 0) {
errors++;
}
lodash.forEach(JSON_FILES, validateJsonFile);

echo("Validating Markdown Files");
lastReturn = lintMarkdown(MARKDOWN_FILES_ARRAY);
@@ -20,7 +20,7 @@
var fs = require("fs"),
path = require("path"),

assign = require("object-assign"),
lodash = require("lodash"),
debug = require("debug"),
glob = require("glob"),
shell = require("shelljs"),
@@ -77,7 +77,7 @@ var fs = require("fs"),
// Private
//------------------------------------------------------------------------------

defaultOptions = assign({}, defaultOptions, {cwd: process.cwd()});
defaultOptions = lodash.assign({}, defaultOptions, {cwd: process.cwd()});

//------------------------------------------------------------------------------
// Helpers
@@ -347,7 +347,7 @@ function getCacheFile(cacheFile, cwd) {
*/
function CLIEngine(options) {

options = assign(Object.create(null), defaultOptions, options);
options = lodash.assign(Object.create(null), defaultOptions, options);

/**
* Stored options for this instance
@@ -11,9 +11,8 @@
// Requirements
//------------------------------------------------------------------------------

var assign = require("object-assign"),
var lodash = require("lodash"),
debug = require("debug"),
isEqual = require("lodash.isequal"),
eslint = require("../eslint"),
configRule = require("./config-rule"),
recConfig = require("../../conf/eslint.json");
@@ -160,7 +159,7 @@ Registry.prototype = {
var ruleIds = Object.keys(this.rules),
newRegistry = new Registry();

newRegistry.rules = assign({}, this.rules);
newRegistry.rules = lodash.assign({}, this.rules);
ruleIds.forEach(function(ruleId) {
var errorFreeItems = newRegistry.rules[ruleId].filter(function(registryItem) {
return (registryItem.errorCount === 0);
@@ -184,7 +183,7 @@ Registry.prototype = {
var ruleIds = Object.keys(this.rules),
newRegistry = new Registry();

newRegistry.rules = assign({}, this.rules);
newRegistry.rules = lodash.assign({}, this.rules);
ruleIds.forEach(function(ruleId) {
newRegistry.rules[ruleId] = newRegistry.rules[ruleId].filter(function(registryItem) {
return (typeof registryItem.errorCount !== "undefined");
@@ -246,7 +245,7 @@ Registry.prototype = {
var ruleIds = Object.keys(this.rules),
newRegistry = new Registry();

newRegistry.rules = assign({}, this.rules);
newRegistry.rules = lodash.assign({}, this.rules);
ruleIds.forEach(function(ruleId) {
newRegistry.rules[ruleId] = this.rules[ruleId].filter(function(registryItem) {
return (registryItem.specificity === specificity);
@@ -273,7 +272,7 @@ Registry.prototype = {
lintedRegistry;

lintedRegistry = new Registry();
lintedRegistry.rules = assign({}, this.rules);
lintedRegistry.rules = lodash.assign({}, this.rules);
ruleSets = lintedRegistry.buildRuleSets();
lintedRegistry = lintedRegistry.stripExtraConfigs();

@@ -284,12 +283,11 @@ Registry.prototype = {
debug("Linting file: " + filename);
ruleSetIdx = 0;
ruleSets.forEach(function(ruleSet) {
lintConfig = assign({}, config, {rules: ruleSet});
lintConfig = lodash.assign({}, config, {rules: ruleSet});
var lintResults = eslint.verify(sourceCodes[filename], lintConfig);
lintResults.forEach(function(result) {
lintedRegistry.rules[result.ruleId][ruleSetIdx].errorCount += 1;
});

ruleSetIdx += 1;
if (cb) {
cb(totalFilesLinting); // eslint-disable-line callback-return
@@ -313,13 +311,13 @@ Registry.prototype = {
* @returns {Object} config object using `"extends": "eslint:recommended"`
*/
function extendFromRecommended(config) {
var newConfig = assign({}, config);
var newConfig = lodash.assign({}, config);
var recRules = Object.keys(recConfig.rules).filter(function(ruleId) {
return (recConfig.rules[ruleId] === 2 || recConfig.rules[ruleId][0] === 2);
});

recRules.forEach(function(ruleId) {
if (isEqual(recConfig.rules[ruleId], newConfig.rules[ruleId])) {
if (lodash.isEqual(recConfig.rules[ruleId], newConfig.rules[ruleId])) {
delete newConfig.rules[ruleId];
}
});
@@ -11,8 +11,8 @@
//------------------------------------------------------------------------------

var util = require("util"),
assign = require("object-assign"),
debug = require("debug"),
lodash = require("lodash"),
inquirer = require("inquirer"),
ProgressBar = require("progress"),
autoconfig = require("./autoconfig.js"),
@@ -109,7 +109,7 @@ function configureRules(answers, config, callback) {
var BAR_TOTAL = 20,
BAR_SOURCE_CODE_TOTAL = 4;

var newConfig = assign({}, config),
var newConfig = lodash.assign({}, config),
bar,
patterns,
sourceCodes,
@@ -187,7 +187,7 @@ function configureRules(answers, config, callback) {
defaultConfigs = registry.filterBySpecificity(1).createConfig().rules;

// Combine configs in reverse priority order (later take precedence)
newConfig.rules = assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs);
newConfig.rules = lodash.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs);

// Make sure progress bar has finished (floating point rounding)
bar.update(BAR_TOTAL);
@@ -395,7 +395,7 @@ function promptUser(callback) {
log.error("Unfortunately, autoconfig does not yet work for JSX code.\nPlease see https://github.com/eslint/eslint/issues/5007 for current status.");
return;
}
var combinedAnswers = assign({}, earlyAnswers, secondAnswers);
var combinedAnswers = lodash.assign({}, earlyAnswers, secondAnswers);
config = processAnswers(combinedAnswers, callback);
installModules(config);
writeFile(config, earlyAnswers.format, callback);
@@ -11,9 +11,9 @@
// Requirements
//------------------------------------------------------------------------------

var debug = require("debug"),
Environments = require("./environments"),
assign = require("object-assign");
var lodash = require("lodash"),
debug = require("debug"),
Environments = require("./environments");

//------------------------------------------------------------------------------
// Private
@@ -62,11 +62,11 @@ module.exports = {
if (environment) {
debug("Creating config for environment " + name);
if (environment.globals) {
assign(envConfig.globals, environment.globals);
lodash.assign(envConfig.globals, environment.globals);
}

if (environment.parserOptions) {
assign(envConfig.parserOptions, environment.parserOptions);
lodash.assign(envConfig.parserOptions, environment.parserOptions);
}
}
});
@@ -10,11 +10,11 @@
// Requirements
//------------------------------------------------------------------------------

var estraverse = require("./util/estraverse"),
var lodash = require("lodash"),
estraverse = require("./util/estraverse"),
escope = require("escope"),
Environments = require("./config/environments"),
blankScriptAST = require("../conf/blank-script.json"),
assign = require("object-assign"),
rules = require("./rules"),
RuleContext = require("./rule-context"),
timing = require("./timing"),
@@ -130,21 +130,21 @@ function addDeclaredGlobals(program, globalScope, config) {
explicitGlobals = {},
builtin = Environments.get("builtin");

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

Object.keys(config.env).forEach(function(name) {
if (config.env[name]) {
var env = Environments.get(name),
environmentGlobals = env && env.globals;
if (environmentGlobals) {
assign(declaredGlobals, environmentGlobals);
lodash.assign(declaredGlobals, environmentGlobals);
}
}
});

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

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

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

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

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

return ConfigOps.merge(config, commentConfig);
}
@@ -479,7 +479,7 @@ function findEslintEnv(text) {

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

return retv;
@@ -561,7 +561,7 @@ module.exports = (function() {

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

/*
@@ -691,10 +691,10 @@ module.exports = (function() {
var envInFile = findEslintEnv(text || textOrSourceCode.text);
if (envInFile) {
if (!config || !config.env) {
config = assign({}, config || {}, {env: envInFile});
config = lodash.assign({}, config || {}, {env: envInFile});
} else {
config = assign({}, config);
config.env = assign({}, config.env, envInFile);
config = lodash.assign({}, config);
config.env = lodash.assign({}, config.env, envInFile);
}
}

@@ -0,0 +1,8 @@
<tr style="display:none" class="f-<%= parentIndex %>">
<td><%= lineNumber %>:<%= columnNumber %></td>
<td class="clr-<%= severityNumber %>"><%= severityName %></td>
<td><%- message %></td>
<td>
<a href="http://eslint.org/docs/rules/<%= ruleId %>" target="_blank"><%= ruleId %></a>
</td>
</tr>
@@ -86,32 +86,15 @@
</style>
</head>
<body>
<div id="overview" class="bg-{{getColor totalErrors totalWarnings}}">
<div id="overview" class="bg-<%= reportColor %>">
<h1>ESLint Report</h1>
<div>
<span>{{renderText totalErrors totalWarnings}}</span> - Generated on {{date}}
<span><%= reportSummary %></span> - Generated on <%= date %>
</div>
</div>
<table>
<tbody>
{{#each results}}
<tr class="bg-{{getColor this.errorCount this.warningCount}}" data-group="f-{{@index}}">
<th colspan="4">
[+] {{this.filePath}}
<span>{{renderText this.errorCount this.warningCount}}</span>
</th>
</tr>
{{#each this.messages}}
<tr class="f-{{@../index}}" style="display:none">
<td>{{#if this.line}}{{this.line}}{{else}}0{{/if}}:{{#if this.column}}{{this.column}}{{else}}0{{/if}}</td>
{{getSeverity this.severity}}
<td>{{this.message}}</td>
<td>
<a href="http://eslint.org/docs/rules/{{this.ruleId}}" target="_blank">{{this.ruleId}}</a>
</td>
</tr>
{{/each}}
{{/each}}
<%= results %>
</tbody>
</table>
<script type="text/javascript">
@@ -127,4 +110,4 @@ <h1>ESLint Report</h1>
}
</script>
</body>
</html>
</html>
@@ -0,0 +1,6 @@
<tr class="bg-<%- color %>" data-group="f-<%- index %>">
<th colspan="4">
[+] <%- filePath %>
<span><%- summary %></span>
</th>
</tr>
Oops, something went wrong.

0 comments on commit 4e99924

Please sign in to comment.
You can’t perform that action at this time.