From eba5d52a89fadbf9b4c9dc26786bc2884171993d Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Mon, 30 May 2022 16:19:26 +0530 Subject: [PATCH] Revert "chore: enable some rules from eslint-plugin-unicorn internally (#15878)" This reverts commit bfa354597066e20d32dc3a38fe4b544f323b861d. --- Makefile.js | 6 +++--- lib/cli-engine/cli-engine.js | 6 ++++-- lib/cli-engine/lint-result-cache.js | 2 +- .../code-path-analysis/code-path-segment.js | 2 +- lib/linter/code-path-analysis/code-path-state.js | 2 +- lib/linter/code-path-analysis/code-path.js | 2 +- lib/rules/accessor-pairs.js | 8 ++++---- lib/rules/callback-return.js | 4 ++-- lib/rules/capitalized-comments.js | 2 +- lib/rules/consistent-this.js | 2 +- lib/rules/dot-notation.js | 4 ++-- lib/rules/global-require.js | 6 +++--- lib/rules/indent-legacy.js | 4 ++-- lib/rules/indent.js | 2 +- lib/rules/jsx-quotes.js | 2 +- lib/rules/lines-around-comment.js | 6 +++--- lib/rules/max-lines.js | 4 ++-- lib/rules/newline-before-return.js | 2 +- lib/rules/no-bitwise.js | 4 ++-- lib/rules/no-console.js | 2 +- lib/rules/no-empty-function.js | 2 +- lib/rules/no-extra-boolean-cast.js | 6 +++--- lib/rules/no-extra-semi.js | 2 +- lib/rules/no-global-assign.js | 2 +- lib/rules/no-implicit-coercion.js | 12 ++++++------ lib/rules/no-magic-numbers.js | 6 +++--- lib/rules/no-mixed-operators.js | 2 +- lib/rules/no-mixed-requires.js | 2 +- lib/rules/no-multi-spaces.js | 2 +- lib/rules/no-native-reassign.js | 2 +- lib/rules/no-new-wrappers.js | 2 +- lib/rules/no-prototype-builtins.js | 6 +++--- lib/rules/no-shadow.js | 10 +++++----- lib/rules/no-sparse-arrays.js | 2 +- lib/rules/no-underscore-dangle.js | 2 +- lib/rules/no-unused-expressions.js | 2 +- lib/rules/no-unused-vars.js | 2 +- lib/rules/operator-assignment.js | 4 ++-- lib/rules/prefer-const.js | 2 +- lib/rules/prefer-reflect.js | 4 ++-- lib/rules/prefer-regex-literals.js | 6 +++--- lib/rules/quote-props.js | 4 ++-- lib/rules/quotes.js | 2 +- lib/rules/spaced-comment.js | 2 +- lib/rules/valid-jsdoc.js | 2 +- lib/rules/valid-typeof.js | 8 ++++---- lib/rules/yoda.js | 2 +- package.json | 1 - packages/eslint-config-eslint/default.yml | 15 --------------- packages/eslint-config-eslint/package.json | 3 +-- tests/lib/cli.js | 6 +++--- tests/lib/linter/node-event-generator.js | 4 ++-- tests/lib/rules/no-invalid-this.js | 3 ++- tools/code-sample-minimizer.js | 6 ++++-- 54 files changed, 99 insertions(+), 111 deletions(-) diff --git a/Makefile.js b/Makefile.js index 49d3093c1f0..e0a19541468 100644 --- a/Makefile.js +++ b/Makefile.js @@ -614,7 +614,7 @@ target.gensite = function(prereleaseVersion) { if (test("-f", fullPath)) { rm("-rf", fullPath); - if (filePath.includes(".md") && test("-f", htmlFullPath)) { + if (filePath.indexOf(".md") >= 0 && test("-f", htmlFullPath)) { rm("-rf", htmlFullPath); } } @@ -673,7 +673,7 @@ target.gensite = function(prereleaseVersion) { process.stdout.write(`> Updating files (Steps 4-9): ${i}/${length} - ${filePath + " ".repeat(30)}\r`); // 5. Prepend page title and layout variables at the top of rules - if (path.dirname(filename).includes("rules")) { + if (path.dirname(filename).indexOf("rules") >= 0) { // Find out if the rule requires a special docs portion (e.g. if it is recommended and/or fixable) const rule = rules.get(ruleName); @@ -696,7 +696,7 @@ target.gensite = function(prereleaseVersion) { } // 8. Append first version of ESLint rule was added at. - if (filename.includes("rules/")) { + if (filename.indexOf("rules/") !== -1) { if (!versions.added[baseName]) { versions.added[baseName] = getFirstVersionOfFile(sourcePath); } diff --git a/lib/cli-engine/cli-engine.js b/lib/cli-engine/cli-engine.js index fdc66198809..f7aa9e2242a 100644 --- a/lib/cli-engine/cli-engine.js +++ b/lib/cli-engine/cli-engine.js @@ -366,7 +366,9 @@ function *iterateRuleDeprecationWarnings(usedConfigArrays) { // Flatten used configs. /** @type {ExtractedConfig[]} */ - const configs = usedConfigArrays.flatMap(getUsedExtractedConfigs); + const configs = [].concat( + ...usedConfigArrays.map(getUsedExtractedConfigs) + ); // Traverse rule configs. for (const config of configs) { @@ -1021,7 +1023,7 @@ class CLIEngine { let formatterPath; // if there's a slash, then it's a file (TODO: this check seems dubious for scoped npm packages) - if (!namespace && normalizedFormatName.includes("/")) { + if (!namespace && normalizedFormatName.indexOf("/") > -1) { formatterPath = path.resolve(cwd, normalizedFormatName); } else { try { diff --git a/lib/cli-engine/lint-result-cache.js b/lib/cli-engine/lint-result-cache.js index e36eb74bada..3304d429deb 100644 --- a/lib/cli-engine/lint-result-cache.js +++ b/lib/cli-engine/lint-result-cache.js @@ -36,7 +36,7 @@ const invalidCacheStrategyErrorMessage = `Cache strategy must be one of: ${valid */ function isValidCacheStrategy(cacheStrategy) { return ( - validCacheStrategies.includes(cacheStrategy) + validCacheStrategies.indexOf(cacheStrategy) !== -1 ); } diff --git a/lib/linter/code-path-analysis/code-path-segment.js b/lib/linter/code-path-analysis/code-path-segment.js index eeedd27524b..fad559a2ad2 100644 --- a/lib/linter/code-path-analysis/code-path-segment.js +++ b/lib/linter/code-path-analysis/code-path-segment.js @@ -100,7 +100,7 @@ class CodePathSegment { * @returns {boolean} `true` if the segment is coming from the end of a loop. */ isLoopedPrevSegment(segment) { - return this.internal.loopedPrevSegments.includes(segment); + return this.internal.loopedPrevSegments.indexOf(segment) !== -1; } /** diff --git a/lib/linter/code-path-analysis/code-path-state.js b/lib/linter/code-path-analysis/code-path-state.js index 426da8d492e..118f70a1707 100644 --- a/lib/linter/code-path-analysis/code-path-state.js +++ b/lib/linter/code-path-analysis/code-path-state.js @@ -33,7 +33,7 @@ function addToReturnedOrThrown(dest, others, all, segments) { const segment = segments[i]; dest.push(segment); - if (!others.includes(segment)) { + if (others.indexOf(segment) === -1) { all.push(segment); } } diff --git a/lib/linter/code-path-analysis/code-path.js b/lib/linter/code-path-analysis/code-path.js index a028ca69481..0e666277094 100644 --- a/lib/linter/code-path-analysis/code-path.js +++ b/lib/linter/code-path-analysis/code-path.js @@ -212,7 +212,7 @@ class CodePath { } // Reset the flag of skipping if all branches have been skipped. - if (skippedSegment && segment.prevSegments.includes(skippedSegment)) { + if (skippedSegment && segment.prevSegments.indexOf(skippedSegment) !== -1) { skippedSegment = null; } visited[segment.id] = true; diff --git a/lib/rules/accessor-pairs.js b/lib/rules/accessor-pairs.js index 33887affef2..2fcf1535290 100644 --- a/lib/rules/accessor-pairs.js +++ b/lib/rules/accessor-pairs.js @@ -299,12 +299,12 @@ module.exports = { * @private */ function checkPropertyDescriptor(node) { - const namesToCheck = new Set(node.properties + const namesToCheck = node.properties .filter(p => p.type === "Property" && p.kind === "init" && !p.computed) - .map(({ key }) => key.name)); + .map(({ key }) => key.name); - const hasGetter = namesToCheck.has("get"); - const hasSetter = namesToCheck.has("set"); + const hasGetter = namesToCheck.includes("get"); + const hasSetter = namesToCheck.includes("set"); if (checkSetWithoutGet && hasSetter && !hasGetter) { report(node, "missingGetter"); diff --git a/lib/rules/callback-return.js b/lib/rules/callback-return.js index 34b74631f0c..532faee4518 100644 --- a/lib/rules/callback-return.js +++ b/lib/rules/callback-return.js @@ -53,7 +53,7 @@ module.exports = { if (!node.parent) { return null; } - if (!types.includes(node.parent.type)) { + if (types.indexOf(node.parent.type) === -1) { return findClosestParentOfType(node.parent, types); } return node.parent; @@ -87,7 +87,7 @@ module.exports = { * @returns {boolean} Whether or not this function matches our callback name. */ function isCallback(node) { - return containsOnlyIdentifiers(node.callee) && callbacks.includes(sourceCode.getText(node.callee)); + return containsOnlyIdentifiers(node.callee) && callbacks.indexOf(sourceCode.getText(node.callee)) > -1; } /** diff --git a/lib/rules/capitalized-comments.js b/lib/rules/capitalized-comments.js index dffe9565003..6ea87a70a81 100644 --- a/lib/rules/capitalized-comments.js +++ b/lib/rules/capitalized-comments.js @@ -185,7 +185,7 @@ module.exports = { return Boolean( previousTokenOrComment && - ["Block", "Line"].includes(previousTokenOrComment.type) + ["Block", "Line"].indexOf(previousTokenOrComment.type) !== -1 ); } diff --git a/lib/rules/consistent-this.js b/lib/rules/consistent-this.js index 2aa07914638..a613f992d7a 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -65,7 +65,7 @@ module.exports = { function checkAssignment(node, name, value) { const isThis = value.type === "ThisExpression"; - if (aliases.includes(name)) { + if (aliases.indexOf(name) !== -1) { if (!isThis || node.operator && node.operator !== "=") { reportBadAssignment(node, name); } diff --git a/lib/rules/dot-notation.js b/lib/rules/dot-notation.js index 90ba6d83b76..6f6b5166f76 100644 --- a/lib/rules/dot-notation.js +++ b/lib/rules/dot-notation.js @@ -76,7 +76,7 @@ module.exports = { function checkComputedProperty(node, value) { if ( validIdentifier.test(value) && - (allowKeywords || !keywords.includes(String(value))) && + (allowKeywords || keywords.indexOf(String(value)) === -1) && !(allowPattern && allowPattern.test(value)) ) { const formattedValue = node.property.type === "Literal" ? JSON.stringify(value) : `\`${value}\``; @@ -142,7 +142,7 @@ module.exports = { !allowKeywords && !node.computed && node.property.type === "Identifier" && - keywords.includes(String(node.property.name)) + keywords.indexOf(String(node.property.name)) !== -1 ) { context.report({ node: node.property, diff --git a/lib/rules/global-require.js b/lib/rules/global-require.js index 71a2bf1ac49..f00ca9bf6dd 100644 --- a/lib/rules/global-require.js +++ b/lib/rules/global-require.js @@ -6,7 +6,7 @@ "use strict"; -const ACCEPTABLE_PARENTS = new Set([ +const ACCEPTABLE_PARENTS = [ "AssignmentExpression", "VariableDeclarator", "MemberExpression", @@ -16,7 +16,7 @@ const ACCEPTABLE_PARENTS = new Set([ "Program", "VariableDeclaration", "ChainExpression" -]); +]; /** * Finds the eslint-scope reference in the given scope. @@ -75,7 +75,7 @@ module.exports = { const currentScope = context.getScope(); if (node.callee.name === "require" && !isShadowed(currentScope, node.callee)) { - const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.has(parent.type)); + const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1); if (!isGoodRequire) { context.report({ node, messageId: "unexpected" }); diff --git a/lib/rules/indent-legacy.js b/lib/rules/indent-legacy.js index c5be4a5d134..bd61f6f8431 100644 --- a/lib/rules/indent-legacy.js +++ b/lib/rules/indent-legacy.js @@ -753,7 +753,7 @@ module.exports = { if (typeof options.CallExpression.arguments === "number") { nodeIndent += options.CallExpression.arguments * indentSize; } else if (options.CallExpression.arguments === "first") { - if (parent.arguments.includes(node)) { + if (parent.arguments.indexOf(node) !== -1) { nodeIndent = parent.arguments[0].loc.start.column; } } else { @@ -840,7 +840,7 @@ module.exports = { "IfStatement", "WhileStatement", "ForStatement", "ForInStatement", "ForOfStatement", "DoWhileStatement", "ClassDeclaration", "TryStatement" ]; - if (node.parent && statementsWithProperties.includes(node.parent.type) && isNodeBodyBlock(node)) { + if (node.parent && statementsWithProperties.indexOf(node.parent.type) !== -1 && isNodeBodyBlock(node)) { indent = getNodeIndent(node.parent).goodChar; } else if (node.parent && node.parent.type === "CatchClause") { indent = getNodeIndent(node.parent.parent).goodChar; diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 9c534cd58f0..6152bc561f9 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -796,7 +796,7 @@ module.exports = { let statement = node.parent && node.parent.parent; while ( - statement.type === "UnaryExpression" && ["!", "~", "+", "-"].includes(statement.operator) || + statement.type === "UnaryExpression" && ["!", "~", "+", "-"].indexOf(statement.operator) > -1 || statement.type === "AssignmentExpression" || statement.type === "LogicalExpression" || statement.type === "SequenceExpression" || diff --git a/lib/rules/jsx-quotes.js b/lib/rules/jsx-quotes.js index f63dfd608bc..a0cdfaa62be 100644 --- a/lib/rules/jsx-quotes.js +++ b/lib/rules/jsx-quotes.js @@ -70,7 +70,7 @@ module.exports = { * @public */ function usesExpectedQuotes(node) { - return node.value.includes(setting.quote) || astUtils.isSurroundedBy(node.raw, setting.quote); + return node.value.indexOf(setting.quote) !== -1 || astUtils.isSurroundedBy(node.raw, setting.quote); } return { diff --git a/lib/rules/lines-around-comment.js b/lib/rules/lines-around-comment.js index 6b1cd5f848b..74df09b01bd 100644 --- a/lib/rules/lines-around-comment.js +++ b/lib/rules/lines-around-comment.js @@ -141,7 +141,7 @@ module.exports = { comments = sourceCode.getAllComments(), commentLines = getCommentLineNums(comments), emptyLines = getEmptyLineNums(lines), - commentAndEmptyLines = new Set(commentLines.concat(emptyLines)); + commentAndEmptyLines = commentLines.concat(emptyLines); /** * Returns whether or not comments are on lines starting with or ending with code @@ -393,7 +393,7 @@ module.exports = { const nextTokenOrComment = sourceCode.getTokenAfter(token, { includeComments: true }); // check for newline before - if (!exceptionStartAllowed && before && !commentAndEmptyLines.has(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]; @@ -408,7 +408,7 @@ module.exports = { } // check for newline after - if (!exceptionEndAllowed && after && !commentAndEmptyLines.has(nextLineNum) && + if (!exceptionEndAllowed && after && !commentAndEmptyLines.includes(nextLineNum) && !(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) { context.report({ node: token, diff --git a/lib/rules/max-lines.js b/lib/rules/max-lines.js index 772f02aff08..31fc657a63c 100644 --- a/lib/rules/max-lines.js +++ b/lib/rules/max-lines.js @@ -159,10 +159,10 @@ module.exports = { if (skipComments) { const comments = sourceCode.getAllComments(); - const commentLines = new Set(comments.flatMap(getLinesWithoutCode)); + const commentLines = comments.flatMap(getLinesWithoutCode); lines = lines.filter( - l => !commentLines.has(l.lineNumber) + l => !commentLines.includes(l.lineNumber) ); } diff --git a/lib/rules/newline-before-return.js b/lib/rules/newline-before-return.js index d07c23658ed..f4aa5166f0e 100644 --- a/lib/rules/newline-before-return.js +++ b/lib/rules/newline-before-return.js @@ -47,7 +47,7 @@ module.exports = { function isPrecededByTokens(node, testTokens) { const tokenBefore = sourceCode.getTokenBefore(node); - return testTokens.includes(tokenBefore.value); + return testTokens.some(token => tokenBefore.value === token); } /** diff --git a/lib/rules/no-bitwise.js b/lib/rules/no-bitwise.js index 43a1e764edc..1de1619bffa 100644 --- a/lib/rules/no-bitwise.js +++ b/lib/rules/no-bitwise.js @@ -76,7 +76,7 @@ module.exports = { * @returns {boolean} Whether or not the node has a bitwise operator. */ function hasBitwiseOperator(node) { - return BITWISE_OPERATORS.includes(node.operator); + return BITWISE_OPERATORS.indexOf(node.operator) !== -1; } /** @@ -85,7 +85,7 @@ module.exports = { * @returns {boolean} Whether or not the node has a bitwise operator. */ function allowedOperator(node) { - return allowed.includes(node.operator); + return allowed.indexOf(node.operator) !== -1; } /** diff --git a/lib/rules/no-console.js b/lib/rules/no-console.js index 464d5647cc3..c0802e23dc7 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -72,7 +72,7 @@ module.exports = { function isAllowed(node) { const propertyName = astUtils.getStaticPropertyName(node); - return propertyName && allowed.includes(propertyName); + return propertyName && allowed.indexOf(propertyName) !== -1; } /** diff --git a/lib/rules/no-empty-function.js b/lib/rules/no-empty-function.js index e23b69e537b..6e73d63b98a 100644 --- a/lib/rules/no-empty-function.js +++ b/lib/rules/no-empty-function.js @@ -144,7 +144,7 @@ module.exports = { filter: astUtils.isCommentToken }); - if (!allowed.includes(kind) && + if (allowed.indexOf(kind) === -1 && node.body.type === "BlockStatement" && node.body.body.length === 0 && innerComments.length === 0 diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index ddb1d8330d5..f45ac616ed9 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -51,13 +51,13 @@ module.exports = { const sourceCode = context.getSourceCode(); // Node types which have a test which will coerce values to booleans. - const BOOLEAN_NODE_TYPES = new Set([ + const BOOLEAN_NODE_TYPES = [ "IfStatement", "DoWhileStatement", "WhileStatement", "ConditionalExpression", "ForStatement" - ]); + ]; /** * Check if a node is a Boolean function or constructor. @@ -95,7 +95,7 @@ module.exports = { (isBooleanFunctionOrConstructorCall(node.parent) && node === node.parent.arguments[0]) || - (BOOLEAN_NODE_TYPES.has(node.parent.type) && + (BOOLEAN_NODE_TYPES.indexOf(node.parent.type) !== -1 && node === node.parent.test) || // ! diff --git a/lib/rules/no-extra-semi.js b/lib/rules/no-extra-semi.js index 625310eea69..89d9fce57f0 100644 --- a/lib/rules/no-extra-semi.js +++ b/lib/rules/no-extra-semi.js @@ -98,7 +98,7 @@ module.exports = { "WithStatement" ]; - if (!allowedParentTypes.includes(parent.type)) { + if (allowedParentTypes.indexOf(parent.type) === -1) { report(node); } }, diff --git a/lib/rules/no-global-assign.js b/lib/rules/no-global-assign.js index 1225baec5de..340c6c798c3 100644 --- a/lib/rules/no-global-assign.js +++ b/lib/rules/no-global-assign.js @@ -78,7 +78,7 @@ module.exports = { * @returns {void} */ function checkVariable(variable) { - if (variable.writeable === false && !exceptions.includes(variable.name)) { + if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) { variable.references.forEach(checkReference); } } diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 4b21e3d94f4..f646093f555 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -257,7 +257,7 @@ module.exports = { let operatorAllowed; // !!foo - operatorAllowed = options.allow.includes("!!"); + operatorAllowed = options.allow.indexOf("!!") >= 0; if (!operatorAllowed && options.boolean && isDoubleLogicalNegating(node)) { const recommendation = `Boolean(${sourceCode.getText(node.argument.argument)})`; @@ -265,7 +265,7 @@ module.exports = { } // ~foo.indexOf(bar) - operatorAllowed = options.allow.includes("~"); + operatorAllowed = options.allow.indexOf("~") >= 0; if (!operatorAllowed && options.boolean && isBinaryNegatingOfIndexOf(node)) { // `foo?.indexOf(bar) !== -1` will be true (== found) if the `foo` is nullish. So use `>= 0` in that case. @@ -276,7 +276,7 @@ module.exports = { } // +foo - operatorAllowed = options.allow.includes("+"); + operatorAllowed = options.allow.indexOf("+") >= 0; if (!operatorAllowed && options.number && node.operator === "+" && !isNumeric(node.argument)) { const recommendation = `Number(${sourceCode.getText(node.argument)})`; @@ -289,7 +289,7 @@ module.exports = { let operatorAllowed; // 1 * foo - operatorAllowed = options.allow.includes("*"); + operatorAllowed = options.allow.indexOf("*") >= 0; const nonNumericOperand = !operatorAllowed && options.number && isMultiplyByOne(node) && getNonNumericOperand(node); if (nonNumericOperand) { @@ -299,7 +299,7 @@ module.exports = { } // "" + foo - operatorAllowed = options.allow.includes("+"); + operatorAllowed = options.allow.indexOf("+") >= 0; if (!operatorAllowed && options.string && isConcatWithEmptyString(node)) { const recommendation = `String(${sourceCode.getText(getNonEmptyOperand(node))})`; @@ -310,7 +310,7 @@ module.exports = { AssignmentExpression(node) { // foo += "" - const operatorAllowed = options.allow.includes("+"); + const operatorAllowed = options.allow.indexOf("+") >= 0; if (!operatorAllowed && options.string && isAppendEmptyString(node)) { const code = sourceCode.getText(getNonEmptyOperand(node)); diff --git a/lib/rules/no-magic-numbers.js b/lib/rules/no-magic-numbers.js index 6b4cf77c326..dfcd593ecbe 100644 --- a/lib/rules/no-magic-numbers.js +++ b/lib/rules/no-magic-numbers.js @@ -80,7 +80,7 @@ module.exports = { const config = context.options[0] || {}, detectObjects = !!config.detectObjects, enforceConst = !!config.enforceConst, - ignore = new Set((config.ignore || []).map(normalizeIgnoreValue)), + ignore = (config.ignore || []).map(normalizeIgnoreValue), ignoreArrayIndexes = !!config.ignoreArrayIndexes, ignoreDefaultValues = !!config.ignoreDefaultValues; @@ -92,7 +92,7 @@ module.exports = { * @returns {boolean} true if the value is ignored */ function isIgnoredValue(value) { - return ignore.has(value); + return ignore.indexOf(value) !== -1; } /** @@ -209,7 +209,7 @@ module.exports = { }); } } else if ( - !okTypes.includes(parent.type) || + okTypes.indexOf(parent.type) === -1 || (parent.type === "AssignmentExpression" && parent.left.type === "Identifier") ) { context.report({ diff --git a/lib/rules/no-mixed-operators.js b/lib/rules/no-mixed-operators.js index 0cace7ea910..c75d01147c9 100644 --- a/lib/rules/no-mixed-operators.js +++ b/lib/rules/no-mixed-operators.js @@ -64,7 +64,7 @@ function normalizeOptions(options = {}) { * @returns {boolean} `true` if such group existed. */ function includesBothInAGroup(groups, left, right) { - return groups.some(group => group.includes(left) && group.includes(right)); + return groups.some(group => group.indexOf(left) !== -1 && group.indexOf(right) !== -1); } /** diff --git a/lib/rules/no-mixed-requires.js b/lib/rules/no-mixed-requires.js index 97064243ed3..5e05cf7a72a 100644 --- a/lib/rules/no-mixed-requires.js +++ b/lib/rules/no-mixed-requires.js @@ -160,7 +160,7 @@ module.exports = { return REQ_COMPUTED; } - if (BUILTIN_MODULES.includes(arg.value)) { + if (BUILTIN_MODULES.indexOf(arg.value) !== -1) { // "var fs = require('fs');" return REQ_CORE; diff --git a/lib/rules/no-multi-spaces.js b/lib/rules/no-multi-spaces.js index 6fac7e3ca7e..e37aae0a16e 100644 --- a/lib/rules/no-multi-spaces.js +++ b/lib/rules/no-multi-spaces.js @@ -56,7 +56,7 @@ module.exports = { const options = context.options[0] || {}; const ignoreEOLComments = options.ignoreEOLComments; const exceptions = Object.assign({ Property: true }, options.exceptions); - const hasExceptions = Object.keys(exceptions).some(key => exceptions[key]); + const hasExceptions = Object.keys(exceptions).filter(key => exceptions[key]).length > 0; /** * Formats value of given comment token for error message by truncating its length. diff --git a/lib/rules/no-native-reassign.js b/lib/rules/no-native-reassign.js index 5f396e404c6..1814a5b3c5b 100644 --- a/lib/rules/no-native-reassign.js +++ b/lib/rules/no-native-reassign.js @@ -81,7 +81,7 @@ module.exports = { * @returns {void} */ function checkVariable(variable) { - if (variable.writeable === false && !exceptions.includes(variable.name)) { + if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) { variable.references.forEach(checkReference); } } diff --git a/lib/rules/no-new-wrappers.js b/lib/rules/no-new-wrappers.js index 1fe06c1943e..4667d581f65 100644 --- a/lib/rules/no-new-wrappers.js +++ b/lib/rules/no-new-wrappers.js @@ -34,7 +34,7 @@ module.exports = { NewExpression(node) { const wrapperObjects = ["String", "Number", "Boolean"]; - if (wrapperObjects.includes(node.callee.name)) { + if (wrapperObjects.indexOf(node.callee.name) > -1) { context.report({ node, messageId: "noConstructor", diff --git a/lib/rules/no-prototype-builtins.js b/lib/rules/no-prototype-builtins.js index dc12669c87d..ae736981e71 100644 --- a/lib/rules/no-prototype-builtins.js +++ b/lib/rules/no-prototype-builtins.js @@ -33,11 +33,11 @@ module.exports = { }, create(context) { - const DISALLOWED_PROPS = new Set([ + const DISALLOWED_PROPS = [ "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable" - ]); + ]; /** * Reports if a disallowed property is used in a CallExpression @@ -54,7 +54,7 @@ module.exports = { const propName = astUtils.getStaticPropertyName(callee); - if (propName !== null && DISALLOWED_PROPS.has(propName)) { + if (propName !== null && DISALLOWED_PROPS.indexOf(propName) > -1) { context.report({ messageId: "prototypeBuildIn", loc: callee.property.loc, diff --git a/lib/rules/no-shadow.js b/lib/rules/no-shadow.js index b4ef334efdd..43d7d738e29 100644 --- a/lib/rules/no-shadow.js +++ b/lib/rules/no-shadow.js @@ -15,8 +15,8 @@ const astUtils = require("./utils/ast-utils"); // Helpers //------------------------------------------------------------------------------ -const FUNC_EXPR_NODE_TYPES = new Set(["ArrowFunctionExpression", "FunctionExpression"]); -const CALL_EXPR_NODE_TYPE = new Set(["CallExpression"]); +const FUNC_EXPR_NODE_TYPES = ["ArrowFunctionExpression", "FunctionExpression"]; +const CALL_EXPR_NODE_TYPE = ["CallExpression"]; const FOR_IN_OF_TYPE = /^For(?:In|Of)Statement$/u; const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/u; @@ -123,7 +123,7 @@ module.exports = { const { variableScope } = variable.scope; - if (!(FUNC_EXPR_NODE_TYPES.has(variableScope.block.type) && getOuterScope(variableScope) === shadowedVariable.scope)) { + if (!(FUNC_EXPR_NODE_TYPES.includes(variableScope.block.type) && getOuterScope(variableScope) === shadowedVariable.scope)) { return false; } @@ -132,7 +132,7 @@ module.exports = { const callExpression = findSelfOrAncestor( parent, - node => CALL_EXPR_NODE_TYPE.has(node.type) + node => CALL_EXPR_NODE_TYPE.includes(node.type) ); if (!callExpression) { @@ -173,7 +173,7 @@ module.exports = { * @returns {boolean} Whether or not the variable name is allowed. */ function isAllowed(variable) { - return options.allow.includes(variable.name); + return options.allow.indexOf(variable.name) !== -1; } /** diff --git a/lib/rules/no-sparse-arrays.js b/lib/rules/no-sparse-arrays.js index ff5c2cf9978..c95bc203c4a 100644 --- a/lib/rules/no-sparse-arrays.js +++ b/lib/rules/no-sparse-arrays.js @@ -37,7 +37,7 @@ module.exports = { ArrayExpression(node) { - const emptySpot = node.elements.includes(null); + const emptySpot = node.elements.indexOf(null) > -1; if (emptySpot) { context.report({ node, messageId: "unexpectedSparseArray" }); diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index a3a9f650032..55fb9b8cfbc 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -86,7 +86,7 @@ module.exports = { * @private */ function isAllowed(identifier) { - return ALLOWED_VARIABLES.includes(identifier); + return ALLOWED_VARIABLES.some(ident => ident === identifier); } /** diff --git a/lib/rules/no-unused-expressions.js b/lib/rules/no-unused-expressions.js index e90099d6201..68a7ebd5e00 100644 --- a/lib/rules/no-unused-expressions.js +++ b/lib/rules/no-unused-expressions.js @@ -124,7 +124,7 @@ module.exports = { */ return (parent.type === "Program" || parent.type === "BlockStatement" && (/Function/u.test(grandparent.type))) && - directives(parent).includes(node); + directives(parent).indexOf(node) >= 0; } /** diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js index 11b1f3722de..54e33705f7f 100644 --- a/lib/rules/no-unused-vars.js +++ b/lib/rules/no-unused-vars.js @@ -259,7 +259,7 @@ module.exports = { let scope = ref.from; while (scope) { - if (nodes.includes(scope.block)) { + if (nodes.indexOf(scope.block) >= 0) { return true; } diff --git a/lib/rules/operator-assignment.js b/lib/rules/operator-assignment.js index 8b9fb5bd73b..50cdff9f9a0 100644 --- a/lib/rules/operator-assignment.js +++ b/lib/rules/operator-assignment.js @@ -22,7 +22,7 @@ const astUtils = require("./utils/ast-utils"); * shorthand form. */ function isCommutativeOperatorWithShorthand(operator) { - return ["*", "&", "^", "|"].includes(operator); + return ["*", "&", "^", "|"].indexOf(operator) >= 0; } /** @@ -33,7 +33,7 @@ function isCommutativeOperatorWithShorthand(operator) { * a shorthand form. */ function isNonCommutativeOperatorWithShorthand(operator) { - return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].includes(operator); + return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].indexOf(operator) >= 0; } //------------------------------------------------------------------------------ diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js index cf07d6ce714..190860019d8 100644 --- a/lib/rules/prefer-const.js +++ b/lib/rules/prefer-const.js @@ -60,7 +60,7 @@ function canBecomeVariableDeclaration(identifier) { */ function isOuterVariableInDestructing(name, initScope) { - if (initScope.through.some(ref => ref.resolved && ref.resolved.name === name)) { + if (initScope.through.find(ref => ref.resolved && ref.resolved.name === name)) { return true; } diff --git a/lib/rules/prefer-reflect.js b/lib/rules/prefer-reflect.js index 377268900b4..1367a1848df 100644 --- a/lib/rules/prefer-reflect.js +++ b/lib/rules/prefer-reflect.js @@ -106,7 +106,7 @@ module.exports = { const methodName = (node.callee.property || {}).name; const isReflectCall = (node.callee.object || {}).name === "Reflect"; const hasReflectSubstitute = Object.prototype.hasOwnProperty.call(reflectSubstitutes, methodName); - const userConfiguredException = exceptions.includes(methodName); + const userConfiguredException = exceptions.indexOf(methodName) !== -1; if (hasReflectSubstitute && !isReflectCall && !userConfiguredException) { report(node, existingNames[methodName], reflectSubstitutes[methodName]); @@ -115,7 +115,7 @@ module.exports = { UnaryExpression(node) { const isDeleteOperator = node.operator === "delete"; const targetsIdentifier = node.argument.type === "Identifier"; - const userConfiguredException = exceptions.includes("delete"); + const userConfiguredException = exceptions.indexOf("delete") !== -1; if (isDeleteOperator && !targetsIdentifier && !userConfiguredException) { report(node, "the delete keyword", "Reflect.deleteProperty"); diff --git a/lib/rules/prefer-regex-literals.js b/lib/rules/prefer-regex-literals.js index aa7258997c5..158f84b940d 100644 --- a/lib/rules/prefer-regex-literals.js +++ b/lib/rules/prefer-regex-literals.js @@ -47,7 +47,7 @@ function isStaticTemplateLiteral(node) { return node.type === "TemplateLiteral" && node.expressions.length === 0; } -const validPrecedingTokens = new Set([ +const validPrecedingTokens = [ "(", ";", "[", @@ -110,7 +110,7 @@ const validPrecedingTokens = new Set([ "debugger", "case", "throw" -]); +]; //------------------------------------------------------------------------------ @@ -334,7 +334,7 @@ module.exports = { const tokenBefore = sourceCode.getTokenBefore(node); - if (tokenBefore && !validPrecedingTokens.has(tokenBefore.value)) { + if (tokenBefore && !validPrecedingTokens.includes(tokenBefore.value)) { noFix = true; } diff --git a/lib/rules/quote-props.js b/lib/rules/quote-props.js index 0b66d761c47..e57ad6eea29 100644 --- a/lib/rules/quote-props.js +++ b/lib/rules/quote-props.js @@ -95,7 +95,7 @@ module.exports = { * @returns {boolean} `true` if it is an ES3 token. */ function isKeyword(tokenStr) { - return keywords.includes(tokenStr); + return keywords.indexOf(tokenStr) >= 0; } /** @@ -108,7 +108,7 @@ module.exports = { */ function areQuotesRedundant(rawKey, tokens, skipNumberLiterals) { return tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === rawKey.length && - (["Identifier", "Keyword", "Null", "Boolean"].includes(tokens[0].type) || + (["Identifier", "Keyword", "Null", "Boolean"].indexOf(tokens[0].type) >= 0 || (tokens[0].type === "Numeric" && !skipNumberLiterals && String(+tokens[0].value) === tokens[0].value)); } diff --git a/lib/rules/quotes.js b/lib/rules/quotes.js index f1d30a044bc..41bff3c4ecf 100644 --- a/lib/rules/quotes.js +++ b/lib/rules/quotes.js @@ -283,7 +283,7 @@ module.exports = { astUtils.isSurroundedBy(rawVal, settings.quote); if (!isValid && avoidEscape) { - isValid = astUtils.isSurroundedBy(rawVal, settings.alternateQuote) && rawVal.includes(settings.quote); + isValid = astUtils.isSurroundedBy(rawVal, settings.alternateQuote) && rawVal.indexOf(settings.quote) >= 0; } if (!isValid) { diff --git a/lib/rules/spaced-comment.js b/lib/rules/spaced-comment.js index d858fc47cf8..674c13cf380 100644 --- a/lib/rules/spaced-comment.js +++ b/lib/rules/spaced-comment.js @@ -39,7 +39,7 @@ function escapeAndRepeat(s) { function parseMarkersOption(markers) { // `*` is a marker for JSDoc comments. - if (!markers.includes("*")) { + if (markers.indexOf("*") === -1) { return markers.concat("*"); } diff --git a/lib/rules/valid-jsdoc.js b/lib/rules/valid-jsdoc.js index 8662bf0eae7..c118e033dd8 100644 --- a/lib/rules/valid-jsdoc.js +++ b/lib/rules/valid-jsdoc.js @@ -405,7 +405,7 @@ module.exports = { loc: getAbsoluteRange(jsdocNode, param), data: { name: param.name } }); - } else if (!param.name.includes(".")) { + } else if (param.name.indexOf(".") === -1) { paramTagsByName[param.name] = param; } }); diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js index 2286d8926cc..cb85cd9cb90 100644 --- a/lib/rules/valid-typeof.js +++ b/lib/rules/valid-typeof.js @@ -42,8 +42,8 @@ module.exports = { create(context) { - const VALID_TYPES = new Set(["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"]), - OPERATORS = new Set(["==", "===", "!=", "!=="]); + const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"], + OPERATORS = ["==", "===", "!=", "!=="]; const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals; @@ -85,13 +85,13 @@ module.exports = { if (isTypeofExpression(node)) { const parent = context.getAncestors().pop(); - if (parent.type === "BinaryExpression" && OPERATORS.has(parent.operator)) { + if (parent.type === "BinaryExpression" && OPERATORS.indexOf(parent.operator) !== -1) { const sibling = parent.left === node ? parent.right : parent.left; if (sibling.type === "Literal" || sibling.type === "TemplateLiteral" && !sibling.expressions.length) { const value = sibling.type === "Literal" ? sibling.value : sibling.quasis[0].value.cooked; - if (!VALID_TYPES.has(value)) { + if (VALID_TYPES.indexOf(value) === -1) { context.report({ node: sibling, messageId: "invalidValue" }); } } else if (sibling.type === "Identifier" && sibling.name === "undefined" && isReferenceToGlobalVariable(sibling)) { diff --git a/lib/rules/yoda.js b/lib/rules/yoda.js index 5b64287a151..f491f756d54 100644 --- a/lib/rules/yoda.js +++ b/lib/rules/yoda.js @@ -39,7 +39,7 @@ function isEqualityOperator(operator) { * @returns {boolean} Whether the operator is used in range tests. */ function isRangeTestOperator(operator) { - return ["<", "<="].includes(operator); + return ["<", "<="].indexOf(operator) >= 0; } /** diff --git a/package.json b/package.json index 380ebf6597d..dbbc034edf6 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,6 @@ "eslint-plugin-internal-rules": "file:tools/internal-rules", "eslint-plugin-jsdoc": "^37.0.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-unicorn": "^42.0.0", "eslint-release": "^3.2.0", "eslump": "^3.0.0", "esprima": "^4.0.1", diff --git a/packages/eslint-config-eslint/default.yml b/packages/eslint-config-eslint/default.yml index 3985ae2988c..1fcbebe75f6 100644 --- a/packages/eslint-config-eslint/default.yml +++ b/packages/eslint-config-eslint/default.yml @@ -4,8 +4,6 @@ extends: - "plugin:node/recommended" - "plugin:jsdoc/recommended" - "plugin:eslint-comments/recommended" -plugins: - - unicorn settings: jsdoc: tagNamePreference: @@ -281,19 +279,6 @@ rules: template-curly-spacing: ["error", "never"] template-tag-spacing: "error" unicode-bom: "error" - - # Selectively-enable unicorn rules since many of its recommended rules are too aggressive/stylistic for us. - unicorn/prefer-array-find: "error" - unicorn/prefer-array-flat-map: "error" - unicorn/prefer-array-flat: "error" - unicorn/prefer-array-index-of: "error" - unicorn/prefer-array-some: "error" - unicorn/prefer-includes: "error" - unicorn/prefer-set-has: "error" - unicorn/prefer-string-slice: "error" - unicorn/prefer-string-starts-ends-with: "error" - unicorn/prefer-string-trim-start-end: "error" - wrap-iife: "error" yield-star-spacing: "error" yoda: ["error", "never", { exceptRange: true }] diff --git a/packages/eslint-config-eslint/package.json b/packages/eslint-config-eslint/package.json index e64f65a7a9b..faa9f4a7188 100644 --- a/packages/eslint-config-eslint/package.json +++ b/packages/eslint-config-eslint/package.json @@ -22,8 +22,7 @@ "peerDependencies": { "eslint-plugin-eslint-comments": ">=3.2.0", "eslint-plugin-jsdoc": ">=36.0.6", - "eslint-plugin-node": ">=11.1.0", - "eslint-plugin-unicorn": ">=42.0.0" + "eslint-plugin-node": ">=11.1.0" }, "keywords": [ "eslintconfig", diff --git a/tests/lib/cli.js b/tests/lib/cli.js index d1725c05b72..59ff0eaf7a4 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -552,9 +552,9 @@ describe("cli", () => { const call = log.info.getCall(0); assert.isTrue(log.info.calledOnce); - assert.isTrue(call.args[0].includes("String!")); - assert.isTrue(call.args[0].includes("Literal!")); - assert.isTrue(call.args[0].includes("2 problems")); + assert.isTrue(call.args[0].indexOf("String!") > -1); + assert.isTrue(call.args[0].indexOf("Literal!") > -1); + assert.isTrue(call.args[0].indexOf("2 problems") > -1); assert.isTrue(log.info.neverCalledWith("")); assert.strictEqual(exit, 1); }); diff --git a/tests/lib/linter/node-event-generator.js b/tests/lib/linter/node-event-generator.js index 4004f7a2835..44f8e512d67 100644 --- a/tests/lib/linter/node-event-generator.js +++ b/tests/lib/linter/node-event-generator.js @@ -126,7 +126,7 @@ describe("NodeEventGenerator", () => { it(possibleQueries.join("; "), () => { const ast = espree.parse(sourceText, ESPREE_CONFIG); const emissions = getEmissions(ast, possibleQueries) - .filter(emission => possibleQueries.includes(emission[0])); + .filter(emission => possibleQueries.indexOf(emission[0]) !== -1); assert.deepStrictEqual(emissions, expectedEmissions(ast)); }); @@ -388,7 +388,7 @@ describe("NodeEventGenerator", () => { function assertEmissions(ast, visitorKeys, possibleQueries, expectedEmissions) { it(possibleQueries.join("; "), () => { const emissions = getEmissions(ast, visitorKeys, possibleQueries) - .filter(emission => possibleQueries.includes(emission[0])); + .filter(emission => possibleQueries.indexOf(emission[0]) !== -1); assert.deepStrictEqual(emissions, expectedEmissions(ast)); }); diff --git a/tests/lib/rules/no-invalid-this.js b/tests/lib/rules/no-invalid-this.js index dd72be49991..b106a706c0f 100644 --- a/tests/lib/rules/no-invalid-this.js +++ b/tests/lib/rules/no-invalid-this.js @@ -86,7 +86,8 @@ function extractPatterns(patterns, type) { return thisPattern; })); - return patternsList.flat(); + // Flatten. + return [].concat(...patternsList); } //------------------------------------------------------------------------------ diff --git a/tools/code-sample-minimizer.js b/tools/code-sample-minimizer.js index e1eb4995cc0..c68f4582050 100644 --- a/tools/code-sample-minimizer.js +++ b/tools/code-sample-minimizer.js @@ -133,8 +133,10 @@ function reduceBadExampleSize({ * @returns {ASTNode} A descendent of `node` which is also bad */ function extractRelevantChild(node) { - const childNodes = visitorKeys[node.type] - .flatMap(key => (Array.isArray(node[key]) ? node[key] : [node[key]])); + const childNodes = [].concat( + ...visitorKeys[node.type] + .map(key => (Array.isArray(node[key]) ? node[key] : [node[key]])) + ); for (const childNode of childNodes) { if (!childNode) {