eslint-plugin-remeda 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +267 -245
  2. package/dist/index.js +278 -256
  3. package/package.json +8 -4
package/dist/index.cjs CHANGED
@@ -47,12 +47,14 @@ var package_default = {
47
47
  scripts: {
48
48
  build: "tsup",
49
49
  typecheck: "tsc",
50
+ lint: "eslint",
50
51
  knip: "knip",
51
52
  publint: "publint",
52
53
  "test:watch": "vitest --ui",
53
54
  test: "vitest run",
54
55
  attw: "attw --pack .",
55
56
  qa: "pnpm typecheck && pnpm test && pnpm knip && pnpm publint && attw",
57
+ nuke: "rm -rf node_modules pnpm-lock.yaml",
56
58
  "semantic-release": "pnpm build && semantic-release"
57
59
  },
58
60
  files: [
@@ -82,8 +84,10 @@ var package_default = {
82
84
  "@types/node": "^20.14.9",
83
85
  "@vitest/coverage-v8": "^2.0.3",
84
86
  "@vitest/ui": "^2.0.3",
85
- eslint: "^9.7.0",
86
- "eslint-plugin-eslint-plugin": "^4.2.0",
87
+ eslint: "9.10.0",
88
+ "eslint-config-sheriff": "^21.2.0",
89
+ "eslint-define-config": "^2.1.0",
90
+ "eslint-plugin-eslint-plugin": "^6.2.0",
87
91
  "eslint-vitest-rule-tester": "^0.3.3",
88
92
  knip: "^5.29.1",
89
93
  prettier: "^3.3.2",
@@ -96,7 +100,7 @@ var package_default = {
96
100
  engines: {
97
101
  node: ">=20"
98
102
  },
99
- packageManager: "pnpm@9.7.1",
103
+ packageManager: "pnpm@9.9.0",
100
104
  publishConfig: {
101
105
  access: "public"
102
106
  },
@@ -115,17 +119,219 @@ var package_default = {
115
119
  }
116
120
  };
117
121
 
122
+ // src/rules/collection-method-value.ts
123
+ var import_includes = __toESM(require("lodash/includes"), 1);
124
+
125
+ // src/util/astUtil.ts
126
+ var import_lodash = require("lodash");
127
+ var getCaller = (0, import_lodash.property)(["callee", "object"]);
128
+ var getMethodName = (0, import_lodash.property)(["callee", "property", "name"]);
129
+ var isMethodCall = (0, import_lodash.matches)({
130
+ type: "CallExpression",
131
+ callee: { type: "MemberExpression" }
132
+ });
133
+ var isFunctionExpression = (0, import_lodash.overSome)(
134
+ (0, import_lodash.matchesProperty)("type", "FunctionExpression"),
135
+ (0, import_lodash.matchesProperty)("type", "FunctionDeclaration")
136
+ );
137
+ var isFunctionDefinitionWithBlock = (0, import_lodash.overSome)(
138
+ isFunctionExpression,
139
+ (0, import_lodash.matches)({
140
+ type: "ArrowFunctionExpression",
141
+ body: { type: "BlockStatement" }
142
+ })
143
+ );
144
+ var getFirstFunctionLine = (0, import_lodash.cond)([
145
+ [isFunctionDefinitionWithBlock, (0, import_lodash.property)(["body", "body", 0])],
146
+ [(0, import_lodash.matches)({ type: "ArrowFunctionExpression" }), (0, import_lodash.property)("body")]
147
+ ]);
148
+ var isPropAccess = (0, import_lodash.overSome)(
149
+ (0, import_lodash.matches)({ computed: false }),
150
+ (0, import_lodash.matchesProperty)(["property", "type"], "Literal")
151
+ );
152
+ function isMemberExpOf(node, objectName, { maxLength = Number.MAX_VALUE, allowComputed } = {}) {
153
+ if (objectName) {
154
+ let curr = node;
155
+ let depth = maxLength;
156
+ while (curr && depth) {
157
+ if (allowComputed || isPropAccess(curr)) {
158
+ if (curr.type === "MemberExpression" && curr.object.name === objectName) {
159
+ return true;
160
+ }
161
+ curr = curr.object;
162
+ depth--;
163
+ } else {
164
+ return false;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ var getFirstParamName = (0, import_lodash.property)(["params", 0, "name"]);
170
+ var isReturnStatement = (0, import_lodash.matchesProperty)("type", "ReturnStatement");
171
+ function hasOnlyOneStatement(func) {
172
+ if (isFunctionDefinitionWithBlock(func)) {
173
+ return (0, import_lodash.get)(func, "body.body.length") === 1;
174
+ }
175
+ if (func.type === "ArrowFunctionExpression") {
176
+ return !(0, import_lodash.get)(func, "body.body");
177
+ }
178
+ }
179
+ function isObjectOfMethodCall(node) {
180
+ return (0, import_lodash.get)(node, "parent.object") === node && (0, import_lodash.get)(node, "parent.parent.type") === "CallExpression";
181
+ }
182
+ function isLiteral(node) {
183
+ return node.type === "Literal";
184
+ }
185
+ function isBinaryExpWithMemberOf(operator, exp, objectName, {
186
+ maxLength,
187
+ allowComputed,
188
+ onlyLiterals
189
+ } = {}) {
190
+ if (!(0, import_lodash.isMatch)(exp, { type: "BinaryExpression", operator })) {
191
+ return false;
192
+ }
193
+ const [left, right] = [exp.left, exp.right].map(
194
+ (side) => isMemberExpOf(side, objectName, { maxLength, allowComputed })
195
+ );
196
+ return left === !right && (!onlyLiterals || isLiteral(exp.left) || isLiteral(exp.right));
197
+ }
198
+ var isNegationExpression = (0, import_lodash.matches)({
199
+ type: "UnaryExpression",
200
+ operator: "!"
201
+ });
202
+ function isNegationOfMemberOf(exp, objectName, { maxLength } = {}) {
203
+ return isNegationExpression(exp) && isMemberExpOf(exp.argument, objectName, { maxLength, allowComputed: false });
204
+ }
205
+ function isIdentifierWithName(exp, paramName) {
206
+ return exp && paramName && exp.type === "Identifier" && exp.name === paramName;
207
+ }
208
+ function getValueReturnedInFirstStatement(func) {
209
+ const firstLine = getFirstFunctionLine(func);
210
+ if (func) {
211
+ if (isFunctionDefinitionWithBlock(func)) {
212
+ return isReturnStatement(firstLine) ? firstLine.argument : void 0;
213
+ }
214
+ if (func.type === "ArrowFunctionExpression") {
215
+ return firstLine;
216
+ }
217
+ }
218
+ }
219
+ function isCallFromObject(node, objName) {
220
+ return node && objName && node.type === "CallExpression" && (0, import_lodash.get)(node, "callee.object.name") === objName;
221
+ }
222
+ function isComputed(node) {
223
+ return (0, import_lodash.get)(node, "computed") && node.property.type !== "Literal";
224
+ }
225
+ function isEquivalentMemberExp(a, b) {
226
+ return (0, import_lodash.isEqualWith)(a, b, (left, right, key) => {
227
+ if ((0, import_lodash.includes)(["loc", "range", "computed", "start", "end", "parent"], key)) {
228
+ return true;
229
+ }
230
+ if (isComputed(left) || isComputed(right)) {
231
+ return false;
232
+ }
233
+ if (key === "property") {
234
+ const leftValue = left.name || left.value;
235
+ const rightValue = right.name || right.value;
236
+ return leftValue === rightValue;
237
+ }
238
+ });
239
+ }
240
+ var isEqEqEq = (0, import_lodash.matches)({ type: "BinaryExpression", operator: "===" });
241
+ var isMinus = (node) => node.type === "UnaryExpression" && node.operator === "-";
242
+ var comparisonType = {
243
+ exact: 0,
244
+ over: 1,
245
+ under: 2,
246
+ any: 3
247
+ };
248
+ var comparisonOperators = ["==", "!=", "===", "!=="];
249
+ function getIsValue(value2) {
250
+ return value2 < 0 ? (0, import_lodash.overEvery)(isMinus, (0, import_lodash.matches)({ argument: { value: -value2 } })) : (0, import_lodash.matches)({ value: value2 });
251
+ }
252
+ function getExpressionComparedToInt(node, value2, checkOver) {
253
+ const isValue = getIsValue(value2);
254
+ if ((0, import_lodash.includes)(comparisonOperators, node.operator)) {
255
+ if (isValue(node.right)) {
256
+ return node.left;
257
+ }
258
+ if (isValue(node.left)) {
259
+ return node.right;
260
+ }
261
+ }
262
+ if (checkOver) {
263
+ if (node.operator === ">" && isValue(node.right)) {
264
+ return node.left;
265
+ }
266
+ if (node.operator === "<" && isValue(node.left)) {
267
+ return node.right;
268
+ }
269
+ const isNext = getIsValue(value2 + 1);
270
+ if ((node.operator === ">=" || node.operator === "<") && isNext(node.right)) {
271
+ return node.left;
272
+ }
273
+ if ((node.operator === "<=" || node.operator === ">") && isNext(node.left)) {
274
+ return node.right;
275
+ }
276
+ }
277
+ }
278
+ var isIndexOfCall = (node) => isMethodCall(node) && getMethodName(node) === "indexOf";
279
+ var isFindIndexCall = (node) => isMethodCall(node) && getMethodName(node) === "findIndex";
280
+ function collectParameterValues(node) {
281
+ switch (node && node.type) {
282
+ case "Identifier": {
283
+ return [node.name];
284
+ }
285
+ case "ObjectPattern": {
286
+ return (0, import_lodash.flatMap)(
287
+ node.properties,
288
+ (prop) => collectParameterValues(prop.value)
289
+ );
290
+ }
291
+ case "ArrayPattern": {
292
+ return (0, import_lodash.flatMap)(node.elements, collectParameterValues);
293
+ }
294
+ default: {
295
+ return [];
296
+ }
297
+ }
298
+ }
299
+ var astUtil_default = {
300
+ getCaller,
301
+ getMethodName,
302
+ isMethodCall,
303
+ getFirstFunctionLine,
304
+ isMemberExpOf,
305
+ getFirstParamName,
306
+ hasOnlyOneStatement,
307
+ isObjectOfMethodCall,
308
+ isEqEqEqToMemberOf: isBinaryExpWithMemberOf.bind(null, "==="),
309
+ isNotEqEqToMemberOf: isBinaryExpWithMemberOf.bind(null, "!=="),
310
+ isNegationOfMemberOf,
311
+ isIdentifierWithName,
312
+ isNegationExpression,
313
+ getValueReturnedInFirstStatement,
314
+ isCallFromObject,
315
+ isComputed,
316
+ isEquivalentMemberExp,
317
+ isEqEqEq,
318
+ comparisonType,
319
+ getExpressionComparedToInt,
320
+ isIndexOfCall,
321
+ isFindIndexCall,
322
+ isFunctionExpression,
323
+ isFunctionDefinitionWithBlock,
324
+ collectParameterValues
325
+ };
326
+
118
327
  // src/util/getDocsUrl.ts
119
328
  var REPO_URL = "https://github.com/AndreaPontrandolfo/eslint-plugin-remeda";
120
329
  function getDocsUrl(ruleName) {
121
330
  return `${REPO_URL}/blob/v${version}/docs/rules/${ruleName}.md`;
122
331
  }
123
332
 
124
- // src/util/remedaUtil.ts
125
- var import_lodash4 = require("lodash");
126
-
127
333
  // src/util/methodDataUtil.ts
128
- var import_lodash = require("lodash");
334
+ var import_lodash2 = require("lodash");
129
335
 
130
336
  // src/util/methodData.ts
131
337
  var methodData_exports = {};
@@ -156,7 +362,7 @@ __export(methodData_exports, {
156
362
  cloneWith: () => cloneWith,
157
363
  commit: () => commit,
158
364
  concat: () => concat,
159
- cond: () => cond,
365
+ cond: () => cond2,
160
366
  conforms: () => conforms,
161
367
  conformsTo: () => conformsTo,
162
368
  constant: () => constant,
@@ -193,7 +399,7 @@ __export(methodData_exports, {
193
399
  findLastIndex: () => findLastIndex,
194
400
  findLastKey: () => findLastKey,
195
401
  first: () => first,
196
- flatMap: () => flatMap,
402
+ flatMap: () => flatMap2,
197
403
  flatMapDeep: () => flatMapDeep,
198
404
  flatMapDepth: () => flatMapDepth,
199
405
  flatten: () => flatten,
@@ -212,7 +418,7 @@ __export(methodData_exports, {
212
418
  fromPairs: () => fromPairs,
213
419
  functions: () => functions,
214
420
  functionsIn: () => functionsIn,
215
- get: () => get,
421
+ get: () => get2,
216
422
  groupBy: () => groupBy,
217
423
  gt: () => gt,
218
424
  gte: () => gte,
@@ -221,7 +427,7 @@ __export(methodData_exports, {
221
427
  head: () => head,
222
428
  identity: () => identity,
223
429
  inRange: () => inRange,
224
- includes: () => includes,
430
+ includes: () => includes2,
225
431
  indexBy: () => indexBy,
226
432
  indexOf: () => indexOf,
227
433
  initial: () => initial,
@@ -243,14 +449,14 @@ __export(methodData_exports, {
243
449
  isElement: () => isElement,
244
450
  isEmpty: () => isEmpty,
245
451
  isEqual: () => isEqual,
246
- isEqualWith: () => isEqualWith,
452
+ isEqualWith: () => isEqualWith2,
247
453
  isError: () => isError,
248
454
  isFinite: () => isFinite,
249
455
  isFunction: () => isFunction,
250
456
  isInteger: () => isInteger,
251
457
  isLength: () => isLength,
252
458
  isMap: () => isMap,
253
- isMatch: () => isMatch,
459
+ isMatch: () => isMatch2,
254
460
  isMatchWith: () => isMatchWith,
255
461
  isNaN: () => isNaN,
256
462
  isNative: () => isNative,
@@ -284,8 +490,8 @@ __export(methodData_exports, {
284
490
  map: () => map,
285
491
  mapKeys: () => mapKeys,
286
492
  mapValues: () => mapValues,
287
- matches: () => matches,
288
- matchesProperty: () => matchesProperty,
493
+ matches: () => matches2,
494
+ matchesProperty: () => matchesProperty2,
289
495
  max: () => max,
290
496
  maxBy: () => maxBy,
291
497
  mean: () => mean,
@@ -312,8 +518,8 @@ __export(methodData_exports, {
312
518
  orderBy: () => orderBy,
313
519
  over: () => over,
314
520
  overArgs: () => overArgs,
315
- overEvery: () => overEvery,
316
- overSome: () => overSome,
521
+ overEvery: () => overEvery2,
522
+ overSome: () => overSome2,
317
523
  pad: () => pad,
318
524
  padEnd: () => padEnd,
319
525
  padStart: () => padStart,
@@ -325,7 +531,7 @@ __export(methodData_exports, {
325
531
  pickBy: () => pickBy,
326
532
  plant: () => plant,
327
533
  pop: () => pop,
328
- property: () => property,
534
+ property: () => property2,
329
535
  propertyOf: () => propertyOf,
330
536
  pull: () => pull,
331
537
  pullAll: () => pullAll,
@@ -611,7 +817,7 @@ var concat = {
611
817
  chainable: true,
612
818
  iteratee: false
613
819
  };
614
- var cond = {
820
+ var cond2 = {
615
821
  wrapper: false,
616
822
  shorthand: false,
617
823
  chainable: false,
@@ -856,7 +1062,7 @@ var findLastKey = {
856
1062
  iteratee: true,
857
1063
  args: 2
858
1064
  };
859
- var flatMap = {
1065
+ var flatMap2 = {
860
1066
  wrapper: false,
861
1067
  shorthand: true,
862
1068
  chainable: true,
@@ -987,7 +1193,7 @@ var functionsIn = {
987
1193
  iteratee: false,
988
1194
  args: 1
989
1195
  };
990
- var get = {
1196
+ var get2 = {
991
1197
  wrapper: false,
992
1198
  shorthand: false,
993
1199
  chainable: false,
@@ -1057,7 +1263,7 @@ var inRange = {
1057
1263
  iteratee: false,
1058
1264
  args: 3
1059
1265
  };
1060
- var includes = {
1266
+ var includes2 = {
1061
1267
  wrapper: false,
1062
1268
  shorthand: false,
1063
1269
  chainable: false,
@@ -1205,7 +1411,7 @@ var isEqual = {
1205
1411
  iteratee: false,
1206
1412
  args: 2
1207
1413
  };
1208
- var isEqualWith = {
1414
+ var isEqualWith2 = {
1209
1415
  wrapper: false,
1210
1416
  shorthand: false,
1211
1417
  chainable: false,
@@ -1254,7 +1460,7 @@ var isMap = {
1254
1460
  iteratee: false,
1255
1461
  args: 1
1256
1462
  };
1257
- var isMatch = {
1463
+ var isMatch2 = {
1258
1464
  wrapper: false,
1259
1465
  shorthand: false,
1260
1466
  chainable: false,
@@ -1491,14 +1697,14 @@ var mapValues = {
1491
1697
  iteratee: true,
1492
1698
  args: 2
1493
1699
  };
1494
- var matches = {
1700
+ var matches2 = {
1495
1701
  wrapper: false,
1496
1702
  shorthand: false,
1497
1703
  chainable: true,
1498
1704
  iteratee: false,
1499
1705
  args: 1
1500
1706
  };
1501
- var matchesProperty = {
1707
+ var matchesProperty2 = {
1502
1708
  wrapper: false,
1503
1709
  shorthand: false,
1504
1710
  chainable: true,
@@ -1679,13 +1885,13 @@ var overArgs = {
1679
1885
  chainable: true,
1680
1886
  iteratee: false
1681
1887
  };
1682
- var overEvery = {
1888
+ var overEvery2 = {
1683
1889
  wrapper: false,
1684
1890
  shorthand: true,
1685
1891
  chainable: true,
1686
1892
  iteratee: true
1687
1893
  };
1688
- var overSome = {
1894
+ var overSome2 = {
1689
1895
  wrapper: false,
1690
1896
  shorthand: true,
1691
1897
  chainable: true,
@@ -1762,7 +1968,7 @@ var pop = {
1762
1968
  chainable: false,
1763
1969
  iteratee: false
1764
1970
  };
1765
- var property = {
1971
+ var property2 = {
1766
1972
  wrapper: false,
1767
1973
  shorthand: false,
1768
1974
  chainable: true,
@@ -2549,18 +2755,18 @@ var zipWith = {
2549
2755
 
2550
2756
  // src/util/methodDataUtil.ts
2551
2757
  function isCollectionMethod(method2) {
2552
- return methodSupportsShorthand(method2) || (0, import_lodash.includes)(["reduce", "reduceRight"], method2);
2758
+ return methodSupportsShorthand(method2) || (0, import_lodash2.includes)(["reduce", "reduceRight"], method2);
2553
2759
  }
2554
2760
  function methodSupportsShorthand(method2, shorthandType) {
2555
- const methodShorthandData = (0, import_lodash.get)(methodData_exports, [method2, "shorthand"]);
2556
- return (0, import_lodash.isObject)(methodShorthandData) ? Boolean(shorthandType && methodShorthandData[shorthandType]) : Boolean(methodShorthandData);
2761
+ const methodShorthandData = (0, import_lodash2.get)(methodData_exports, `${method2}.shorthand`);
2762
+ return (0, import_lodash2.isObject)(methodShorthandData) ? Boolean(shorthandType && methodShorthandData[shorthandType]) : Boolean(methodShorthandData);
2557
2763
  }
2558
2764
  function getIterateeIndex(method2) {
2559
2765
  const methodData = methodData_exports[method2];
2560
- if ((0, import_lodash.has)(methodData, "iterateeIndex")) {
2766
+ if ((0, import_lodash2.has)(methodData, "iterateeIndex")) {
2561
2767
  return methodData.iterateeIndex;
2562
2768
  }
2563
- if (methodData?.iteratee) {
2769
+ if (methodData.iteratee) {
2564
2770
  return 1;
2565
2771
  }
2566
2772
  return -1;
@@ -2577,203 +2783,8 @@ function getSideEffectIterationMethods() {
2577
2783
  return sideEffectIterationMethods;
2578
2784
  }
2579
2785
 
2580
- // src/util/astUtil.ts
2581
- var import_lodash2 = require("lodash");
2582
- var getCaller = (0, import_lodash2.property)(["callee", "object"]);
2583
- var getMethodName = (0, import_lodash2.property)(["callee", "property", "name"]);
2584
- var isMethodCall = (0, import_lodash2.matches)({
2585
- type: "CallExpression",
2586
- callee: { type: "MemberExpression" }
2587
- });
2588
- var isFunctionExpression = (0, import_lodash2.overSome)(
2589
- (0, import_lodash2.matchesProperty)("type", "FunctionExpression"),
2590
- (0, import_lodash2.matchesProperty)("type", "FunctionDeclaration")
2591
- );
2592
- var isFunctionDefinitionWithBlock = (0, import_lodash2.overSome)(
2593
- isFunctionExpression,
2594
- (0, import_lodash2.matches)({
2595
- type: "ArrowFunctionExpression",
2596
- body: { type: "BlockStatement" }
2597
- })
2598
- );
2599
- var getFirstFunctionLine = (0, import_lodash2.cond)([
2600
- [isFunctionDefinitionWithBlock, (0, import_lodash2.property)(["body", "body", 0])],
2601
- [(0, import_lodash2.matches)({ type: "ArrowFunctionExpression" }), (0, import_lodash2.property)("body")]
2602
- ]);
2603
- var isPropAccess = (0, import_lodash2.overSome)(
2604
- (0, import_lodash2.matches)({ computed: false }),
2605
- (0, import_lodash2.matchesProperty)(["property", "type"], "Literal")
2606
- );
2607
- function isMemberExpOf(node, objectName, { maxLength = Number.MAX_VALUE, allowComputed } = {}) {
2608
- if (objectName) {
2609
- let curr = node;
2610
- let depth = maxLength;
2611
- while (curr && depth) {
2612
- if (allowComputed || isPropAccess(curr)) {
2613
- if (curr.type === "MemberExpression" && curr.object.name === objectName) {
2614
- return true;
2615
- }
2616
- curr = curr.object;
2617
- depth--;
2618
- } else {
2619
- return false;
2620
- }
2621
- }
2622
- }
2623
- }
2624
- var getFirstParamName = (0, import_lodash2.property)(["params", 0, "name"]);
2625
- var isReturnStatement = (0, import_lodash2.matchesProperty)("type", "ReturnStatement");
2626
- function hasOnlyOneStatement(func) {
2627
- if (isFunctionDefinitionWithBlock(func)) {
2628
- return (0, import_lodash2.get)(func, "body.body.length") === 1;
2629
- }
2630
- if (func.type === "ArrowFunctionExpression") {
2631
- return !(0, import_lodash2.get)(func, "body.body");
2632
- }
2633
- }
2634
- function isObjectOfMethodCall(node) {
2635
- return (0, import_lodash2.get)(node, "parent.object") === node && (0, import_lodash2.get)(node, "parent.parent.type") === "CallExpression";
2636
- }
2637
- function isLiteral(node) {
2638
- return node.type === "Literal";
2639
- }
2640
- function isBinaryExpWithMemberOf(operator, exp, objectName, {
2641
- maxLength,
2642
- allowComputed,
2643
- onlyLiterals
2644
- } = {}) {
2645
- if (!(0, import_lodash2.isMatch)(exp, { type: "BinaryExpression", operator })) {
2646
- return false;
2647
- }
2648
- const [left, right] = [exp.left, exp.right].map(
2649
- (side) => isMemberExpOf(side, objectName, { maxLength, allowComputed })
2650
- );
2651
- return left === !right && (!onlyLiterals || isLiteral(exp.left) || isLiteral(exp.right));
2652
- }
2653
- var isNegationExpression = (0, import_lodash2.matches)({
2654
- type: "UnaryExpression",
2655
- operator: "!"
2656
- });
2657
- function isNegationOfMemberOf(exp, objectName, { maxLength } = {}) {
2658
- return isNegationExpression(exp) && isMemberExpOf(exp.argument, objectName, { maxLength, allowComputed: false });
2659
- }
2660
- function isIdentifierWithName(exp, paramName) {
2661
- return exp && paramName && exp.type === "Identifier" && exp.name === paramName;
2662
- }
2663
- function getValueReturnedInFirstStatement(func) {
2664
- const firstLine = getFirstFunctionLine(func);
2665
- if (func) {
2666
- if (isFunctionDefinitionWithBlock(func)) {
2667
- return isReturnStatement(firstLine) ? firstLine.argument : void 0;
2668
- }
2669
- if (func.type === "ArrowFunctionExpression") {
2670
- return firstLine;
2671
- }
2672
- }
2673
- }
2674
- function isCallFromObject(node, objName) {
2675
- return node && objName && node.type === "CallExpression" && (0, import_lodash2.get)(node, "callee.object.name") === objName;
2676
- }
2677
- function isComputed(node) {
2678
- return (0, import_lodash2.get)(node, "computed") && node.property.type !== "Literal";
2679
- }
2680
- function isEquivalentMemberExp(a, b) {
2681
- return (0, import_lodash2.isEqualWith)(a, b, (left, right, key) => {
2682
- if ((0, import_lodash2.includes)(["loc", "range", "computed", "start", "end", "parent"], key)) {
2683
- return true;
2684
- }
2685
- if (isComputed(left) || isComputed(right)) {
2686
- return false;
2687
- }
2688
- if (key === "property") {
2689
- const leftValue = left.name || left.value;
2690
- const rightValue = right.name || right.value;
2691
- return leftValue === rightValue;
2692
- }
2693
- });
2694
- }
2695
- var isEqEqEq = (0, import_lodash2.matches)({ type: "BinaryExpression", operator: "===" });
2696
- var isMinus = (node) => node.type === "UnaryExpression" && node.operator === "-";
2697
- var comparisonType = {
2698
- exact: 0,
2699
- over: 1,
2700
- under: 2,
2701
- any: 3
2702
- };
2703
- var comparisonOperators = ["==", "!=", "===", "!=="];
2704
- function getIsValue(value2) {
2705
- return value2 < 0 ? (0, import_lodash2.overEvery)(isMinus, (0, import_lodash2.matches)({ argument: { value: -value2 } })) : (0, import_lodash2.matches)({ value: value2 });
2706
- }
2707
- function getExpressionComparedToInt(node, value2, checkOver) {
2708
- const isValue = getIsValue(value2);
2709
- if ((0, import_lodash2.includes)(comparisonOperators, node.operator)) {
2710
- if (isValue(node.right)) {
2711
- return node.left;
2712
- }
2713
- if (isValue(node.left)) {
2714
- return node.right;
2715
- }
2716
- }
2717
- if (checkOver) {
2718
- if (node.operator === ">" && isValue(node.right)) {
2719
- return node.left;
2720
- }
2721
- if (node.operator === "<" && isValue(node.left)) {
2722
- return node.right;
2723
- }
2724
- const isNext = getIsValue(value2 + 1);
2725
- if ((node.operator === ">=" || node.operator === "<") && isNext(node.right)) {
2726
- return node.left;
2727
- }
2728
- if ((node.operator === "<=" || node.operator === ">") && isNext(node.left)) {
2729
- return node.right;
2730
- }
2731
- }
2732
- }
2733
- var isIndexOfCall = (node) => isMethodCall(node) && getMethodName(node) === "indexOf";
2734
- var isFindIndexCall = (node) => isMethodCall(node) && getMethodName(node) === "findIndex";
2735
- function collectParameterValues(node) {
2736
- switch (node && node.type) {
2737
- case "Identifier":
2738
- return [node.name];
2739
- case "ObjectPattern":
2740
- return (0, import_lodash2.flatMap)(
2741
- node.properties,
2742
- (prop) => collectParameterValues(prop.value)
2743
- );
2744
- case "ArrayPattern":
2745
- return (0, import_lodash2.flatMap)(node.elements, collectParameterValues);
2746
- default:
2747
- return [];
2748
- }
2749
- }
2750
- var astUtil_default = {
2751
- getCaller,
2752
- getMethodName,
2753
- isMethodCall,
2754
- getFirstFunctionLine,
2755
- isMemberExpOf,
2756
- getFirstParamName,
2757
- hasOnlyOneStatement,
2758
- isObjectOfMethodCall,
2759
- isEqEqEqToMemberOf: isBinaryExpWithMemberOf.bind(null, "==="),
2760
- isNotEqEqToMemberOf: isBinaryExpWithMemberOf.bind(null, "!=="),
2761
- isNegationOfMemberOf,
2762
- isIdentifierWithName,
2763
- isNegationExpression,
2764
- getValueReturnedInFirstStatement,
2765
- isCallFromObject,
2766
- isComputed,
2767
- isEquivalentMemberExp,
2768
- isEqEqEq,
2769
- comparisonType,
2770
- getExpressionComparedToInt,
2771
- isIndexOfCall,
2772
- isFindIndexCall,
2773
- isFunctionExpression,
2774
- isFunctionDefinitionWithBlock,
2775
- collectParameterValues
2776
- };
2786
+ // src/util/remedaUtil.ts
2787
+ var import_lodash4 = require("lodash");
2777
2788
 
2778
2789
  // src/util/settingsUtil.ts
2779
2790
  var import_lodash3 = require("lodash");
@@ -2805,7 +2816,8 @@ var RemedaContext_default = class {
2805
2816
  _pragma;
2806
2817
  /**
2807
2818
  * Create a Remeda context wrapper from a file's RuleContext
2808
- * @param {RuleContext} context
2819
+ *
2820
+ * @param context
2809
2821
  */
2810
2822
  constructor(context) {
2811
2823
  this.context = context;
@@ -2814,7 +2826,8 @@ var RemedaContext_default = class {
2814
2826
  }
2815
2827
  /**
2816
2828
  * Gets visitors to collect Remeda declarations in the context
2817
- * @returns {Object} visitors for everywhere Remeda can be declared
2829
+ *
2830
+ * @returns visitors for everywhere Remeda can be declared
2818
2831
  */
2819
2832
  getImportVisitors() {
2820
2833
  const self = this;
@@ -2824,15 +2837,17 @@ var RemedaContext_default = class {
2824
2837
  specifiers.forEach((spec) => {
2825
2838
  switch (spec.type) {
2826
2839
  case "ImportNamespaceSpecifier":
2827
- case "ImportDefaultSpecifier":
2840
+ case "ImportDefaultSpecifier": {
2828
2841
  self.general[spec.local.name] = true;
2829
2842
  break;
2830
- case "ImportSpecifier":
2843
+ }
2844
+ case "ImportSpecifier": {
2831
2845
  self.methods[spec.local.name] = spec.imported.name;
2832
2846
  if (spec.imported.name === "chain") {
2833
2847
  self.general[spec.local.name] = true;
2834
2848
  }
2835
2849
  break;
2850
+ }
2836
2851
  }
2837
2852
  });
2838
2853
  } else {
@@ -2866,8 +2881,9 @@ var RemedaContext_default = class {
2866
2881
  }
2867
2882
  /**
2868
2883
  * Returns whether the node is an imported Remeda in this context
2884
+ *
2869
2885
  * @param node
2870
- * @returns {boolean|undefined}
2886
+ * @returns
2871
2887
  */
2872
2888
  isImportedRemeda(node) {
2873
2889
  if (node && node.type === "Identifier") {
@@ -2876,8 +2892,9 @@ var RemedaContext_default = class {
2876
2892
  }
2877
2893
  /**
2878
2894
  * Returns the name of the Remeda method for this node, if any
2895
+ *
2879
2896
  * @param node
2880
- * @returns {string|undefined}
2897
+ * @returns
2881
2898
  */
2882
2899
  getImportedRemedaMethod(node) {
2883
2900
  if (node && node.type === "CallExpression" && !isMethodCall2(node)) {
@@ -2886,15 +2903,16 @@ var RemedaContext_default = class {
2886
2903
  }
2887
2904
  /**
2888
2905
  * Returns whether the node is a call from a Remeda object
2906
+ *
2889
2907
  * @param node
2890
- * @returns {boolean|undefined}
2908
+ * @returns
2891
2909
  */
2892
2910
  isRemedaCall(node) {
2893
2911
  return this.pragma && isCallFromObject2(node, this.pragma) || this.isImportedRemeda(getCaller2(node));
2894
2912
  }
2895
2913
  /**
2896
2914
  *
2897
- * @returns {string|undefined} the current Remeda pragma
2915
+ * @returns the current Remeda pragma
2898
2916
  */
2899
2917
  get pragma() {
2900
2918
  if (!this._pragma) {
@@ -2972,7 +2990,6 @@ function getRemedaContext(context) {
2972
2990
  }
2973
2991
 
2974
2992
  // src/rules/collection-method-value.ts
2975
- var import_includes = __toESM(require("lodash/includes"), 1);
2976
2993
  var { getMethodName: getMethodName2 } = astUtil_default;
2977
2994
  var meta = {
2978
2995
  type: "problem",
@@ -3090,16 +3107,21 @@ function create4(context) {
3090
3107
  const shouldCheckFunctionDeclarations = context.options[1] !== void 0 ? context.options[1] : false;
3091
3108
  function isCompletelyLiteral(node) {
3092
3109
  switch (node.type) {
3093
- case "Literal":
3110
+ case "Literal": {
3094
3111
  return true;
3095
- case "BinaryExpression":
3112
+ }
3113
+ case "BinaryExpression": {
3096
3114
  return isCompletelyLiteral(node.left) && isCompletelyLiteral(node.right);
3097
- case "UnaryExpression":
3115
+ }
3116
+ case "UnaryExpression": {
3098
3117
  return isCompletelyLiteral(node.argument);
3099
- case "ConditionalExpression":
3118
+ }
3119
+ case "ConditionalExpression": {
3100
3120
  return isCompletelyLiteral(node.test) && isCompletelyLiteral(node.consequent) && isCompletelyLiteral(node.alternate);
3101
- default:
3121
+ }
3122
+ default: {
3102
3123
  return false;
3124
+ }
3103
3125
  }
3104
3126
  }
3105
3127
  function reportIfLikeConstant(func, node) {