Skip to content

Commit 08273e4

Browse files
committed
feature: enable unicorn/prefer-set-has rule
1 parent 8f89eab commit 08273e4

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

eslint-plugin-expensify/no-default-id-values.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ function create(context) {
7474
'CONST.DEFAULT_NUMBER_ID}`',
7575
];
7676

77-
disallowedNumberDefaults.forEach((pattern) => {
77+
for (const pattern of disallowedNumberDefaults) {
7878
searchForPatternsAndReport(context, sourceCode, soureCodeStr, pattern, 'disallowedNumberDefault');
79-
});
79+
}
8080

81-
disallowedStringDefaults.forEach((pattern) => {
81+
for (const pattern of disallowedStringDefaults) {
8282
searchForPatternsAndReport(context, sourceCode, soureCodeStr, pattern, 'disallowedStringDefault');
83-
});
83+
}
8484

8585
return {};
8686
}

eslint-plugin-expensify/no-unstable-hook-defaults.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ function create(context) {
8181

8282
// Check if the variable declaration is an array pattern (destructuring)
8383
if (node.id.type === 'ArrayPattern') {
84-
node.id.elements.forEach((element) => {
84+
for (const element of node.id.elements) {
8585
if (!element || element.type !== 'AssignmentPattern') {
86-
return;
86+
continue; // eslint-disable-line no-continue
8787
}
8888
checkDefaultValue(element.right);
89-
});
89+
}
9090
}
9191

9292
// Check if the variable declaration is an object pattern (destructuring)
9393
if (node.id.type === 'ObjectPattern') {
94-
node.id.properties.forEach((property) => {
94+
for (const property of node.id.properties) {
9595
if (!property || property.type !== 'Property' || property.value.type !== 'AssignmentPattern') {
96-
return;
96+
continue; // eslint-disable-line no-continue
9797
}
9898
checkDefaultValue(property.value.right);
99-
});
99+
}
100100
}
101101
},
102102
};

eslint-plugin-expensify/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ function create(context) {
2727

2828
// Check for 'const {isSmallScreenWidth, ...} = useResponsiveLayout();' pattern
2929
if (node.id.type === AST_NODE_TYPES.ObjectPattern) {
30-
node.id.properties.forEach((property) => {
30+
for (const property of node.id.properties) {
3131
if (!property.key || property.key.name !== 'isSmallScreenWidth') {
32-
return;
32+
continue; // eslint-disable-line no-continue
3333
}
3434
context.report({
3535
node: property,
3636
message:
3737
CONST.MESSAGE
3838
.PREFER_SHOULD_USE_NARROW_LAYOUT_INSTEAD_OF_IS_SMALL_SCREEN_WIDTH,
3939
});
40-
});
40+
}
4141
}
4242

4343
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
@@ -48,7 +48,7 @@ function create(context) {
4848
scope.references,
4949
reference => reference.identifier.name === variableName,
5050
);
51-
variableUsages.forEach((usage) => {
51+
for (const usage of variableUsages) {
5252
const parent = usage.identifier.parent;
5353

5454
// Check for 'const isSmallScreenWidth = var.isSmallScreenWidth;' pattern
@@ -69,19 +69,19 @@ function create(context) {
6969
parent.type === AST_NODE_TYPES.VariableDeclarator
7070
&& parent.id.type === AST_NODE_TYPES.ObjectPattern
7171
) {
72-
parent.id.properties.forEach((property) => {
72+
for (const property of parent.id.properties) {
7373
if (!property.key || property.key.name !== 'isSmallScreenWidth') {
74-
return;
74+
continue; // eslint-disable-line no-continue
7575
}
7676
context.report({
7777
node: property,
7878
message:
7979
CONST.MESSAGE
8080
.PREFER_SHOULD_USE_NARROW_LAYOUT_INSTEAD_OF_IS_SMALL_SCREEN_WIDTH,
8181
});
82-
});
82+
}
8383
}
84-
});
84+
}
8585
},
8686
MemberExpression(node) {
8787
// Check for 'const isSmallScreenWidth = useResponsiveLayout().isSmallScreenWidth;' pattern

eslint-plugin-expensify/prefer-type-fest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function create(context) {
1919
return {
2020
Program(node) {
2121
// Find type-fest import declarations
22-
node.body.forEach((statement) => {
22+
for (const statement of node.body) {
2323
if (statement.type !== 'ImportDeclaration' || statement.source.value !== 'type-fest') {
24-
return;
24+
continue; // eslint-disable-line no-continue
2525
}
2626
typeFestImport = statement;
27-
});
27+
}
2828
},
2929
TSIndexedAccessType(node) {
3030
const objectType = node.objectType;

rules/unicorn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const config = defineConfig([{
1313

1414
rules: {
1515
'unicorn/prefer-set-has': 'error',
16+
'unicorn/no-array-for-each': 'error',
1617

1718
// Enforce that .find or .findLast are used instead of .filter
1819
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-find.md

0 commit comments

Comments
 (0)