Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Reduce lodash usage #14178

Merged
merged 8 commits into from Mar 9, 2021
7 changes: 3 additions & 4 deletions Makefile.js
Expand Up @@ -13,8 +13,7 @@

require("shelljs/make");

const lodash = require("lodash"),
checker = require("npm-license"),
const checker = require("npm-license"),
ReleaseOps = require("eslint-release"),
dateformat = require("dateformat"),
fs = require("fs"),
Expand Down Expand Up @@ -200,7 +199,7 @@ function generateRuleIndexPage() {
recommended: rule.meta.docs.recommended || false,
fixable: !!rule.meta.fixable
},
category = lodash.find(categoriesData.categories, { name: rule.meta.docs.category });
category = categoriesData.categories.find(c => c.name === rule.meta.docs.category);

if (!category.rules) {
category.rules = [];
Expand Down Expand Up @@ -487,7 +486,7 @@ target.lint = function([fix = false] = []) {
}

echo("Validating JSON Files");
lodash.forEach(JSON_FILES, validateJsonFile);
JSON_FILES.forEach(validateJsonFile);

echo("Validating Markdown Files");
lastReturn = lintMarkdown(MARKDOWN_FILES_ARRAY);
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/formatters/html.js
Expand Up @@ -72,7 +72,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
* @param {Object} message Message.
* @returns {string} HTML (table row) describing a message.
*/
return lodash.map(messages, message => {
return messages.map(message => {
const lineNumber = message.line || 0;
const columnNumber = message.column || 0;
let ruleUrl;
Expand Down Expand Up @@ -103,7 +103,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
* @returns {string} HTML string describing the results.
*/
function renderResults(results, rulesMeta) {
return lodash.map(results, (result, index) => resultTemplate({
return results.map((result, index) => resultTemplate({
index,
color: renderColor(result.errorCount, result.warningCount),
filePath: result.filePath,
Expand Down
4 changes: 2 additions & 2 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -427,12 +427,12 @@ class RuleTester {
scenarioErrors = [],
linter = this.linter;

if (lodash.isNil(test) || typeof test !== "object") {
if (!test || typeof test !== "object") {
throw new TypeError(`Test Scenarios for rule ${ruleName} : Could not find test scenario object`);
}

requiredScenarios.forEach(scenarioType => {
if (lodash.isNil(test[scenarioType])) {
if (!test[scenarioType]) {
scenarioErrors.push(`Could not find any ${scenarioType} test scenarios`);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/eol-last.js
Expand Up @@ -54,7 +54,7 @@ module.exports = {
},
LF = "\n",
CRLF = `\r${LF}`,
endsWithNewline = lodash.endsWith(src, LF);
endsWithNewline = src.endsWith(LF);

/*
* Empty source is always valid: No content in file so we don't
Expand Down
7 changes: 3 additions & 4 deletions lib/rules/lines-around-comment.js
Expand Up @@ -8,8 +8,7 @@
// Requirements
//------------------------------------------------------------------------------

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

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -347,7 +346,7 @@ module.exports = {
const nextTokenOrComment = sourceCode.getTokenAfter(token, { includeComments: true });

// check for newline before
if (!exceptionStartAllowed && before && !lodash.includes(commentAndEmptyLines, prevLineNum) &&
if (!exceptionStartAllowed && before && !commentAndEmptyLines.includes(prevLineNum) &&
!(astUtils.isCommentToken(previousTokenOrComment) && astUtils.isTokenOnSameLine(previousTokenOrComment, token))) {
const lineStart = token.range[0] - token.loc.start.column;
const range = [lineStart, lineStart];
Expand All @@ -362,7 +361,7 @@ module.exports = {
}

// check for newline after
if (!exceptionEndAllowed && after && !lodash.includes(commentAndEmptyLines, nextLineNum) &&
if (!exceptionEndAllowed && after && !commentAndEmptyLines.includes(nextLineNum) &&
!(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) {
context.report({
node: token,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-lines.js
Expand Up @@ -151,7 +151,7 @@ module.exports = {
);

lines = lines.filter(
l => !lodash.includes(commentLines, l.lineNumber)
l => !commentLines.includes(l.lineNumber)
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/object-curly-newline.js
Expand Up @@ -82,7 +82,7 @@ function normalizeOptionValue(value) {
function normalizeOptions(options) {
const isNodeSpecificOption = lodash.overSome([lodash.isPlainObject, lodash.isString]);

if (lodash.isPlainObject(options) && lodash.some(options, isNodeSpecificOption)) {
if (lodash.isPlainObject(options) && Object.values(options).some(isNodeSpecificOption)) {
return {
ObjectExpression: normalizeOptionValue(options.ObjectExpression),
ObjectPattern: normalizeOptionValue(options.ObjectPattern),
Expand Down
3 changes: 1 addition & 2 deletions lib/shared/runtime-info.js
Expand Up @@ -11,7 +11,6 @@

const path = require("path");
const spawn = require("cross-spawn");
const { isEmpty } = require("lodash");
const log = require("../shared/logging");
const packageJson = require("../../package.json");

Expand Down Expand Up @@ -107,7 +106,7 @@ function environment() {
* Checking globally returns an empty JSON object, while local checks
* include the name and version of the local project.
*/
if (isEmpty(parsedStdout) || !(parsedStdout.dependencies && parsedStdout.dependencies.eslint)) {
if (Object.keys(parsedStdout).length === 0 || !(parsedStdout.dependencies && parsedStdout.dependencies.eslint)) {
return "Not found";
}

Expand Down