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/dist/index.d.cts
CHANGED
@@ -14,6 +14,7 @@ declare const plugin: {
|
|
14
14
|
readonly type: "problem";
|
15
15
|
readonly schema: readonly [];
|
16
16
|
readonly docs: {
|
17
|
+
readonly description: "Use value returned from collection methods properly";
|
17
18
|
readonly url: string;
|
18
19
|
};
|
19
20
|
};
|
@@ -38,6 +39,7 @@ declare const plugin: {
|
|
38
39
|
readonly type: "problem";
|
39
40
|
readonly schema: readonly [];
|
40
41
|
readonly docs: {
|
42
|
+
readonly description: "Always return a value in iteratees of Remeda collection methods that aren't `forEach`";
|
41
43
|
readonly url: string;
|
42
44
|
};
|
43
45
|
};
|
@@ -51,6 +53,7 @@ declare const plugin: {
|
|
51
53
|
meta: {
|
52
54
|
readonly type: "problem";
|
53
55
|
readonly docs: {
|
56
|
+
readonly description: "Prefer R.constant over functions returning literals";
|
54
57
|
readonly url: string;
|
55
58
|
};
|
56
59
|
readonly schema: readonly [{
|
@@ -69,6 +72,7 @@ declare const plugin: {
|
|
69
72
|
readonly type: "problem";
|
70
73
|
readonly schema: readonly [];
|
71
74
|
readonly docs: {
|
75
|
+
readonly description: "Prefer R.doNothing() or R.constant(undefined) over an empty function";
|
72
76
|
readonly url: string;
|
73
77
|
};
|
74
78
|
};
|
@@ -78,6 +82,7 @@ declare const plugin: {
|
|
78
82
|
meta: {
|
79
83
|
readonly type: "problem";
|
80
84
|
readonly docs: {
|
85
|
+
readonly description: "Prefer R.filter or R.some over an if statement inside a R.forEach";
|
81
86
|
readonly url: string;
|
82
87
|
};
|
83
88
|
readonly schema: readonly [{
|
@@ -91,6 +96,7 @@ declare const plugin: {
|
|
91
96
|
readonly type: "problem";
|
92
97
|
readonly schema: readonly [];
|
93
98
|
readonly docs: {
|
99
|
+
readonly description: "Prefer using `R.find` over selecting the first item of a filtered result";
|
94
100
|
readonly url: string;
|
95
101
|
};
|
96
102
|
};
|
@@ -101,6 +107,7 @@ declare const plugin: {
|
|
101
107
|
readonly type: "problem";
|
102
108
|
readonly schema: readonly [];
|
103
109
|
readonly docs: {
|
110
|
+
readonly description: "Prefer R.flatMap over consecutive R.map and R.flat.";
|
104
111
|
readonly url: string;
|
105
112
|
};
|
106
113
|
};
|
@@ -111,17 +118,19 @@ declare const plugin: {
|
|
111
118
|
readonly type: "problem";
|
112
119
|
readonly schema: readonly [];
|
113
120
|
readonly docs: {
|
121
|
+
readonly description: "Prefer R.isEmpty over manually checking for length value.";
|
114
122
|
readonly url: string;
|
115
123
|
};
|
116
124
|
readonly fixable: "code";
|
117
125
|
};
|
118
126
|
};
|
119
|
-
"prefer-is-
|
127
|
+
"prefer-is-nullish": {
|
120
128
|
create: (context: any) => RemedaMethodVisitors;
|
121
129
|
meta: {
|
122
130
|
readonly type: "problem";
|
123
131
|
readonly schema: readonly [];
|
124
132
|
readonly docs: {
|
133
|
+
readonly description: "Prefer R.isNullish over checks for both null and undefined.";
|
125
134
|
readonly url: string;
|
126
135
|
};
|
127
136
|
};
|
@@ -132,6 +141,7 @@ declare const plugin: {
|
|
132
141
|
readonly type: "problem";
|
133
142
|
readonly schema: readonly [];
|
134
143
|
readonly docs: {
|
144
|
+
readonly description: "Prefer R.map over a R.forEach with a push to an array inside";
|
135
145
|
readonly url: string;
|
136
146
|
};
|
137
147
|
};
|
@@ -142,6 +152,7 @@ declare const plugin: {
|
|
142
152
|
readonly type: "problem";
|
143
153
|
readonly schema: readonly [];
|
144
154
|
readonly docs: {
|
155
|
+
readonly description: "Prefer nullish coalescing over checking a ternary with !isNullish.";
|
145
156
|
readonly url: string;
|
146
157
|
};
|
147
158
|
readonly fixable: "code";
|
@@ -155,6 +166,7 @@ declare const plugin: {
|
|
155
166
|
readonly type: "problem";
|
156
167
|
readonly schema: readonly [];
|
157
168
|
readonly docs: {
|
169
|
+
readonly description: "Prefer using `R.is*` methods over `typeof` and `instanceof` checks when applicable.";
|
158
170
|
readonly url: string;
|
159
171
|
};
|
160
172
|
};
|
@@ -164,6 +176,7 @@ declare const plugin: {
|
|
164
176
|
meta: {
|
165
177
|
readonly type: "problem";
|
166
178
|
readonly docs: {
|
179
|
+
readonly description: "Prefer R.some over findIndex comparison to -1";
|
167
180
|
readonly url: string;
|
168
181
|
};
|
169
182
|
readonly schema: readonly [];
|
@@ -175,6 +188,7 @@ declare const plugin: {
|
|
175
188
|
readonly type: "problem";
|
176
189
|
readonly schema: readonly [];
|
177
190
|
readonly docs: {
|
191
|
+
readonly description: "Prefer R.times over R.map without using arguments";
|
178
192
|
readonly url: string;
|
179
193
|
};
|
180
194
|
};
|
package/dist/index.d.ts
CHANGED
@@ -14,6 +14,7 @@ declare const plugin: {
|
|
14
14
|
readonly type: "problem";
|
15
15
|
readonly schema: readonly [];
|
16
16
|
readonly docs: {
|
17
|
+
readonly description: "Use value returned from collection methods properly";
|
17
18
|
readonly url: string;
|
18
19
|
};
|
19
20
|
};
|
@@ -38,6 +39,7 @@ declare const plugin: {
|
|
38
39
|
readonly type: "problem";
|
39
40
|
readonly schema: readonly [];
|
40
41
|
readonly docs: {
|
42
|
+
readonly description: "Always return a value in iteratees of Remeda collection methods that aren't `forEach`";
|
41
43
|
readonly url: string;
|
42
44
|
};
|
43
45
|
};
|
@@ -51,6 +53,7 @@ declare const plugin: {
|
|
51
53
|
meta: {
|
52
54
|
readonly type: "problem";
|
53
55
|
readonly docs: {
|
56
|
+
readonly description: "Prefer R.constant over functions returning literals";
|
54
57
|
readonly url: string;
|
55
58
|
};
|
56
59
|
readonly schema: readonly [{
|
@@ -69,6 +72,7 @@ declare const plugin: {
|
|
69
72
|
readonly type: "problem";
|
70
73
|
readonly schema: readonly [];
|
71
74
|
readonly docs: {
|
75
|
+
readonly description: "Prefer R.doNothing() or R.constant(undefined) over an empty function";
|
72
76
|
readonly url: string;
|
73
77
|
};
|
74
78
|
};
|
@@ -78,6 +82,7 @@ declare const plugin: {
|
|
78
82
|
meta: {
|
79
83
|
readonly type: "problem";
|
80
84
|
readonly docs: {
|
85
|
+
readonly description: "Prefer R.filter or R.some over an if statement inside a R.forEach";
|
81
86
|
readonly url: string;
|
82
87
|
};
|
83
88
|
readonly schema: readonly [{
|
@@ -91,6 +96,7 @@ declare const plugin: {
|
|
91
96
|
readonly type: "problem";
|
92
97
|
readonly schema: readonly [];
|
93
98
|
readonly docs: {
|
99
|
+
readonly description: "Prefer using `R.find` over selecting the first item of a filtered result";
|
94
100
|
readonly url: string;
|
95
101
|
};
|
96
102
|
};
|
@@ -101,6 +107,7 @@ declare const plugin: {
|
|
101
107
|
readonly type: "problem";
|
102
108
|
readonly schema: readonly [];
|
103
109
|
readonly docs: {
|
110
|
+
readonly description: "Prefer R.flatMap over consecutive R.map and R.flat.";
|
104
111
|
readonly url: string;
|
105
112
|
};
|
106
113
|
};
|
@@ -111,17 +118,19 @@ declare const plugin: {
|
|
111
118
|
readonly type: "problem";
|
112
119
|
readonly schema: readonly [];
|
113
120
|
readonly docs: {
|
121
|
+
readonly description: "Prefer R.isEmpty over manually checking for length value.";
|
114
122
|
readonly url: string;
|
115
123
|
};
|
116
124
|
readonly fixable: "code";
|
117
125
|
};
|
118
126
|
};
|
119
|
-
"prefer-is-
|
127
|
+
"prefer-is-nullish": {
|
120
128
|
create: (context: any) => RemedaMethodVisitors;
|
121
129
|
meta: {
|
122
130
|
readonly type: "problem";
|
123
131
|
readonly schema: readonly [];
|
124
132
|
readonly docs: {
|
133
|
+
readonly description: "Prefer R.isNullish over checks for both null and undefined.";
|
125
134
|
readonly url: string;
|
126
135
|
};
|
127
136
|
};
|
@@ -132,6 +141,7 @@ declare const plugin: {
|
|
132
141
|
readonly type: "problem";
|
133
142
|
readonly schema: readonly [];
|
134
143
|
readonly docs: {
|
144
|
+
readonly description: "Prefer R.map over a R.forEach with a push to an array inside";
|
135
145
|
readonly url: string;
|
136
146
|
};
|
137
147
|
};
|
@@ -142,6 +152,7 @@ declare const plugin: {
|
|
142
152
|
readonly type: "problem";
|
143
153
|
readonly schema: readonly [];
|
144
154
|
readonly docs: {
|
155
|
+
readonly description: "Prefer nullish coalescing over checking a ternary with !isNullish.";
|
145
156
|
readonly url: string;
|
146
157
|
};
|
147
158
|
readonly fixable: "code";
|
@@ -155,6 +166,7 @@ declare const plugin: {
|
|
155
166
|
readonly type: "problem";
|
156
167
|
readonly schema: readonly [];
|
157
168
|
readonly docs: {
|
169
|
+
readonly description: "Prefer using `R.is*` methods over `typeof` and `instanceof` checks when applicable.";
|
158
170
|
readonly url: string;
|
159
171
|
};
|
160
172
|
};
|
@@ -164,6 +176,7 @@ declare const plugin: {
|
|
164
176
|
meta: {
|
165
177
|
readonly type: "problem";
|
166
178
|
readonly docs: {
|
179
|
+
readonly description: "Prefer R.some over findIndex comparison to -1";
|
167
180
|
readonly url: string;
|
168
181
|
};
|
169
182
|
readonly schema: readonly [];
|
@@ -175,6 +188,7 @@ declare const plugin: {
|
|
175
188
|
readonly type: "problem";
|
176
189
|
readonly schema: readonly [];
|
177
190
|
readonly docs: {
|
191
|
+
readonly description: "Prefer R.times over R.map without using arguments";
|
178
192
|
readonly url: string;
|
179
193
|
};
|
180
194
|
};
|
package/dist/index.js
CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
5
5
|
};
|
6
6
|
|
7
7
|
// src/index.ts
|
8
|
-
import { last as last2 } from "lodash";
|
8
|
+
import { last as last2 } from "lodash-es";
|
9
9
|
|
10
10
|
// package.json
|
11
11
|
var version = "0.0.0-development";
|
@@ -27,6 +27,8 @@ var package_default = {
|
|
27
27
|
attw: "attw --pack .",
|
28
28
|
qa: "pnpm typecheck && pnpm test && pnpm knip && pnpm publint && attw",
|
29
29
|
nuke: "rm -rf node_modules pnpm-lock.yaml",
|
30
|
+
"update:eslint-docs": "eslint-doc-generator",
|
31
|
+
"lint:eslint-docs": "pnpm update:eslint-docs -- --check",
|
30
32
|
"semantic-release": "pnpm build && semantic-release"
|
31
33
|
},
|
32
34
|
files: [
|
@@ -52,14 +54,15 @@ var package_default = {
|
|
52
54
|
},
|
53
55
|
devDependencies: {
|
54
56
|
"@arethetypeswrong/cli": "^0.15.4",
|
55
|
-
"@types/lodash": "^4.17.
|
57
|
+
"@types/lodash-es": "^4.17.12",
|
56
58
|
"@types/node": "^20.14.9",
|
57
59
|
"@vitest/coverage-v8": "^2.0.3",
|
58
60
|
"@vitest/ui": "^2.0.3",
|
59
61
|
eslint: "9.10.0",
|
60
62
|
"eslint-config-sheriff": "^21.2.0",
|
61
63
|
"eslint-define-config": "^2.1.0",
|
62
|
-
"eslint-
|
64
|
+
"eslint-doc-generator": "^2.1.2",
|
65
|
+
"eslint-plugin-eslint-plugin": "^6.4.0",
|
63
66
|
"eslint-vitest-rule-tester": "^0.3.3",
|
64
67
|
knip: "^5.29.1",
|
65
68
|
prettier: "^3.3.2",
|
@@ -87,12 +90,12 @@ var package_default = {
|
|
87
90
|
],
|
88
91
|
license: "MIT",
|
89
92
|
dependencies: {
|
90
|
-
lodash: "^4.17.21"
|
93
|
+
"lodash-es": "^4.17.21"
|
91
94
|
}
|
92
95
|
};
|
93
96
|
|
94
97
|
// src/rules/collection-method-value.ts
|
95
|
-
import { includes as includes5 } from "lodash";
|
98
|
+
import { includes as includes5 } from "lodash-es";
|
96
99
|
|
97
100
|
// src/util/astUtil.ts
|
98
101
|
import {
|
@@ -107,7 +110,7 @@ import {
|
|
107
110
|
overEvery,
|
108
111
|
overSome,
|
109
112
|
property
|
110
|
-
} from "lodash";
|
113
|
+
} from "lodash-es";
|
111
114
|
var getCaller = property(["callee", "object"]);
|
112
115
|
var getMethodName = property(["callee", "property", "name"]);
|
113
116
|
var isMethodCall = matches({
|
@@ -315,7 +318,7 @@ function getDocsUrl(ruleName) {
|
|
315
318
|
}
|
316
319
|
|
317
320
|
// src/util/methodDataUtil.ts
|
318
|
-
import { get as get3, has as has2, includes as includes3, isObject as isObject2 } from "lodash";
|
321
|
+
import { get as get3, has as has2, includes as includes3, isObject as isObject2 } from "lodash-es";
|
319
322
|
|
320
323
|
// src/util/methodData.ts
|
321
324
|
var methodData_exports = {};
|
@@ -444,8 +447,8 @@ __export(methodData_exports, {
|
|
444
447
|
isMatchWith: () => isMatchWith,
|
445
448
|
isNaN: () => isNaN,
|
446
449
|
isNative: () => isNative,
|
447
|
-
isNil: () => isNil,
|
448
450
|
isNull: () => isNull,
|
451
|
+
isNullish: () => isNullish,
|
449
452
|
isNumber: () => isNumber,
|
450
453
|
isObject: () => isObject,
|
451
454
|
isObjectLike: () => isObjectLike,
|
@@ -1472,7 +1475,7 @@ var isNative = {
|
|
1472
1475
|
iteratee: false,
|
1473
1476
|
args: 1
|
1474
1477
|
};
|
1475
|
-
var
|
1478
|
+
var isNullish = {
|
1476
1479
|
wrapper: false,
|
1477
1480
|
shorthand: false,
|
1478
1481
|
chainable: false,
|
@@ -2770,10 +2773,10 @@ function getSideEffectIterationMethods() {
|
|
2770
2773
|
}
|
2771
2774
|
|
2772
2775
|
// src/util/remedaUtil.ts
|
2773
|
-
import { capitalize as capitalize2, includes as includes4 } from "lodash";
|
2776
|
+
import { capitalize as capitalize2, includes as includes4 } from "lodash-es";
|
2774
2777
|
|
2775
2778
|
// src/util/settingsUtil.ts
|
2776
|
-
import { chain as chain2, get as get4 } from "lodash";
|
2779
|
+
import { chain as chain2, get as get4 } from "lodash-es";
|
2777
2780
|
function getSettings(context) {
|
2778
2781
|
return chain2(context).get(["settings", "remeda"]).clone().defaults({
|
2779
2782
|
version: 4
|
@@ -2781,7 +2784,7 @@ function getSettings(context) {
|
|
2781
2784
|
}
|
2782
2785
|
|
2783
2786
|
// src/util/importUtil.ts
|
2784
|
-
import { get as get5 } from "lodash";
|
2787
|
+
import { get as get5 } from "lodash-es";
|
2785
2788
|
function getNameFromCjsRequire(init) {
|
2786
2789
|
if (get5(init, "callee.name") === "require" && get5(init, "arguments.length") === 1 && init.arguments[0].type === "Literal") {
|
2787
2790
|
return init.arguments[0].value;
|
@@ -2981,6 +2984,7 @@ var meta = {
|
|
2981
2984
|
type: "problem",
|
2982
2985
|
schema: [],
|
2983
2986
|
docs: {
|
2987
|
+
description: "Use value returned from collection methods properly",
|
2984
2988
|
url: getDocsUrl("collection-method-value")
|
2985
2989
|
}
|
2986
2990
|
};
|
@@ -3019,11 +3023,12 @@ var RULE_NAME = "collection-method-value";
|
|
3019
3023
|
var collection_method_value_default = rule;
|
3020
3024
|
|
3021
3025
|
// src/rules/collection-return.ts
|
3022
|
-
import { assign as assign2 } from "lodash";
|
3026
|
+
import { assign as assign2 } from "lodash-es";
|
3023
3027
|
var meta2 = {
|
3024
3028
|
type: "problem",
|
3025
3029
|
schema: [],
|
3026
3030
|
docs: {
|
3031
|
+
description: "Always return a value in iteratees of Remeda collection methods that aren't `forEach`",
|
3027
3032
|
url: getDocsUrl("collection-return")
|
3028
3033
|
}
|
3029
3034
|
};
|
@@ -3077,6 +3082,7 @@ var { getValueReturnedInFirstStatement: getValueReturnedInFirstStatement2 } = as
|
|
3077
3082
|
var meta3 = {
|
3078
3083
|
type: "problem",
|
3079
3084
|
docs: {
|
3085
|
+
description: "Prefer R.constant over functions returning literals",
|
3080
3086
|
url: getDocsUrl("prefer-constant")
|
3081
3087
|
},
|
3082
3088
|
schema: [
|
@@ -3149,6 +3155,7 @@ var meta4 = {
|
|
3149
3155
|
type: "problem",
|
3150
3156
|
schema: [],
|
3151
3157
|
docs: {
|
3158
|
+
description: "Prefer R.doNothing() or R.constant(undefined) over an empty function",
|
3152
3159
|
url: getDocsUrl("prefer-do-nothing")
|
3153
3160
|
}
|
3154
3161
|
};
|
@@ -3187,6 +3194,7 @@ var {
|
|
3187
3194
|
var meta5 = {
|
3188
3195
|
type: "problem",
|
3189
3196
|
docs: {
|
3197
|
+
description: "Prefer R.filter or R.some over an if statement inside a R.forEach",
|
3190
3198
|
url: getDocsUrl("prefer-filter")
|
3191
3199
|
},
|
3192
3200
|
schema: [
|
@@ -3229,6 +3237,7 @@ var meta6 = {
|
|
3229
3237
|
type: "problem",
|
3230
3238
|
schema: [],
|
3231
3239
|
docs: {
|
3240
|
+
description: "Prefer using `R.find` over selecting the first item of a filtered result",
|
3232
3241
|
url: getDocsUrl("prefer-find")
|
3233
3242
|
}
|
3234
3243
|
};
|
@@ -3272,6 +3281,7 @@ var meta7 = {
|
|
3272
3281
|
type: "problem",
|
3273
3282
|
schema: [],
|
3274
3283
|
docs: {
|
3284
|
+
description: "Prefer R.flatMap over consecutive R.map and R.flat.",
|
3275
3285
|
url: getDocsUrl("prefer-flat-map")
|
3276
3286
|
}
|
3277
3287
|
};
|
@@ -3303,6 +3313,7 @@ var meta8 = {
|
|
3303
3313
|
type: "problem",
|
3304
3314
|
schema: [],
|
3305
3315
|
docs: {
|
3316
|
+
description: "Prefer R.isEmpty over manually checking for length value.",
|
3306
3317
|
url: getDocsUrl("prefer-is-empty")
|
3307
3318
|
},
|
3308
3319
|
fixable: "code"
|
@@ -3403,14 +3414,15 @@ var rule8 = {
|
|
3403
3414
|
var RULE_NAME8 = "prefer-is-empty";
|
3404
3415
|
var prefer_is_empty_default = rule8;
|
3405
3416
|
|
3406
|
-
// src/rules/prefer-is-
|
3407
|
-
import
|
3417
|
+
// src/rules/prefer-is-nullish.ts
|
3418
|
+
import { cond as cond3, find as find2, map as map2, matches as matches3, property as property3 } from "lodash-es";
|
3408
3419
|
var { isNegationExpression: isNegationExpression2, isEquivalentMemberExp: isEquivalentMemberExp2 } = astUtil_default;
|
3409
3420
|
var meta9 = {
|
3410
3421
|
type: "problem",
|
3411
3422
|
schema: [],
|
3412
3423
|
docs: {
|
3413
|
-
|
3424
|
+
description: "Prefer R.isNullish over checks for both null and undefined.",
|
3425
|
+
url: getDocsUrl("prefer-is-nullish")
|
3414
3426
|
}
|
3415
3427
|
};
|
3416
3428
|
function create10(context) {
|
@@ -3456,7 +3468,11 @@ function create10(context) {
|
|
3456
3468
|
return node.type === "BinaryExpression" && node.operator === operator && (isUndefinedString(node.right) && getTypeofArgument(node.left) || isUndefinedString(node.left) && getTypeofArgument(node.right));
|
3457
3469
|
}
|
3458
3470
|
function checkExpression(nil, operator, node) {
|
3459
|
-
|
3471
|
+
const mappedValues = map2(
|
3472
|
+
nilChecks[nil].expressionChecks,
|
3473
|
+
(check) => check(node, operator)
|
3474
|
+
);
|
3475
|
+
return find2(mappedValues);
|
3460
3476
|
}
|
3461
3477
|
function checkNegatedExpression(nil, node) {
|
3462
3478
|
return isNegationExpression2(node) && checkExpression(nil, "===", node.argument) || checkExpression(nil, "!==", node);
|
@@ -3481,13 +3497,13 @@ function create10(context) {
|
|
3481
3497
|
if (isEquivalentExistingExpression(node, "undefined", "null") || isEquivalentExistingExpression(node, "null", "undefined")) {
|
3482
3498
|
context.report({
|
3483
3499
|
node,
|
3484
|
-
message: "Prefer
|
3500
|
+
message: "Prefer isNullish over checking for undefined or null."
|
3485
3501
|
});
|
3486
3502
|
}
|
3487
3503
|
} else if (isEquivalentExistingNegation(node, "undefined", "null") || isEquivalentExistingNegation(node, "null", "undefined")) {
|
3488
3504
|
context.report({
|
3489
3505
|
node,
|
3490
|
-
message: "Prefer
|
3506
|
+
message: "Prefer isNullish over checking for undefined or null."
|
3491
3507
|
});
|
3492
3508
|
}
|
3493
3509
|
};
|
@@ -3497,11 +3513,11 @@ var rule9 = {
|
|
3497
3513
|
create: create10,
|
3498
3514
|
meta: meta9
|
3499
3515
|
};
|
3500
|
-
var RULE_NAME9 = "prefer-is-
|
3501
|
-
var
|
3516
|
+
var RULE_NAME9 = "prefer-is-nullish";
|
3517
|
+
var prefer_is_nullish_default = rule9;
|
3502
3518
|
|
3503
3519
|
// src/rules/prefer-map.ts
|
3504
|
-
import { get as get6, includes as includes6 } from "lodash";
|
3520
|
+
import { get as get6, includes as includes6 } from "lodash-es";
|
3505
3521
|
var {
|
3506
3522
|
getFirstFunctionLine: getFirstFunctionLine4,
|
3507
3523
|
hasOnlyOneStatement: hasOnlyOneStatement3,
|
@@ -3513,6 +3529,7 @@ var meta10 = {
|
|
3513
3529
|
type: "problem",
|
3514
3530
|
schema: [],
|
3515
3531
|
docs: {
|
3532
|
+
description: "Prefer R.map over a R.forEach with a push to an array inside",
|
3516
3533
|
url: getDocsUrl("prefer-map")
|
3517
3534
|
}
|
3518
3535
|
};
|
@@ -3550,6 +3567,7 @@ var meta11 = {
|
|
3550
3567
|
type: "problem",
|
3551
3568
|
schema: [],
|
3552
3569
|
docs: {
|
3570
|
+
description: "Prefer nullish coalescing over checking a ternary with !isNullish.",
|
3553
3571
|
url: getDocsUrl("prefer-nullish-coalescing")
|
3554
3572
|
},
|
3555
3573
|
fixable: "code"
|
@@ -3568,7 +3586,7 @@ function create12(context) {
|
|
3568
3586
|
visitors.ConditionalExpression = function(node) {
|
3569
3587
|
const statement = node.test;
|
3570
3588
|
if (statement.operator === "!") {
|
3571
|
-
if (statement.argument
|
3589
|
+
if (statement.argument?.callee?.name && statement.argument.callee.name === "isNullish") {
|
3572
3590
|
const argument = getTextOfNode(statement.argument.arguments[0]);
|
3573
3591
|
const consequent = getTextOfNode(node.consequent);
|
3574
3592
|
const alternate = getTextOfNode(node.alternate);
|
@@ -3594,11 +3612,12 @@ var RULE_NAME11 = "prefer-nullish-coalescing";
|
|
3594
3612
|
var prefer_nullish_coalescing_default = rule11;
|
3595
3613
|
|
3596
3614
|
// src/rules/prefer-remeda-typecheck.ts
|
3597
|
-
import { some as some2 } from "lodash";
|
3615
|
+
import { some as some2 } from "lodash-es";
|
3598
3616
|
var meta12 = {
|
3599
3617
|
type: "problem",
|
3600
3618
|
schema: [],
|
3601
3619
|
docs: {
|
3620
|
+
description: "Prefer using `R.is*` methods over `typeof` and `instanceof` checks when applicable.",
|
3602
3621
|
url: getDocsUrl("prefer-remeda-typecheck")
|
3603
3622
|
}
|
3604
3623
|
};
|
@@ -3671,6 +3690,7 @@ var { getExpressionComparedToInt: getExpressionComparedToInt2 } = astUtil_defaul
|
|
3671
3690
|
var meta13 = {
|
3672
3691
|
type: "problem",
|
3673
3692
|
docs: {
|
3693
|
+
description: "Prefer R.some over findIndex comparison to -1",
|
3674
3694
|
url: getDocsUrl("prefer-some")
|
3675
3695
|
},
|
3676
3696
|
schema: []
|
@@ -3697,11 +3717,12 @@ var RULE_NAME13 = "prefer-some";
|
|
3697
3717
|
var prefer_some_default = rule13;
|
3698
3718
|
|
3699
3719
|
// src/rules/prefer-times.ts
|
3700
|
-
import { get as get7 } from "lodash";
|
3720
|
+
import { get as get7 } from "lodash-es";
|
3701
3721
|
var meta14 = {
|
3702
3722
|
type: "problem",
|
3703
3723
|
schema: [],
|
3704
3724
|
docs: {
|
3725
|
+
description: "Prefer R.times over R.map without using arguments",
|
3705
3726
|
url: getDocsUrl("prefer-times")
|
3706
3727
|
}
|
3707
3728
|
};
|
@@ -3732,7 +3753,7 @@ var rules = {
|
|
3732
3753
|
[RULE_NAME6]: prefer_find_default,
|
3733
3754
|
[RULE_NAME7]: prefer_flat_map_default,
|
3734
3755
|
[RULE_NAME8]: prefer_is_empty_default,
|
3735
|
-
[RULE_NAME9]:
|
3756
|
+
[RULE_NAME9]: prefer_is_nullish_default,
|
3736
3757
|
[RULE_NAME10]: prefer_map_default,
|
3737
3758
|
[RULE_NAME11]: prefer_nullish_coalescing_default,
|
3738
3759
|
[RULE_NAME12]: prefer_remeda_typecheck_default,
|
@@ -3756,7 +3777,7 @@ Object.assign(plugin.configs, {
|
|
3756
3777
|
},
|
3757
3778
|
rules: {
|
3758
3779
|
[`${pluginShortName}/prefer-is-empty`]: 2,
|
3759
|
-
[`${pluginShortName}/prefer-is-
|
3780
|
+
[`${pluginShortName}/prefer-is-nullish`]: 2,
|
3760
3781
|
[`${pluginShortName}/prefer-times`]: 2,
|
3761
3782
|
[`${pluginShortName}/prefer-constant`]: 2,
|
3762
3783
|
[`${pluginShortName}/prefer-remeda-typecheck`]: 2,
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/collection-method-value
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When using a Remeda collection method, the expression should be used (e.g. assigning to a variable or check in a condition), unless it's a method meant for side effects (e.g. `forEach` or `forOwn`) which should NOT be used.
|
4
8
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/collection-return
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When using a Remeda collection method that isn't forEach, the iteratee should return a value, otherwise it could result in either unclear code or unexpected results.
|
4
8
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-constant
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When you want a function that always returns the same value, it can be more concise to use `R.constant`.
|
4
8
|
|
@@ -9,6 +13,10 @@ This rule takes two arguments:
|
|
9
13
|
- whether or not to check arrow functions
|
10
14
|
- whether or not to check function declarations (named functions)
|
11
15
|
|
16
|
+
## Options
|
17
|
+
|
18
|
+
## Examples
|
19
|
+
|
12
20
|
The following patterns are considered warnings:
|
13
21
|
|
14
22
|
```js
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-do-nothing
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When defining an empty function (e.g. for callbacks) it can be more readable to use `R.doNothing()` or `R.constant(undefined)` instead. Use `R.doNothing()` if you need to return void, otherwise use `R.constant(undefined)`.
|
4
8
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-filter
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When using R.forEach with a single `if` statement, you should probably use `R.filter` or `R.some` instead.
|
4
8
|
|
@@ -6,6 +10,10 @@ When using R.forEach with a single `if` statement, you should probably use `R.fi
|
|
6
10
|
|
7
11
|
This rule takes one argument, maximum path length (default is 3).
|
8
12
|
|
13
|
+
## Options
|
14
|
+
|
15
|
+
## Examples
|
16
|
+
|
9
17
|
The following patterns are considered warnings:
|
10
18
|
|
11
19
|
```js
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-find
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When using R.filter and accessing the first or last result, you should probably use `R.find` or `R.findLast`, respectively.
|
4
8
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-flat-map
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
<!-- end auto-generated rule header -->
|
2
6
|
|
3
7
|
When using [`R.map`] and [`R.flat`], it can be more concise to use [`R.flatMap`] instead.
|
4
8
|
|
@@ -1,4 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# remeda/prefer-is-empty
|
2
|
+
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
4
|
+
|
5
|
+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
6
|
+
|
7
|
+
<!-- end auto-generated rule header -->
|
2
8
|
|
3
9
|
When checking if a collection is empty or no, it is more concise to use R.isEmpty instead.
|
4
10
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# Prefer R.
|
1
|
+
# Prefer R.isNullish
|
2
2
|
|
3
|
-
When checking that a value is undefined or null (but not false or ''), it is more concise to use R.
|
3
|
+
When checking that a value is undefined or null (but not false or ''), it is more concise to use R.isNullish instead.
|
4
4
|
|
5
5
|
## Rule Details
|
6
6
|
|
@@ -17,11 +17,11 @@ var t = x === undefined || x === null;
|
|
17
17
|
The following patterns are not considered warnings:
|
18
18
|
|
19
19
|
```js
|
20
|
-
var t = R.
|
20
|
+
var t = R.isNullish(x);
|
21
21
|
|
22
22
|
var t = R.isUndefined(x) || R.isNull(y);
|
23
23
|
```
|
24
24
|
|
25
25
|
## When Not To Use It
|
26
26
|
|
27
|
-
If you do not want to enforce using `R.
|
27
|
+
If you do not want to enforce using `R.isNullish`, and prefer using specific checks instead.
|
package/docs/rules/prefer-map.md
CHANGED