eslint-plugin-remeda 1.2.0 → 1.3.1

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 +296 -273
  2. package/dist/index.js +290 -267
  3. package/package.json +8 -4
package/dist/index.cjs CHANGED
@@ -33,7 +33,7 @@ __export(src_exports, {
33
33
  default: () => src_default
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_lodash7 = __toESM(require("lodash"), 1);
36
+ var import_lodash12 = require("lodash");
37
37
 
38
38
  // package.json
39
39
  var version = "0.0.0-development";
@@ -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_lodash6 = require("lodash");
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,19 +2755,21 @@ 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")) {
2561
- return methodData.iterateeIndex;
2562
- }
2563
- if (methodData?.iteratee) {
2564
- return 1;
2766
+ if (methodData) {
2767
+ if ((0, import_lodash2.has)(methodData, "iterateeIndex")) {
2768
+ return methodData.iterateeIndex;
2769
+ }
2770
+ if (methodData.iteratee) {
2771
+ return 1;
2772
+ }
2565
2773
  }
2566
2774
  return -1;
2567
2775
  }
@@ -2577,203 +2785,8 @@ function getSideEffectIterationMethods() {
2577
2785
  return sideEffectIterationMethods;
2578
2786
  }
2579
2787
 
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
- };
2788
+ // src/util/remedaUtil.ts
2789
+ var import_lodash5 = require("lodash");
2777
2790
 
2778
2791
  // src/util/settingsUtil.ts
2779
2792
  var import_lodash3 = require("lodash");
@@ -2784,9 +2797,9 @@ function getSettings(context) {
2784
2797
  }
2785
2798
 
2786
2799
  // src/util/importUtil.ts
2787
- var import_get = __toESM(require("lodash/get"), 1);
2800
+ var import_lodash4 = require("lodash");
2788
2801
  function getNameFromCjsRequire(init) {
2789
- if ((0, import_get.default)(init, "callee.name") === "require" && (0, import_get.default)(init, "arguments.length") === 1 && init.arguments[0].type === "Literal") {
2802
+ if ((0, import_lodash4.get)(init, "callee.name") === "require" && (0, import_lodash4.get)(init, "arguments.length") === 1 && init.arguments[0].type === "Literal") {
2790
2803
  return init.arguments[0].value;
2791
2804
  }
2792
2805
  }
@@ -2805,7 +2818,8 @@ var RemedaContext_default = class {
2805
2818
  _pragma;
2806
2819
  /**
2807
2820
  * Create a Remeda context wrapper from a file's RuleContext
2808
- * @param {RuleContext} context
2821
+ *
2822
+ * @param context
2809
2823
  */
2810
2824
  constructor(context) {
2811
2825
  this.context = context;
@@ -2814,7 +2828,8 @@ var RemedaContext_default = class {
2814
2828
  }
2815
2829
  /**
2816
2830
  * Gets visitors to collect Remeda declarations in the context
2817
- * @returns {Object} visitors for everywhere Remeda can be declared
2831
+ *
2832
+ * @returns visitors for everywhere Remeda can be declared
2818
2833
  */
2819
2834
  getImportVisitors() {
2820
2835
  const self = this;
@@ -2824,15 +2839,17 @@ var RemedaContext_default = class {
2824
2839
  specifiers.forEach((spec) => {
2825
2840
  switch (spec.type) {
2826
2841
  case "ImportNamespaceSpecifier":
2827
- case "ImportDefaultSpecifier":
2842
+ case "ImportDefaultSpecifier": {
2828
2843
  self.general[spec.local.name] = true;
2829
2844
  break;
2830
- case "ImportSpecifier":
2845
+ }
2846
+ case "ImportSpecifier": {
2831
2847
  self.methods[spec.local.name] = spec.imported.name;
2832
2848
  if (spec.imported.name === "chain") {
2833
2849
  self.general[spec.local.name] = true;
2834
2850
  }
2835
2851
  break;
2852
+ }
2836
2853
  }
2837
2854
  });
2838
2855
  } else {
@@ -2866,8 +2883,9 @@ var RemedaContext_default = class {
2866
2883
  }
2867
2884
  /**
2868
2885
  * Returns whether the node is an imported Remeda in this context
2886
+ *
2869
2887
  * @param node
2870
- * @returns {boolean|undefined}
2888
+ * @returns
2871
2889
  */
2872
2890
  isImportedRemeda(node) {
2873
2891
  if (node && node.type === "Identifier") {
@@ -2876,8 +2894,9 @@ var RemedaContext_default = class {
2876
2894
  }
2877
2895
  /**
2878
2896
  * Returns the name of the Remeda method for this node, if any
2897
+ *
2879
2898
  * @param node
2880
- * @returns {string|undefined}
2899
+ * @returns
2881
2900
  */
2882
2901
  getImportedRemedaMethod(node) {
2883
2902
  if (node && node.type === "CallExpression" && !isMethodCall2(node)) {
@@ -2886,15 +2905,16 @@ var RemedaContext_default = class {
2886
2905
  }
2887
2906
  /**
2888
2907
  * Returns whether the node is a call from a Remeda object
2908
+ *
2889
2909
  * @param node
2890
- * @returns {boolean|undefined}
2910
+ * @returns
2891
2911
  */
2892
2912
  isRemedaCall(node) {
2893
2913
  return this.pragma && isCallFromObject2(node, this.pragma) || this.isImportedRemeda(getCaller2(node));
2894
2914
  }
2895
2915
  /**
2896
2916
  *
2897
- * @returns {string|undefined} the current Remeda pragma
2917
+ * @returns the current Remeda pragma
2898
2918
  */
2899
2919
  get pragma() {
2900
2920
  if (!this._pragma) {
@@ -2923,7 +2943,7 @@ function getIsTypeMethod(name) {
2923
2943
  "Error"
2924
2944
  // "Element",
2925
2945
  ];
2926
- return (0, import_lodash4.includes)(types, name) ? `is${(0, import_lodash4.capitalize)(name)}` : null;
2946
+ return (0, import_lodash5.includes)(types, name) ? `is${(0, import_lodash5.capitalize)(name)}` : null;
2927
2947
  }
2928
2948
  function getRemedaMethodCallExpVisitor(remedaContext, reporter) {
2929
2949
  return function(node) {
@@ -2972,7 +2992,6 @@ function getRemedaContext(context) {
2972
2992
  }
2973
2993
 
2974
2994
  // src/rules/collection-method-value.ts
2975
- var import_includes = __toESM(require("lodash/includes"), 1);
2976
2995
  var { getMethodName: getMethodName2 } = astUtil_default;
2977
2996
  var meta = {
2978
2997
  type: "problem",
@@ -2986,7 +3005,7 @@ function create2(context) {
2986
3005
  return node.parent.type !== "ExpressionStatement";
2987
3006
  }
2988
3007
  function isSideEffectIterationMethod(method2) {
2989
- return (0, import_includes.default)(getSideEffectIterationMethods(), method2);
3008
+ return (0, import_lodash6.includes)(getSideEffectIterationMethods(), method2);
2990
3009
  }
2991
3010
  function isParentCommit(node, callType) {
2992
3011
  return callType === "chained" && isCallToMethod(node.parent.parent, "commit");
@@ -3016,7 +3035,7 @@ var RULE_NAME = "collection-method-value";
3016
3035
  var collection_method_value_default = rule;
3017
3036
 
3018
3037
  // src/rules/collection-return.ts
3019
- var import_assign = __toESM(require("lodash/assign"), 1);
3038
+ var import_lodash7 = require("lodash");
3020
3039
  var meta2 = {
3021
3040
  type: "problem",
3022
3041
  schema: [],
@@ -3028,7 +3047,7 @@ function create3(context) {
3028
3047
  const funcInfos = /* @__PURE__ */ new Map();
3029
3048
  let currFuncInfo;
3030
3049
  const remedaContext = getRemedaContext(context);
3031
- return (0, import_assign.default)(
3050
+ return (0, import_lodash7.assign)(
3032
3051
  {
3033
3052
  "CallExpression:exit": getRemedaMethodCallExpVisitor(
3034
3053
  remedaContext,
@@ -3090,16 +3109,21 @@ function create4(context) {
3090
3109
  const shouldCheckFunctionDeclarations = context.options[1] !== void 0 ? context.options[1] : false;
3091
3110
  function isCompletelyLiteral(node) {
3092
3111
  switch (node.type) {
3093
- case "Literal":
3112
+ case "Literal": {
3094
3113
  return true;
3095
- case "BinaryExpression":
3114
+ }
3115
+ case "BinaryExpression": {
3096
3116
  return isCompletelyLiteral(node.left) && isCompletelyLiteral(node.right);
3097
- case "UnaryExpression":
3117
+ }
3118
+ case "UnaryExpression": {
3098
3119
  return isCompletelyLiteral(node.argument);
3099
- case "ConditionalExpression":
3120
+ }
3121
+ case "ConditionalExpression": {
3100
3122
  return isCompletelyLiteral(node.test) && isCompletelyLiteral(node.consequent) && isCompletelyLiteral(node.alternate);
3101
- default:
3123
+ }
3124
+ default: {
3102
3125
  return false;
3126
+ }
3103
3127
  }
3104
3128
  }
3105
3129
  function reportIfLikeConstant(func, node) {
@@ -3396,7 +3420,7 @@ var RULE_NAME8 = "prefer-is-empty";
3396
3420
  var prefer_is_empty_default = rule8;
3397
3421
 
3398
3422
  // src/rules/prefer-is-nil.ts
3399
- var import_lodash5 = __toESM(require("lodash"), 1);
3423
+ var import_lodash8 = __toESM(require("lodash"), 1);
3400
3424
  var { isNegationExpression: isNegationExpression2, isEquivalentMemberExp: isEquivalentMemberExp2 } = astUtil_default;
3401
3425
  var meta9 = {
3402
3426
  type: "problem",
@@ -3409,14 +3433,14 @@ function create10(context) {
3409
3433
  const remedaContext = getRemedaContext(context);
3410
3434
  const nilChecks = {
3411
3435
  null: {
3412
- isValue: (0, import_lodash5.matches)({ type: "Literal", value: null }),
3436
+ isValue: (0, import_lodash8.matches)({ type: "Literal", value: null }),
3413
3437
  expressionChecks: [
3414
3438
  getRemedaTypeCheckedBy("isNull"),
3415
3439
  getValueComparedTo("null")
3416
3440
  ]
3417
3441
  },
3418
3442
  undefined: {
3419
- isValue: (0, import_lodash5.matches)({ type: "Identifier", name: "undefined" }),
3443
+ isValue: (0, import_lodash8.matches)({ type: "Identifier", name: "undefined" }),
3420
3444
  expressionChecks: [
3421
3445
  getRemedaTypeCheckedBy("isUndefined"),
3422
3446
  getValueComparedTo("undefined"),
@@ -3434,13 +3458,13 @@ function create10(context) {
3434
3458
  return node.type === "BinaryExpression" && node.operator === operator && (nilChecks[nil].isValue(node.right) && node.left || nilChecks[nil].isValue(node.left) && node.right);
3435
3459
  };
3436
3460
  }
3437
- const getTypeofArgument = (0, import_lodash5.cond)([
3461
+ const getTypeofArgument = (0, import_lodash8.cond)([
3438
3462
  [
3439
- (0, import_lodash5.matches)({ type: "UnaryExpression", operator: "typeof" }),
3440
- (0, import_lodash5.property)("argument")
3463
+ (0, import_lodash8.matches)({ type: "UnaryExpression", operator: "typeof" }),
3464
+ (0, import_lodash8.property)("argument")
3441
3465
  ]
3442
3466
  ]);
3443
- const isUndefinedString = (0, import_lodash5.matches)({
3467
+ const isUndefinedString = (0, import_lodash8.matches)({
3444
3468
  type: "Literal",
3445
3469
  value: "undefined"
3446
3470
  });
@@ -3448,7 +3472,7 @@ function create10(context) {
3448
3472
  return node.type === "BinaryExpression" && node.operator === operator && (isUndefinedString(node.right) && getTypeofArgument(node.left) || isUndefinedString(node.left) && getTypeofArgument(node.right));
3449
3473
  }
3450
3474
  function checkExpression(nil, operator, node) {
3451
- return (0, import_lodash5.default)(nilChecks[nil].expressionChecks).map((check) => check(node, operator)).find();
3475
+ return (0, import_lodash8.default)(nilChecks[nil].expressionChecks).map((check) => check(node, operator)).find();
3452
3476
  }
3453
3477
  function checkNegatedExpression(nil, node) {
3454
3478
  return isNegationExpression2(node) && checkExpression(nil, "===", node.argument) || checkExpression(nil, "!==", node);
@@ -3493,8 +3517,7 @@ var RULE_NAME9 = "prefer-is-nil";
3493
3517
  var prefer_is_nil_default = rule9;
3494
3518
 
3495
3519
  // src/rules/prefer-map.ts
3496
- var import_get2 = __toESM(require("lodash/get"), 1);
3497
- var import_includes2 = __toESM(require("lodash/includes"), 1);
3520
+ var import_lodash9 = require("lodash");
3498
3521
  var {
3499
3522
  getFirstFunctionLine: getFirstFunctionLine4,
3500
3523
  hasOnlyOneStatement: hasOnlyOneStatement3,
@@ -3512,14 +3535,14 @@ var meta10 = {
3512
3535
  function create11(context) {
3513
3536
  function onlyHasPush(func) {
3514
3537
  const firstLine = getFirstFunctionLine4(func);
3515
- const firstParam = (0, import_get2.default)(func, "params[0]");
3538
+ const firstParam = (0, import_lodash9.get)(func, "params[0]");
3516
3539
  const exp = func && !isFunctionDefinitionWithBlock2(func) ? firstLine : (
3517
3540
  //@ts-expect-error
3518
3541
  firstLine?.expression
3519
3542
  );
3520
- return func && hasOnlyOneStatement3(func) && getMethodName3(exp) === "push" && !(0, import_includes2.default)(
3543
+ return func && hasOnlyOneStatement3(func) && getMethodName3(exp) === "push" && !(0, import_lodash9.includes)(
3521
3544
  collectParameterValues2(firstParam),
3522
- (0, import_get2.default)(exp, "callee.object.name")
3545
+ (0, import_lodash9.get)(exp, "callee.object.name")
3523
3546
  );
3524
3547
  }
3525
3548
  return getRemedaMethodVisitors(context, (node, iteratee2, { method: method2 }) => {
@@ -3587,7 +3610,7 @@ var RULE_NAME11 = "prefer-nullish-coalescing";
3587
3610
  var prefer_nullish_coalescing_default = rule11;
3588
3611
 
3589
3612
  // src/rules/prefer-remeda-typecheck.ts
3590
- var import_some = __toESM(require("lodash/some"), 1);
3613
+ var import_lodash10 = require("lodash");
3591
3614
  var meta12 = {
3592
3615
  type: "problem",
3593
3616
  schema: [],
@@ -3610,7 +3633,7 @@ function create13(context) {
3610
3633
  const sourceCode = context.sourceCode ?? context.getSourceCode();
3611
3634
  const scope = sourceCode?.getScope?.(node);
3612
3635
  const definedVariables = scope.variables;
3613
- return (0, import_some.default)(definedVariables, { name: node.name });
3636
+ return (0, import_lodash10.some)(definedVariables, { name: node.name });
3614
3637
  }
3615
3638
  function getValueForSide(node, side) {
3616
3639
  const otherSide = otherSides[side];
@@ -3690,7 +3713,7 @@ var RULE_NAME13 = "prefer-some";
3690
3713
  var prefer_some_default = rule13;
3691
3714
 
3692
3715
  // src/rules/prefer-times.ts
3693
- var import_lodash6 = require("lodash");
3716
+ var import_lodash11 = require("lodash");
3694
3717
  var meta14 = {
3695
3718
  type: "problem",
3696
3719
  schema: [],
@@ -3700,7 +3723,7 @@ var meta14 = {
3700
3723
  };
3701
3724
  function create15(context) {
3702
3725
  return getRemedaMethodVisitors(context, (node, iteratee2, { method: method2 }) => {
3703
- if (method2 === "map" && (0, import_lodash6.get)(iteratee2, "params.length") === 0) {
3726
+ if (method2 === "map" && (0, import_lodash11.get)(iteratee2, "params.length") === 0) {
3704
3727
  context.report({
3705
3728
  node,
3706
3729
  message: "Prefer R.times over R.map without using arguments"
@@ -3741,7 +3764,7 @@ var plugin = {
3741
3764
  configs: {},
3742
3765
  processors: {}
3743
3766
  };
3744
- var pluginShortName = import_lodash7.default.last(plugin.meta.name.split("-"));
3767
+ var pluginShortName = (0, import_lodash12.last)(plugin.meta.name.split("-"));
3745
3768
  Object.assign(plugin.configs, {
3746
3769
  recommended: {
3747
3770
  plugins: {