eslint-plugin-remeda 1.3.1 → 1.5.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.
- package/README.md +30 -20
- package/dist/index.cjs +99 -88
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +48 -27
- package/docs/rules/collection-method-value.md +5 -1
- package/docs/rules/collection-return.md +5 -1
- package/docs/rules/prefer-constant.md +9 -1
- package/docs/rules/prefer-do-nothing.md +5 -1
- package/docs/rules/prefer-filter.md +9 -1
- package/docs/rules/prefer-find.md +5 -1
- package/docs/rules/prefer-flat-map.md +5 -1
- package/docs/rules/prefer-is-empty.md +7 -1
- package/docs/rules/{prefer-is-nil.md → prefer-is-nullish.md} +4 -4
- package/docs/rules/prefer-map.md +5 -1
- package/docs/rules/prefer-nullish-coalescing.md +9 -3
- package/docs/rules/prefer-remeda-typecheck.md +5 -1
- package/docs/rules/prefer-some.md +5 -1
- package/docs/rules/prefer-times.md +5 -1
- package/package.json +7 -4
package/README.md
CHANGED
@@ -2,42 +2,52 @@
|
|
2
2
|
|
3
3
|
ESLint plugin for [Remeda](https://github.com/remeda/remeda).
|
4
4
|
|
5
|
+
## Preamble
|
6
|
+
|
7
|
+
This plugin was originally derived from [eslint-plugin-lodash-f](https://github.com/AndreaPontrandolfo/eslint-plugin-lodash) (fork of [eslint-plugin-lodash](https://github.com/wix-incubator/eslint-plugin-lodash)) and used that as a base to build upon.
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
First, you'll first need to install [ESLint](https://eslint.org/):
|
8
12
|
|
9
13
|
```sh
|
10
|
-
|
14
|
+
pnpm add -D eslint
|
11
15
|
```
|
12
16
|
|
13
17
|
Next, install `eslint-plugin-remeda`:
|
14
18
|
|
15
19
|
```sh
|
16
|
-
|
20
|
+
pnpm add -D eslint-plugin-remeda
|
17
21
|
```
|
18
22
|
|
19
|
-
## Preamble
|
20
|
-
|
21
|
-
This plugin was originally derived from [eslint-plugin-lodash-f](https://github.com/AndreaPontrandolfo/eslint-plugin-lodash) (fork of [eslint-plugin-lodash](https://github.com/wix-incubator/eslint-plugin-lodash)) and used that as a base to build upon.
|
22
|
-
|
23
23
|
## Rules
|
24
24
|
|
25
25
|
Enable all of the rules that you would like to use. All rules are off by default, unless you use one of the plugin's configurations which turn all relevant rules on.
|
26
26
|
|
27
|
-
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
<!-- begin auto-generated rules list -->
|
28
|
+
|
29
|
+
💼 Configurations enabled in.\
|
30
|
+
✅ Set in the `recommended` configuration.\
|
31
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
32
|
+
|
33
|
+
| Name | 💼 | 🔧 |
|
34
|
+
| :------------------------------------------------------------------- | :-- | :-- |
|
35
|
+
| [collection-method-value](docs/rules/collection-method-value.md) | ✅ | |
|
36
|
+
| [collection-return](docs/rules/collection-return.md) | ✅ | |
|
37
|
+
| [prefer-constant](docs/rules/prefer-constant.md) | ✅ | |
|
38
|
+
| [prefer-do-nothing](docs/rules/prefer-do-nothing.md) | ✅ | |
|
39
|
+
| [prefer-filter](docs/rules/prefer-filter.md) | ✅ | |
|
40
|
+
| [prefer-find](docs/rules/prefer-find.md) | ✅ | |
|
41
|
+
| [prefer-flat-map](docs/rules/prefer-flat-map.md) | ✅ | |
|
42
|
+
| [prefer-is-empty](docs/rules/prefer-is-empty.md) | ✅ | 🔧 |
|
43
|
+
| [prefer-is-nullish](docs/rules/prefer-is-nullish.md) | ✅ | |
|
44
|
+
| [prefer-map](docs/rules/prefer-map.md) | ✅ | |
|
45
|
+
| [prefer-nullish-coalescing](docs/rules/prefer-nullish-coalescing.md) | ✅ | 🔧 |
|
46
|
+
| [prefer-remeda-typecheck](docs/rules/prefer-remeda-typecheck.md) | ✅ | |
|
47
|
+
| [prefer-some](docs/rules/prefer-some.md) | ✅ | |
|
48
|
+
| [prefer-times](docs/rules/prefer-times.md) | ✅ | |
|
49
|
+
|
50
|
+
<!-- end auto-generated rules list -->
|
41
51
|
|
42
52
|
## Contributing
|
43
53
|
|
package/dist/index.cjs
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
|
30
20
|
// src/index.ts
|
@@ -33,7 +23,7 @@ __export(src_exports, {
|
|
33
23
|
default: () => src_default
|
34
24
|
});
|
35
25
|
module.exports = __toCommonJS(src_exports);
|
36
|
-
var
|
26
|
+
var import_lodash_es12 = require("lodash-es");
|
37
27
|
|
38
28
|
// package.json
|
39
29
|
var version = "0.0.0-development";
|
@@ -55,6 +45,8 @@ var package_default = {
|
|
55
45
|
attw: "attw --pack .",
|
56
46
|
qa: "pnpm typecheck && pnpm test && pnpm knip && pnpm publint && attw",
|
57
47
|
nuke: "rm -rf node_modules pnpm-lock.yaml",
|
48
|
+
"update:eslint-docs": "eslint-doc-generator",
|
49
|
+
"lint:eslint-docs": "pnpm update:eslint-docs -- --check",
|
58
50
|
"semantic-release": "pnpm build && semantic-release"
|
59
51
|
},
|
60
52
|
files: [
|
@@ -80,14 +72,15 @@ var package_default = {
|
|
80
72
|
},
|
81
73
|
devDependencies: {
|
82
74
|
"@arethetypeswrong/cli": "^0.15.4",
|
83
|
-
"@types/lodash": "^4.17.
|
75
|
+
"@types/lodash-es": "^4.17.12",
|
84
76
|
"@types/node": "^20.14.9",
|
85
77
|
"@vitest/coverage-v8": "^2.0.3",
|
86
78
|
"@vitest/ui": "^2.0.3",
|
87
79
|
eslint: "9.10.0",
|
88
80
|
"eslint-config-sheriff": "^21.2.0",
|
89
81
|
"eslint-define-config": "^2.1.0",
|
90
|
-
"eslint-
|
82
|
+
"eslint-doc-generator": "^2.1.2",
|
83
|
+
"eslint-plugin-eslint-plugin": "^6.4.0",
|
91
84
|
"eslint-vitest-rule-tester": "^0.3.3",
|
92
85
|
knip: "^5.29.1",
|
93
86
|
prettier: "^3.3.2",
|
@@ -115,39 +108,39 @@ var package_default = {
|
|
115
108
|
],
|
116
109
|
license: "MIT",
|
117
110
|
dependencies: {
|
118
|
-
lodash: "^4.17.21"
|
111
|
+
"lodash-es": "^4.17.21"
|
119
112
|
}
|
120
113
|
};
|
121
114
|
|
122
115
|
// src/rules/collection-method-value.ts
|
123
|
-
var
|
116
|
+
var import_lodash_es6 = require("lodash-es");
|
124
117
|
|
125
118
|
// src/util/astUtil.ts
|
126
|
-
var
|
127
|
-
var getCaller = (0,
|
128
|
-
var getMethodName = (0,
|
129
|
-
var isMethodCall = (0,
|
119
|
+
var import_lodash_es = require("lodash-es");
|
120
|
+
var getCaller = (0, import_lodash_es.property)(["callee", "object"]);
|
121
|
+
var getMethodName = (0, import_lodash_es.property)(["callee", "property", "name"]);
|
122
|
+
var isMethodCall = (0, import_lodash_es.matches)({
|
130
123
|
type: "CallExpression",
|
131
124
|
callee: { type: "MemberExpression" }
|
132
125
|
});
|
133
|
-
var isFunctionExpression = (0,
|
134
|
-
(0,
|
135
|
-
(0,
|
126
|
+
var isFunctionExpression = (0, import_lodash_es.overSome)(
|
127
|
+
(0, import_lodash_es.matchesProperty)("type", "FunctionExpression"),
|
128
|
+
(0, import_lodash_es.matchesProperty)("type", "FunctionDeclaration")
|
136
129
|
);
|
137
|
-
var isFunctionDefinitionWithBlock = (0,
|
130
|
+
var isFunctionDefinitionWithBlock = (0, import_lodash_es.overSome)(
|
138
131
|
isFunctionExpression,
|
139
|
-
(0,
|
132
|
+
(0, import_lodash_es.matches)({
|
140
133
|
type: "ArrowFunctionExpression",
|
141
134
|
body: { type: "BlockStatement" }
|
142
135
|
})
|
143
136
|
);
|
144
|
-
var getFirstFunctionLine = (0,
|
145
|
-
[isFunctionDefinitionWithBlock, (0,
|
146
|
-
[(0,
|
137
|
+
var getFirstFunctionLine = (0, import_lodash_es.cond)([
|
138
|
+
[isFunctionDefinitionWithBlock, (0, import_lodash_es.property)(["body", "body", 0])],
|
139
|
+
[(0, import_lodash_es.matches)({ type: "ArrowFunctionExpression" }), (0, import_lodash_es.property)("body")]
|
147
140
|
]);
|
148
|
-
var isPropAccess = (0,
|
149
|
-
(0,
|
150
|
-
(0,
|
141
|
+
var isPropAccess = (0, import_lodash_es.overSome)(
|
142
|
+
(0, import_lodash_es.matches)({ computed: false }),
|
143
|
+
(0, import_lodash_es.matchesProperty)(["property", "type"], "Literal")
|
151
144
|
);
|
152
145
|
function isMemberExpOf(node, objectName, { maxLength = Number.MAX_VALUE, allowComputed } = {}) {
|
153
146
|
if (objectName) {
|
@@ -166,18 +159,18 @@ function isMemberExpOf(node, objectName, { maxLength = Number.MAX_VALUE, allowCo
|
|
166
159
|
}
|
167
160
|
}
|
168
161
|
}
|
169
|
-
var getFirstParamName = (0,
|
170
|
-
var isReturnStatement = (0,
|
162
|
+
var getFirstParamName = (0, import_lodash_es.property)(["params", 0, "name"]);
|
163
|
+
var isReturnStatement = (0, import_lodash_es.matchesProperty)("type", "ReturnStatement");
|
171
164
|
function hasOnlyOneStatement(func) {
|
172
165
|
if (isFunctionDefinitionWithBlock(func)) {
|
173
|
-
return (0,
|
166
|
+
return (0, import_lodash_es.get)(func, "body.body.length") === 1;
|
174
167
|
}
|
175
168
|
if (func.type === "ArrowFunctionExpression") {
|
176
|
-
return !(0,
|
169
|
+
return !(0, import_lodash_es.get)(func, "body.body");
|
177
170
|
}
|
178
171
|
}
|
179
172
|
function isObjectOfMethodCall(node) {
|
180
|
-
return (0,
|
173
|
+
return (0, import_lodash_es.get)(node, "parent.object") === node && (0, import_lodash_es.get)(node, "parent.parent.type") === "CallExpression";
|
181
174
|
}
|
182
175
|
function isLiteral(node) {
|
183
176
|
return node.type === "Literal";
|
@@ -187,7 +180,7 @@ function isBinaryExpWithMemberOf(operator, exp, objectName, {
|
|
187
180
|
allowComputed,
|
188
181
|
onlyLiterals
|
189
182
|
} = {}) {
|
190
|
-
if (!(0,
|
183
|
+
if (!(0, import_lodash_es.isMatch)(exp, { type: "BinaryExpression", operator })) {
|
191
184
|
return false;
|
192
185
|
}
|
193
186
|
const [left, right] = [exp.left, exp.right].map(
|
@@ -195,7 +188,7 @@ function isBinaryExpWithMemberOf(operator, exp, objectName, {
|
|
195
188
|
);
|
196
189
|
return left === !right && (!onlyLiterals || isLiteral(exp.left) || isLiteral(exp.right));
|
197
190
|
}
|
198
|
-
var isNegationExpression = (0,
|
191
|
+
var isNegationExpression = (0, import_lodash_es.matches)({
|
199
192
|
type: "UnaryExpression",
|
200
193
|
operator: "!"
|
201
194
|
});
|
@@ -217,14 +210,14 @@ function getValueReturnedInFirstStatement(func) {
|
|
217
210
|
}
|
218
211
|
}
|
219
212
|
function isCallFromObject(node, objName) {
|
220
|
-
return node && objName && node.type === "CallExpression" && (0,
|
213
|
+
return node && objName && node.type === "CallExpression" && (0, import_lodash_es.get)(node, "callee.object.name") === objName;
|
221
214
|
}
|
222
215
|
function isComputed(node) {
|
223
|
-
return (0,
|
216
|
+
return (0, import_lodash_es.get)(node, "computed") && node.property.type !== "Literal";
|
224
217
|
}
|
225
218
|
function isEquivalentMemberExp(a, b) {
|
226
|
-
return (0,
|
227
|
-
if ((0,
|
219
|
+
return (0, import_lodash_es.isEqualWith)(a, b, (left, right, key) => {
|
220
|
+
if ((0, import_lodash_es.includes)(["loc", "range", "computed", "start", "end", "parent"], key)) {
|
228
221
|
return true;
|
229
222
|
}
|
230
223
|
if (isComputed(left) || isComputed(right)) {
|
@@ -237,7 +230,7 @@ function isEquivalentMemberExp(a, b) {
|
|
237
230
|
}
|
238
231
|
});
|
239
232
|
}
|
240
|
-
var isEqEqEq = (0,
|
233
|
+
var isEqEqEq = (0, import_lodash_es.matches)({ type: "BinaryExpression", operator: "===" });
|
241
234
|
var isMinus = (node) => node.type === "UnaryExpression" && node.operator === "-";
|
242
235
|
var comparisonType = {
|
243
236
|
exact: 0,
|
@@ -247,11 +240,11 @@ var comparisonType = {
|
|
247
240
|
};
|
248
241
|
var comparisonOperators = ["==", "!=", "===", "!=="];
|
249
242
|
function getIsValue(value2) {
|
250
|
-
return value2 < 0 ? (0,
|
243
|
+
return value2 < 0 ? (0, import_lodash_es.overEvery)(isMinus, (0, import_lodash_es.matches)({ argument: { value: -value2 } })) : (0, import_lodash_es.matches)({ value: value2 });
|
251
244
|
}
|
252
245
|
function getExpressionComparedToInt(node, value2, checkOver) {
|
253
246
|
const isValue = getIsValue(value2);
|
254
|
-
if ((0,
|
247
|
+
if ((0, import_lodash_es.includes)(comparisonOperators, node.operator)) {
|
255
248
|
if (isValue(node.right)) {
|
256
249
|
return node.left;
|
257
250
|
}
|
@@ -283,13 +276,13 @@ function collectParameterValues(node) {
|
|
283
276
|
return [node.name];
|
284
277
|
}
|
285
278
|
case "ObjectPattern": {
|
286
|
-
return (0,
|
279
|
+
return (0, import_lodash_es.flatMap)(
|
287
280
|
node.properties,
|
288
281
|
(prop) => collectParameterValues(prop.value)
|
289
282
|
);
|
290
283
|
}
|
291
284
|
case "ArrayPattern": {
|
292
|
-
return (0,
|
285
|
+
return (0, import_lodash_es.flatMap)(node.elements, collectParameterValues);
|
293
286
|
}
|
294
287
|
default: {
|
295
288
|
return [];
|
@@ -331,7 +324,7 @@ function getDocsUrl(ruleName) {
|
|
331
324
|
}
|
332
325
|
|
333
326
|
// src/util/methodDataUtil.ts
|
334
|
-
var
|
327
|
+
var import_lodash_es2 = require("lodash-es");
|
335
328
|
|
336
329
|
// src/util/methodData.ts
|
337
330
|
var methodData_exports = {};
|
@@ -460,8 +453,8 @@ __export(methodData_exports, {
|
|
460
453
|
isMatchWith: () => isMatchWith,
|
461
454
|
isNaN: () => isNaN,
|
462
455
|
isNative: () => isNative,
|
463
|
-
isNil: () => isNil,
|
464
456
|
isNull: () => isNull,
|
457
|
+
isNullish: () => isNullish,
|
465
458
|
isNumber: () => isNumber,
|
466
459
|
isObject: () => isObject,
|
467
460
|
isObjectLike: () => isObjectLike,
|
@@ -1488,7 +1481,7 @@ var isNative = {
|
|
1488
1481
|
iteratee: false,
|
1489
1482
|
args: 1
|
1490
1483
|
};
|
1491
|
-
var
|
1484
|
+
var isNullish = {
|
1492
1485
|
wrapper: false,
|
1493
1486
|
shorthand: false,
|
1494
1487
|
chainable: false,
|
@@ -2755,16 +2748,16 @@ var zipWith = {
|
|
2755
2748
|
|
2756
2749
|
// src/util/methodDataUtil.ts
|
2757
2750
|
function isCollectionMethod(method2) {
|
2758
|
-
return methodSupportsShorthand(method2) || (0,
|
2751
|
+
return methodSupportsShorthand(method2) || (0, import_lodash_es2.includes)(["reduce", "reduceRight"], method2);
|
2759
2752
|
}
|
2760
2753
|
function methodSupportsShorthand(method2, shorthandType) {
|
2761
|
-
const methodShorthandData = (0,
|
2762
|
-
return (0,
|
2754
|
+
const methodShorthandData = (0, import_lodash_es2.get)(methodData_exports, `${method2}.shorthand`);
|
2755
|
+
return (0, import_lodash_es2.isObject)(methodShorthandData) ? Boolean(shorthandType && methodShorthandData[shorthandType]) : Boolean(methodShorthandData);
|
2763
2756
|
}
|
2764
2757
|
function getIterateeIndex(method2) {
|
2765
2758
|
const methodData = methodData_exports[method2];
|
2766
2759
|
if (methodData) {
|
2767
|
-
if ((0,
|
2760
|
+
if ((0, import_lodash_es2.has)(methodData, "iterateeIndex")) {
|
2768
2761
|
return methodData.iterateeIndex;
|
2769
2762
|
}
|
2770
2763
|
if (methodData.iteratee) {
|
@@ -2786,20 +2779,20 @@ function getSideEffectIterationMethods() {
|
|
2786
2779
|
}
|
2787
2780
|
|
2788
2781
|
// src/util/remedaUtil.ts
|
2789
|
-
var
|
2782
|
+
var import_lodash_es5 = require("lodash-es");
|
2790
2783
|
|
2791
2784
|
// src/util/settingsUtil.ts
|
2792
|
-
var
|
2785
|
+
var import_lodash_es3 = require("lodash-es");
|
2793
2786
|
function getSettings(context) {
|
2794
|
-
return (0,
|
2787
|
+
return (0, import_lodash_es3.chain)(context).get(["settings", "remeda"]).clone().defaults({
|
2795
2788
|
version: 4
|
2796
2789
|
}).value();
|
2797
2790
|
}
|
2798
2791
|
|
2799
2792
|
// src/util/importUtil.ts
|
2800
|
-
var
|
2793
|
+
var import_lodash_es4 = require("lodash-es");
|
2801
2794
|
function getNameFromCjsRequire(init) {
|
2802
|
-
if ((0,
|
2795
|
+
if ((0, import_lodash_es4.get)(init, "callee.name") === "require" && (0, import_lodash_es4.get)(init, "arguments.length") === 1 && init.arguments[0].type === "Literal") {
|
2803
2796
|
return init.arguments[0].value;
|
2804
2797
|
}
|
2805
2798
|
}
|
@@ -2943,7 +2936,7 @@ function getIsTypeMethod(name) {
|
|
2943
2936
|
"Error"
|
2944
2937
|
// "Element",
|
2945
2938
|
];
|
2946
|
-
return (0,
|
2939
|
+
return (0, import_lodash_es5.includes)(types, name) ? `is${(0, import_lodash_es5.capitalize)(name)}` : null;
|
2947
2940
|
}
|
2948
2941
|
function getRemedaMethodCallExpVisitor(remedaContext, reporter) {
|
2949
2942
|
return function(node) {
|
@@ -2997,6 +2990,7 @@ var meta = {
|
|
2997
2990
|
type: "problem",
|
2998
2991
|
schema: [],
|
2999
2992
|
docs: {
|
2993
|
+
description: "Use value returned from collection methods properly",
|
3000
2994
|
url: getDocsUrl("collection-method-value")
|
3001
2995
|
}
|
3002
2996
|
};
|
@@ -3005,7 +2999,7 @@ function create2(context) {
|
|
3005
2999
|
return node.parent.type !== "ExpressionStatement";
|
3006
3000
|
}
|
3007
3001
|
function isSideEffectIterationMethod(method2) {
|
3008
|
-
return (0,
|
3002
|
+
return (0, import_lodash_es6.includes)(getSideEffectIterationMethods(), method2);
|
3009
3003
|
}
|
3010
3004
|
function isParentCommit(node, callType) {
|
3011
3005
|
return callType === "chained" && isCallToMethod(node.parent.parent, "commit");
|
@@ -3035,11 +3029,12 @@ var RULE_NAME = "collection-method-value";
|
|
3035
3029
|
var collection_method_value_default = rule;
|
3036
3030
|
|
3037
3031
|
// src/rules/collection-return.ts
|
3038
|
-
var
|
3032
|
+
var import_lodash_es7 = require("lodash-es");
|
3039
3033
|
var meta2 = {
|
3040
3034
|
type: "problem",
|
3041
3035
|
schema: [],
|
3042
3036
|
docs: {
|
3037
|
+
description: "Always return a value in iteratees of Remeda collection methods that aren't `forEach`",
|
3043
3038
|
url: getDocsUrl("collection-return")
|
3044
3039
|
}
|
3045
3040
|
};
|
@@ -3047,7 +3042,7 @@ function create3(context) {
|
|
3047
3042
|
const funcInfos = /* @__PURE__ */ new Map();
|
3048
3043
|
let currFuncInfo;
|
3049
3044
|
const remedaContext = getRemedaContext(context);
|
3050
|
-
return (0,
|
3045
|
+
return (0, import_lodash_es7.assign)(
|
3051
3046
|
{
|
3052
3047
|
"CallExpression:exit": getRemedaMethodCallExpVisitor(
|
3053
3048
|
remedaContext,
|
@@ -3093,6 +3088,7 @@ var { getValueReturnedInFirstStatement: getValueReturnedInFirstStatement2 } = as
|
|
3093
3088
|
var meta3 = {
|
3094
3089
|
type: "problem",
|
3095
3090
|
docs: {
|
3091
|
+
description: "Prefer R.constant over functions returning literals",
|
3096
3092
|
url: getDocsUrl("prefer-constant")
|
3097
3093
|
},
|
3098
3094
|
schema: [
|
@@ -3165,6 +3161,7 @@ var meta4 = {
|
|
3165
3161
|
type: "problem",
|
3166
3162
|
schema: [],
|
3167
3163
|
docs: {
|
3164
|
+
description: "Prefer R.doNothing() or R.constant(undefined) over an empty function",
|
3168
3165
|
url: getDocsUrl("prefer-do-nothing")
|
3169
3166
|
}
|
3170
3167
|
};
|
@@ -3203,6 +3200,7 @@ var {
|
|
3203
3200
|
var meta5 = {
|
3204
3201
|
type: "problem",
|
3205
3202
|
docs: {
|
3203
|
+
description: "Prefer R.filter or R.some over an if statement inside a R.forEach",
|
3206
3204
|
url: getDocsUrl("prefer-filter")
|
3207
3205
|
},
|
3208
3206
|
schema: [
|
@@ -3245,6 +3243,7 @@ var meta6 = {
|
|
3245
3243
|
type: "problem",
|
3246
3244
|
schema: [],
|
3247
3245
|
docs: {
|
3246
|
+
description: "Prefer using `R.find` over selecting the first item of a filtered result",
|
3248
3247
|
url: getDocsUrl("prefer-find")
|
3249
3248
|
}
|
3250
3249
|
};
|
@@ -3288,6 +3287,7 @@ var meta7 = {
|
|
3288
3287
|
type: "problem",
|
3289
3288
|
schema: [],
|
3290
3289
|
docs: {
|
3290
|
+
description: "Prefer R.flatMap over consecutive R.map and R.flat.",
|
3291
3291
|
url: getDocsUrl("prefer-flat-map")
|
3292
3292
|
}
|
3293
3293
|
};
|
@@ -3319,6 +3319,7 @@ var meta8 = {
|
|
3319
3319
|
type: "problem",
|
3320
3320
|
schema: [],
|
3321
3321
|
docs: {
|
3322
|
+
description: "Prefer R.isEmpty over manually checking for length value.",
|
3322
3323
|
url: getDocsUrl("prefer-is-empty")
|
3323
3324
|
},
|
3324
3325
|
fixable: "code"
|
@@ -3419,28 +3420,29 @@ var rule8 = {
|
|
3419
3420
|
var RULE_NAME8 = "prefer-is-empty";
|
3420
3421
|
var prefer_is_empty_default = rule8;
|
3421
3422
|
|
3422
|
-
// src/rules/prefer-is-
|
3423
|
-
var
|
3423
|
+
// src/rules/prefer-is-nullish.ts
|
3424
|
+
var import_lodash_es8 = require("lodash-es");
|
3424
3425
|
var { isNegationExpression: isNegationExpression2, isEquivalentMemberExp: isEquivalentMemberExp2 } = astUtil_default;
|
3425
3426
|
var meta9 = {
|
3426
3427
|
type: "problem",
|
3427
3428
|
schema: [],
|
3428
3429
|
docs: {
|
3429
|
-
|
3430
|
+
description: "Prefer R.isNullish over checks for both null and undefined.",
|
3431
|
+
url: getDocsUrl("prefer-is-nullish")
|
3430
3432
|
}
|
3431
3433
|
};
|
3432
3434
|
function create10(context) {
|
3433
3435
|
const remedaContext = getRemedaContext(context);
|
3434
3436
|
const nilChecks = {
|
3435
3437
|
null: {
|
3436
|
-
isValue: (0,
|
3438
|
+
isValue: (0, import_lodash_es8.matches)({ type: "Literal", value: null }),
|
3437
3439
|
expressionChecks: [
|
3438
3440
|
getRemedaTypeCheckedBy("isNull"),
|
3439
3441
|
getValueComparedTo("null")
|
3440
3442
|
]
|
3441
3443
|
},
|
3442
3444
|
undefined: {
|
3443
|
-
isValue: (0,
|
3445
|
+
isValue: (0, import_lodash_es8.matches)({ type: "Identifier", name: "undefined" }),
|
3444
3446
|
expressionChecks: [
|
3445
3447
|
getRemedaTypeCheckedBy("isUndefined"),
|
3446
3448
|
getValueComparedTo("undefined"),
|
@@ -3458,13 +3460,13 @@ function create10(context) {
|
|
3458
3460
|
return node.type === "BinaryExpression" && node.operator === operator && (nilChecks[nil].isValue(node.right) && node.left || nilChecks[nil].isValue(node.left) && node.right);
|
3459
3461
|
};
|
3460
3462
|
}
|
3461
|
-
const getTypeofArgument = (0,
|
3463
|
+
const getTypeofArgument = (0, import_lodash_es8.cond)([
|
3462
3464
|
[
|
3463
|
-
(0,
|
3464
|
-
(0,
|
3465
|
+
(0, import_lodash_es8.matches)({ type: "UnaryExpression", operator: "typeof" }),
|
3466
|
+
(0, import_lodash_es8.property)("argument")
|
3465
3467
|
]
|
3466
3468
|
]);
|
3467
|
-
const isUndefinedString = (0,
|
3469
|
+
const isUndefinedString = (0, import_lodash_es8.matches)({
|
3468
3470
|
type: "Literal",
|
3469
3471
|
value: "undefined"
|
3470
3472
|
});
|
@@ -3472,7 +3474,11 @@ function create10(context) {
|
|
3472
3474
|
return node.type === "BinaryExpression" && node.operator === operator && (isUndefinedString(node.right) && getTypeofArgument(node.left) || isUndefinedString(node.left) && getTypeofArgument(node.right));
|
3473
3475
|
}
|
3474
3476
|
function checkExpression(nil, operator, node) {
|
3475
|
-
|
3477
|
+
const mappedValues = (0, import_lodash_es8.map)(
|
3478
|
+
nilChecks[nil].expressionChecks,
|
3479
|
+
(check) => check(node, operator)
|
3480
|
+
);
|
3481
|
+
return (0, import_lodash_es8.find)(mappedValues);
|
3476
3482
|
}
|
3477
3483
|
function checkNegatedExpression(nil, node) {
|
3478
3484
|
return isNegationExpression2(node) && checkExpression(nil, "===", node.argument) || checkExpression(nil, "!==", node);
|
@@ -3497,13 +3503,13 @@ function create10(context) {
|
|
3497
3503
|
if (isEquivalentExistingExpression(node, "undefined", "null") || isEquivalentExistingExpression(node, "null", "undefined")) {
|
3498
3504
|
context.report({
|
3499
3505
|
node,
|
3500
|
-
message: "Prefer
|
3506
|
+
message: "Prefer isNullish over checking for undefined or null."
|
3501
3507
|
});
|
3502
3508
|
}
|
3503
3509
|
} else if (isEquivalentExistingNegation(node, "undefined", "null") || isEquivalentExistingNegation(node, "null", "undefined")) {
|
3504
3510
|
context.report({
|
3505
3511
|
node,
|
3506
|
-
message: "Prefer
|
3512
|
+
message: "Prefer isNullish over checking for undefined or null."
|
3507
3513
|
});
|
3508
3514
|
}
|
3509
3515
|
};
|
@@ -3513,11 +3519,11 @@ var rule9 = {
|
|
3513
3519
|
create: create10,
|
3514
3520
|
meta: meta9
|
3515
3521
|
};
|
3516
|
-
var RULE_NAME9 = "prefer-is-
|
3517
|
-
var
|
3522
|
+
var RULE_NAME9 = "prefer-is-nullish";
|
3523
|
+
var prefer_is_nullish_default = rule9;
|
3518
3524
|
|
3519
3525
|
// src/rules/prefer-map.ts
|
3520
|
-
var
|
3526
|
+
var import_lodash_es9 = require("lodash-es");
|
3521
3527
|
var {
|
3522
3528
|
getFirstFunctionLine: getFirstFunctionLine4,
|
3523
3529
|
hasOnlyOneStatement: hasOnlyOneStatement3,
|
@@ -3529,20 +3535,21 @@ var meta10 = {
|
|
3529
3535
|
type: "problem",
|
3530
3536
|
schema: [],
|
3531
3537
|
docs: {
|
3538
|
+
description: "Prefer R.map over a R.forEach with a push to an array inside",
|
3532
3539
|
url: getDocsUrl("prefer-map")
|
3533
3540
|
}
|
3534
3541
|
};
|
3535
3542
|
function create11(context) {
|
3536
3543
|
function onlyHasPush(func) {
|
3537
3544
|
const firstLine = getFirstFunctionLine4(func);
|
3538
|
-
const firstParam = (0,
|
3545
|
+
const firstParam = (0, import_lodash_es9.get)(func, "params[0]");
|
3539
3546
|
const exp = func && !isFunctionDefinitionWithBlock2(func) ? firstLine : (
|
3540
3547
|
//@ts-expect-error
|
3541
3548
|
firstLine?.expression
|
3542
3549
|
);
|
3543
|
-
return func && hasOnlyOneStatement3(func) && getMethodName3(exp) === "push" && !(0,
|
3550
|
+
return func && hasOnlyOneStatement3(func) && getMethodName3(exp) === "push" && !(0, import_lodash_es9.includes)(
|
3544
3551
|
collectParameterValues2(firstParam),
|
3545
|
-
(0,
|
3552
|
+
(0, import_lodash_es9.get)(exp, "callee.object.name")
|
3546
3553
|
);
|
3547
3554
|
}
|
3548
3555
|
return getRemedaMethodVisitors(context, (node, iteratee2, { method: method2 }) => {
|
@@ -3566,6 +3573,7 @@ var meta11 = {
|
|
3566
3573
|
type: "problem",
|
3567
3574
|
schema: [],
|
3568
3575
|
docs: {
|
3576
|
+
description: "Prefer nullish coalescing over checking a ternary with !isNullish.",
|
3569
3577
|
url: getDocsUrl("prefer-nullish-coalescing")
|
3570
3578
|
},
|
3571
3579
|
fixable: "code"
|
@@ -3584,7 +3592,7 @@ function create12(context) {
|
|
3584
3592
|
visitors.ConditionalExpression = function(node) {
|
3585
3593
|
const statement = node.test;
|
3586
3594
|
if (statement.operator === "!") {
|
3587
|
-
if (statement.argument
|
3595
|
+
if (statement.argument?.callee?.name && statement.argument.callee.name === "isNullish") {
|
3588
3596
|
const argument = getTextOfNode(statement.argument.arguments[0]);
|
3589
3597
|
const consequent = getTextOfNode(node.consequent);
|
3590
3598
|
const alternate = getTextOfNode(node.alternate);
|
@@ -3610,11 +3618,12 @@ var RULE_NAME11 = "prefer-nullish-coalescing";
|
|
3610
3618
|
var prefer_nullish_coalescing_default = rule11;
|
3611
3619
|
|
3612
3620
|
// src/rules/prefer-remeda-typecheck.ts
|
3613
|
-
var
|
3621
|
+
var import_lodash_es10 = require("lodash-es");
|
3614
3622
|
var meta12 = {
|
3615
3623
|
type: "problem",
|
3616
3624
|
schema: [],
|
3617
3625
|
docs: {
|
3626
|
+
description: "Prefer using `R.is*` methods over `typeof` and `instanceof` checks when applicable.",
|
3618
3627
|
url: getDocsUrl("prefer-remeda-typecheck")
|
3619
3628
|
}
|
3620
3629
|
};
|
@@ -3633,7 +3642,7 @@ function create13(context) {
|
|
3633
3642
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
3634
3643
|
const scope = sourceCode?.getScope?.(node);
|
3635
3644
|
const definedVariables = scope.variables;
|
3636
|
-
return (0,
|
3645
|
+
return (0, import_lodash_es10.some)(definedVariables, { name: node.name });
|
3637
3646
|
}
|
3638
3647
|
function getValueForSide(node, side) {
|
3639
3648
|
const otherSide = otherSides[side];
|
@@ -3687,6 +3696,7 @@ var { getExpressionComparedToInt: getExpressionComparedToInt2 } = astUtil_defaul
|
|
3687
3696
|
var meta13 = {
|
3688
3697
|
type: "problem",
|
3689
3698
|
docs: {
|
3699
|
+
description: "Prefer R.some over findIndex comparison to -1",
|
3690
3700
|
url: getDocsUrl("prefer-some")
|
3691
3701
|
},
|
3692
3702
|
schema: []
|
@@ -3713,17 +3723,18 @@ var RULE_NAME13 = "prefer-some";
|
|
3713
3723
|
var prefer_some_default = rule13;
|
3714
3724
|
|
3715
3725
|
// src/rules/prefer-times.ts
|
3716
|
-
var
|
3726
|
+
var import_lodash_es11 = require("lodash-es");
|
3717
3727
|
var meta14 = {
|
3718
3728
|
type: "problem",
|
3719
3729
|
schema: [],
|
3720
3730
|
docs: {
|
3731
|
+
description: "Prefer R.times over R.map without using arguments",
|
3721
3732
|
url: getDocsUrl("prefer-times")
|
3722
3733
|
}
|
3723
3734
|
};
|
3724
3735
|
function create15(context) {
|
3725
3736
|
return getRemedaMethodVisitors(context, (node, iteratee2, { method: method2 }) => {
|
3726
|
-
if (method2 === "map" && (0,
|
3737
|
+
if (method2 === "map" && (0, import_lodash_es11.get)(iteratee2, "params.length") === 0) {
|
3727
3738
|
context.report({
|
3728
3739
|
node,
|
3729
3740
|
message: "Prefer R.times over R.map without using arguments"
|
@@ -3748,7 +3759,7 @@ var rules = {
|
|
3748
3759
|
[RULE_NAME6]: prefer_find_default,
|
3749
3760
|
[RULE_NAME7]: prefer_flat_map_default,
|
3750
3761
|
[RULE_NAME8]: prefer_is_empty_default,
|
3751
|
-
[RULE_NAME9]:
|
3762
|
+
[RULE_NAME9]: prefer_is_nullish_default,
|
3752
3763
|
[RULE_NAME10]: prefer_map_default,
|
3753
3764
|
[RULE_NAME11]: prefer_nullish_coalescing_default,
|
3754
3765
|
[RULE_NAME12]: prefer_remeda_typecheck_default,
|
@@ -3764,7 +3775,7 @@ var plugin = {
|
|
3764
3775
|
configs: {},
|
3765
3776
|
processors: {}
|
3766
3777
|
};
|
3767
|
-
var pluginShortName = (0,
|
3778
|
+
var pluginShortName = (0, import_lodash_es12.last)(plugin.meta.name.split("-"));
|
3768
3779
|
Object.assign(plugin.configs, {
|
3769
3780
|
recommended: {
|
3770
3781
|
plugins: {
|
@@ -3772,7 +3783,7 @@ Object.assign(plugin.configs, {
|
|
3772
3783
|
},
|
3773
3784
|
rules: {
|
3774
3785
|
[`${pluginShortName}/prefer-is-empty`]: 2,
|
3775
|
-
[`${pluginShortName}/prefer-is-
|
3786
|
+
[`${pluginShortName}/prefer-is-nullish`]: 2,
|
3776
3787
|
[`${pluginShortName}/prefer-times`]: 2,
|
3777
3788
|
[`${pluginShortName}/prefer-constant`]: 2,
|
3778
3789
|
[`${pluginShortName}/prefer-remeda-typecheck`]: 2,
|