Skip to content

Commit c7894cd

Browse files
bmishbrettz9
andauthored
chore: enable some rules from eslint-plugin-unicorn internally (#15878)
* chore: add eslint-plugin-unicorn internally * Update tests/lib/rules/no-invalid-this.js Co-authored-by: Brett Zamir <[email protected]> Co-authored-by: Brett Zamir <[email protected]>
1 parent ea65cb5 commit c7894cd

54 files changed

Lines changed: 111 additions & 99 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ target.gensite = function(prereleaseVersion) {
614614
if (test("-f", fullPath)) {
615615
rm("-rf", fullPath);
616616

617-
if (filePath.indexOf(".md") >= 0 && test("-f", htmlFullPath)) {
617+
if (filePath.includes(".md") && test("-f", htmlFullPath)) {
618618
rm("-rf", htmlFullPath);
619619
}
620620
}
@@ -673,7 +673,7 @@ target.gensite = function(prereleaseVersion) {
673673
process.stdout.write(`> Updating files (Steps 4-9): ${i}/${length} - ${filePath + " ".repeat(30)}\r`);
674674

675675
// 5. Prepend page title and layout variables at the top of rules
676-
if (path.dirname(filename).indexOf("rules") >= 0) {
676+
if (path.dirname(filename).includes("rules")) {
677677

678678
// Find out if the rule requires a special docs portion (e.g. if it is recommended and/or fixable)
679679
const rule = rules.get(ruleName);
@@ -696,7 +696,7 @@ target.gensite = function(prereleaseVersion) {
696696
}
697697

698698
// 8. Append first version of ESLint rule was added at.
699-
if (filename.indexOf("rules/") !== -1) {
699+
if (filename.includes("rules/")) {
700700
if (!versions.added[baseName]) {
701701
versions.added[baseName] = getFirstVersionOfFile(sourcePath);
702702
}

lib/cli-engine/cli-engine.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ function *iterateRuleDeprecationWarnings(usedConfigArrays) {
366366

367367
// Flatten used configs.
368368
/** @type {ExtractedConfig[]} */
369-
const configs = [].concat(
370-
...usedConfigArrays.map(getUsedExtractedConfigs)
371-
);
369+
const configs = usedConfigArrays.flatMap(getUsedExtractedConfigs);
372370

373371
// Traverse rule configs.
374372
for (const config of configs) {
@@ -1023,7 +1021,7 @@ class CLIEngine {
10231021
let formatterPath;
10241022

10251023
// if there's a slash, then it's a file (TODO: this check seems dubious for scoped npm packages)
1026-
if (!namespace && normalizedFormatName.indexOf("/") > -1) {
1024+
if (!namespace && normalizedFormatName.includes("/")) {
10271025
formatterPath = path.resolve(cwd, normalizedFormatName);
10281026
} else {
10291027
try {

lib/cli-engine/lint-result-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const invalidCacheStrategyErrorMessage = `Cache strategy must be one of: ${valid
3636
*/
3737
function isValidCacheStrategy(cacheStrategy) {
3838
return (
39-
validCacheStrategies.indexOf(cacheStrategy) !== -1
39+
validCacheStrategies.includes(cacheStrategy)
4040
);
4141
}
4242

lib/linter/code-path-analysis/code-path-segment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CodePathSegment {
100100
* @returns {boolean} `true` if the segment is coming from the end of a loop.
101101
*/
102102
isLoopedPrevSegment(segment) {
103-
return this.internal.loopedPrevSegments.indexOf(segment) !== -1;
103+
return this.internal.loopedPrevSegments.includes(segment);
104104
}
105105

106106
/**

lib/linter/code-path-analysis/code-path-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function addToReturnedOrThrown(dest, others, all, segments) {
3333
const segment = segments[i];
3434

3535
dest.push(segment);
36-
if (others.indexOf(segment) === -1) {
36+
if (!others.includes(segment)) {
3737
all.push(segment);
3838
}
3939
}

lib/linter/code-path-analysis/code-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class CodePath {
212212
}
213213

214214
// Reset the flag of skipping if all branches have been skipped.
215-
if (skippedSegment && segment.prevSegments.indexOf(skippedSegment) !== -1) {
215+
if (skippedSegment && segment.prevSegments.includes(skippedSegment)) {
216216
skippedSegment = null;
217217
}
218218
visited[segment.id] = true;

lib/rules/accessor-pairs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,12 @@ module.exports = {
299299
* @private
300300
*/
301301
function checkPropertyDescriptor(node) {
302-
const namesToCheck = node.properties
302+
const namesToCheck = new Set(node.properties
303303
.filter(p => p.type === "Property" && p.kind === "init" && !p.computed)
304-
.map(({ key }) => key.name);
304+
.map(({ key }) => key.name));
305305

306-
const hasGetter = namesToCheck.includes("get");
307-
const hasSetter = namesToCheck.includes("set");
306+
const hasGetter = namesToCheck.has("get");
307+
const hasSetter = namesToCheck.has("set");
308308

309309
if (checkSetWithoutGet && hasSetter && !hasGetter) {
310310
report(node, "missingGetter");

lib/rules/callback-return.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = {
5353
if (!node.parent) {
5454
return null;
5555
}
56-
if (types.indexOf(node.parent.type) === -1) {
56+
if (!types.includes(node.parent.type)) {
5757
return findClosestParentOfType(node.parent, types);
5858
}
5959
return node.parent;
@@ -87,7 +87,7 @@ module.exports = {
8787
* @returns {boolean} Whether or not this function matches our callback name.
8888
*/
8989
function isCallback(node) {
90-
return containsOnlyIdentifiers(node.callee) && callbacks.indexOf(sourceCode.getText(node.callee)) > -1;
90+
return containsOnlyIdentifiers(node.callee) && callbacks.includes(sourceCode.getText(node.callee));
9191
}
9292

9393
/**

lib/rules/capitalized-comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ module.exports = {
185185

186186
return Boolean(
187187
previousTokenOrComment &&
188-
["Block", "Line"].indexOf(previousTokenOrComment.type) !== -1
188+
["Block", "Line"].includes(previousTokenOrComment.type)
189189
);
190190
}
191191

lib/rules/consistent-this.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = {
6565
function checkAssignment(node, name, value) {
6666
const isThis = value.type === "ThisExpression";
6767

68-
if (aliases.indexOf(name) !== -1) {
68+
if (aliases.includes(name)) {
6969
if (!isThis || node.operator && node.operator !== "=") {
7070
reportBadAssignment(node, name);
7171
}

0 commit comments

Comments
 (0)