eslint-plugin-react-x 1.23.2 → 1.23.3-beta.5
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/dist/index.js +562 -222
- package/dist/index.mjs +565 -225
- package/package.json +14 -10
package/dist/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.23.
|
|
45
|
+
var version = "1.23.3-beta.5";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -132,11 +132,17 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
132
132
|
create(context) {
|
|
133
133
|
return {
|
|
134
134
|
CallExpression(node) {
|
|
135
|
-
if (!core.isForwardRefCall(node, context))
|
|
135
|
+
if (!core.isForwardRefCall(node, context)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
136
138
|
const [component] = node.arguments;
|
|
137
|
-
if (!component || !AST11__namespace.isFunction(component))
|
|
139
|
+
if (!component || !AST11__namespace.isFunction(component)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
138
142
|
const [_, ref] = component.params;
|
|
139
|
-
if (ref)
|
|
143
|
+
if (ref) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
140
146
|
context.report({
|
|
141
147
|
messageId: "ensureForwardRefUsingRef",
|
|
142
148
|
node: component
|
|
@@ -179,17 +185,23 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
179
185
|
},
|
|
180
186
|
name: RULE_NAME4,
|
|
181
187
|
create(context) {
|
|
182
|
-
if (!context.sourceCode.text.includes("setState"))
|
|
188
|
+
if (!context.sourceCode.text.includes("setState")) {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
183
191
|
const classStack = [];
|
|
184
192
|
const methodStack = [];
|
|
185
193
|
const setStateStack = [];
|
|
186
194
|
return {
|
|
187
195
|
CallExpression(node) {
|
|
188
|
-
if (!core.isThisSetState(node))
|
|
196
|
+
if (!core.isThisSetState(node)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
189
199
|
setStateStack.push([node, false]);
|
|
190
200
|
},
|
|
191
201
|
"CallExpression:exit"(node) {
|
|
192
|
-
if (!core.isThisSetState(node))
|
|
202
|
+
if (!core.isThisSetState(node)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
193
205
|
setStateStack.pop();
|
|
194
206
|
},
|
|
195
207
|
ClassDeclaration(node) {
|
|
@@ -205,14 +217,24 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
205
217
|
classStack.pop();
|
|
206
218
|
},
|
|
207
219
|
MemberExpression(node) {
|
|
208
|
-
if (!AST11__namespace.isThisExpression(node.object))
|
|
220
|
+
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
209
223
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
210
|
-
if (!currClass || !isComponent)
|
|
224
|
+
if (!currClass || !isComponent) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
211
227
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
212
|
-
if (!currMethod || isStatic)
|
|
228
|
+
if (!currMethod || isStatic) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
213
231
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
214
|
-
if (!setState || hasThisState)
|
|
215
|
-
|
|
232
|
+
if (!setState || hasThisState) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (!eff.O.exists(getName(node.property), (name2) => name2 === "state")) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
216
238
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
217
239
|
},
|
|
218
240
|
MethodDefinition(node) {
|
|
@@ -229,19 +251,29 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
229
251
|
},
|
|
230
252
|
VariableDeclarator(node) {
|
|
231
253
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
232
|
-
if (!currClass || !isComponent)
|
|
254
|
+
if (!currClass || !isComponent) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
233
257
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
234
|
-
if (!currMethod || isStatic)
|
|
258
|
+
if (!currMethod || isStatic) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
235
261
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
236
|
-
if (!setState || hasThisState)
|
|
237
|
-
|
|
262
|
+
if (!setState || hasThisState) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (!(node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
238
268
|
const hasState = node.id.properties.some((prop) => {
|
|
239
269
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
240
270
|
return eff.O.exists(getName(prop.key), (name2) => name2 === "state");
|
|
241
271
|
}
|
|
242
272
|
return false;
|
|
243
273
|
});
|
|
244
|
-
if (!hasState)
|
|
274
|
+
if (!hasState) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
245
277
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
246
278
|
}
|
|
247
279
|
};
|
|
@@ -267,16 +299,6 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
267
299
|
["reduceRight", 2],
|
|
268
300
|
["some", 1]
|
|
269
301
|
]);
|
|
270
|
-
var isToStringCall = tsPattern.isMatching({
|
|
271
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
272
|
-
callee: {
|
|
273
|
-
type: types.AST_NODE_TYPES.MemberExpression,
|
|
274
|
-
property: {
|
|
275
|
-
type: types.AST_NODE_TYPES.Identifier,
|
|
276
|
-
name: "toString"
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
302
|
function isReactChildrenMethod(name2) {
|
|
281
303
|
return reactChildrenMethod.some((method) => method === name2);
|
|
282
304
|
}
|
|
@@ -286,9 +308,13 @@ function isUsingReactChildren(node, context) {
|
|
|
286
308
|
if (!("property" in callee) || !("object" in callee) || !("name" in callee.property)) {
|
|
287
309
|
return false;
|
|
288
310
|
}
|
|
289
|
-
if (!isReactChildrenMethod(callee.property.name))
|
|
311
|
+
if (!isReactChildrenMethod(callee.property.name)) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
290
314
|
const initialScope = context.sourceCode.getScope(node);
|
|
291
|
-
if (callee.object.type === types.AST_NODE_TYPES.Identifier && callee.object.name === "Children")
|
|
315
|
+
if (callee.object.type === types.AST_NODE_TYPES.Identifier && callee.object.name === "Children") {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
292
318
|
if (callee.object.type === types.AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
293
319
|
return core.isInitializedFromReact(callee.object.object.name, initialScope, settings.importSource);
|
|
294
320
|
}
|
|
@@ -296,19 +322,31 @@ function isUsingReactChildren(node, context) {
|
|
|
296
322
|
}
|
|
297
323
|
function getMapIndexParamName(node, context) {
|
|
298
324
|
const { callee } = node;
|
|
299
|
-
if (callee.type !== types.AST_NODE_TYPES.MemberExpression)
|
|
300
|
-
|
|
325
|
+
if (callee.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
326
|
+
return eff.O.none();
|
|
327
|
+
}
|
|
328
|
+
if (callee.property.type !== types.AST_NODE_TYPES.Identifier) {
|
|
329
|
+
return eff.O.none();
|
|
330
|
+
}
|
|
301
331
|
const { name: name2 } = callee.property;
|
|
302
|
-
if (!iteratorFunctionIndexParamPosition.has(name2))
|
|
332
|
+
if (!iteratorFunctionIndexParamPosition.has(name2)) {
|
|
333
|
+
return eff.O.none();
|
|
334
|
+
}
|
|
303
335
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
304
|
-
if (!callbackArg)
|
|
336
|
+
if (!callbackArg) {
|
|
337
|
+
return eff.O.none();
|
|
338
|
+
}
|
|
305
339
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
306
340
|
return eff.O.none();
|
|
307
341
|
}
|
|
308
342
|
const { params } = callbackArg;
|
|
309
343
|
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
|
|
310
|
-
if (eff.isNullable(indexParamPosition))
|
|
311
|
-
|
|
344
|
+
if (eff.isNullable(indexParamPosition)) {
|
|
345
|
+
return eff.O.none();
|
|
346
|
+
}
|
|
347
|
+
if (params.length < indexParamPosition + 1) {
|
|
348
|
+
return eff.O.none();
|
|
349
|
+
}
|
|
312
350
|
const param = params.at(indexParamPosition);
|
|
313
351
|
return param && "name" in param ? eff.O.some(param.name) : eff.O.none();
|
|
314
352
|
}
|
|
@@ -327,47 +365,82 @@ var no_array_index_key_default = createRule({
|
|
|
327
365
|
name: RULE_NAME5,
|
|
328
366
|
create(context) {
|
|
329
367
|
const indexParamNames = [];
|
|
330
|
-
const isCreateOrCloneElementCall = eff.or(core.isCreateElementCall(context), core.isCloneElementCall(context));
|
|
331
368
|
function isArrayIndex(node) {
|
|
332
369
|
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(eff.O.exists((name2) => name2 === node.name));
|
|
333
370
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
371
|
+
function isCreateOrCloneElementCall(node) {
|
|
372
|
+
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
373
|
+
}
|
|
374
|
+
function getReportDescriptors(node) {
|
|
375
|
+
switch (node.type) {
|
|
376
|
+
// key={bar}
|
|
377
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
378
|
+
if (indexParamNames.some(eff.O.exists((name2) => name2 === node.name))) {
|
|
379
|
+
return [{
|
|
380
|
+
messageId: "noArrayIndexKey",
|
|
381
|
+
node
|
|
382
|
+
}];
|
|
383
|
+
}
|
|
384
|
+
return [];
|
|
385
|
+
}
|
|
386
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
387
|
+
case types.AST_NODE_TYPES.TemplateLiteral:
|
|
388
|
+
case types.AST_NODE_TYPES.BinaryExpression: {
|
|
389
|
+
const descriptors = [];
|
|
390
|
+
const expressions = node.type === types.AST_NODE_TYPES.TemplateLiteral ? node.expressions : AST11__namespace.getIdentifiersFromBinaryExpression(node);
|
|
391
|
+
for (const expression of expressions) {
|
|
392
|
+
if (isArrayIndex(expression)) {
|
|
393
|
+
descriptors.push({
|
|
394
|
+
messageId: "noArrayIndexKey",
|
|
395
|
+
node: expression
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return descriptors;
|
|
400
|
+
}
|
|
401
|
+
// key={bar.toString()} or key={String(bar)}
|
|
402
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
403
|
+
switch (true) {
|
|
404
|
+
// key={bar.toString()}
|
|
405
|
+
case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object)): {
|
|
406
|
+
return [{
|
|
407
|
+
messageId: "noArrayIndexKey",
|
|
408
|
+
node: node.callee.object
|
|
409
|
+
}];
|
|
410
|
+
}
|
|
411
|
+
// key={String(bar)}
|
|
412
|
+
case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] && isArrayIndex(node.arguments[0])): {
|
|
413
|
+
return [{
|
|
414
|
+
messageId: "noArrayIndexKey",
|
|
415
|
+
node: node.arguments[0]
|
|
416
|
+
}];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
352
419
|
}
|
|
353
|
-
}, node);
|
|
354
|
-
if (isStringCall) {
|
|
355
|
-
const [arg] = node.arguments;
|
|
356
|
-
if (arg && isArrayIndex(arg)) return [{ messageId: "noArrayIndexKey", node: arg }];
|
|
357
420
|
}
|
|
358
421
|
return [];
|
|
359
422
|
}
|
|
360
423
|
return {
|
|
361
424
|
CallExpression(node) {
|
|
362
425
|
indexParamNames.push(getMapIndexParamName(node, context));
|
|
363
|
-
if (node.arguments.length === 0)
|
|
364
|
-
|
|
426
|
+
if (node.arguments.length === 0) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (!isCreateOrCloneElementCall(node)) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
365
432
|
const [_, props] = node.arguments;
|
|
366
|
-
if (props?.type !== types.AST_NODE_TYPES.ObjectExpression)
|
|
433
|
+
if (props?.type !== types.AST_NODE_TYPES.ObjectExpression) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
367
436
|
for (const prop of props.properties) {
|
|
368
|
-
if (!tsPattern.isMatching({ key: { name: "key" } })(prop))
|
|
369
|
-
|
|
370
|
-
|
|
437
|
+
if (!tsPattern.isMatching({ key: { name: "key" } })(prop)) {
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (!("value" in prop)) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
371
444
|
for (const descriptor of descriptors) {
|
|
372
445
|
context.report(descriptor);
|
|
373
446
|
}
|
|
@@ -377,11 +450,16 @@ var no_array_index_key_default = createRule({
|
|
|
377
450
|
indexParamNames.pop();
|
|
378
451
|
},
|
|
379
452
|
JSXAttribute(node) {
|
|
380
|
-
if (node.name.name !== "key")
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (
|
|
384
|
-
|
|
453
|
+
if (node.name.name !== "key") {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (indexParamNames.length === 0) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (node.value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
385
463
|
for (const descriptor of descriptors) {
|
|
386
464
|
context.report(descriptor);
|
|
387
465
|
}
|
|
@@ -578,22 +656,12 @@ var RULE_NAME12 = "no-class-component";
|
|
|
578
656
|
var RULE_FEATURES12 = [
|
|
579
657
|
"CHK"
|
|
580
658
|
];
|
|
581
|
-
|
|
582
|
-
key
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
static: false
|
|
588
|
-
});
|
|
589
|
-
var isGetDerivedStateFromError = tsPattern.isMatching({
|
|
590
|
-
key: {
|
|
591
|
-
type: types.AST_NODE_TYPES.Identifier,
|
|
592
|
-
name: "getDerivedStateFromError"
|
|
593
|
-
},
|
|
594
|
-
type: tsPattern.P.union(types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition),
|
|
595
|
-
static: true
|
|
596
|
-
});
|
|
659
|
+
function isComponentDidCatch(node) {
|
|
660
|
+
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
661
|
+
}
|
|
662
|
+
function isGetDerivedStateFromError(node) {
|
|
663
|
+
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
664
|
+
}
|
|
597
665
|
var no_class_component_default = createRule({
|
|
598
666
|
meta: {
|
|
599
667
|
type: "problem",
|
|
@@ -608,14 +676,18 @@ var no_class_component_default = createRule({
|
|
|
608
676
|
},
|
|
609
677
|
name: RULE_NAME12,
|
|
610
678
|
create(context) {
|
|
611
|
-
if (!context.sourceCode.text.includes("Component"))
|
|
679
|
+
if (!context.sourceCode.text.includes("Component")) {
|
|
680
|
+
return {};
|
|
681
|
+
}
|
|
612
682
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
613
683
|
return {
|
|
614
684
|
...listeners,
|
|
615
685
|
"Program:exit"(node) {
|
|
616
686
|
const components = ctx.getAllComponents(node);
|
|
617
687
|
for (const { name: name2, node: component } of components.values()) {
|
|
618
|
-
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m)))
|
|
688
|
+
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
619
691
|
context.report({
|
|
620
692
|
messageId: "noClassComponent",
|
|
621
693
|
node: component,
|
|
@@ -650,7 +722,9 @@ var no_clone_element_default = createRule({
|
|
|
650
722
|
create(context) {
|
|
651
723
|
return {
|
|
652
724
|
CallExpression(node) {
|
|
653
|
-
if (!core.isCloneElementCall(node, context))
|
|
725
|
+
if (!core.isCloneElementCall(node, context)) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
654
728
|
context.report({
|
|
655
729
|
messageId: "noCloneElement",
|
|
656
730
|
node
|
|
@@ -679,14 +753,22 @@ var no_comment_textnodes_default = createRule({
|
|
|
679
753
|
name: RULE_NAME14,
|
|
680
754
|
create(context) {
|
|
681
755
|
function hasCommentLike(node) {
|
|
682
|
-
if (AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXAttribute, types.AST_NODE_TYPES.JSXExpressionContainer])(node.parent))
|
|
756
|
+
if (AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXAttribute, types.AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
683
759
|
const rawValue = context.sourceCode.getText(node);
|
|
684
760
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
685
761
|
}
|
|
686
762
|
const getReportDescriptor = (node) => {
|
|
687
|
-
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent))
|
|
688
|
-
|
|
689
|
-
|
|
763
|
+
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
764
|
+
return eff.O.none();
|
|
765
|
+
}
|
|
766
|
+
if (!hasCommentLike(node)) {
|
|
767
|
+
return eff.O.none();
|
|
768
|
+
}
|
|
769
|
+
if (!node.parent.type.includes("JSX")) {
|
|
770
|
+
return eff.O.none();
|
|
771
|
+
}
|
|
690
772
|
return eff.O.some({
|
|
691
773
|
messageId: "noCommentTextnodes",
|
|
692
774
|
node
|
|
@@ -720,11 +802,15 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
720
802
|
create(context) {
|
|
721
803
|
function getReportDescriptor(node) {
|
|
722
804
|
const jsxExpContainer = node.parent?.parent;
|
|
723
|
-
if (!AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer))
|
|
805
|
+
if (!AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
806
|
+
return eff.O.none();
|
|
807
|
+
}
|
|
724
808
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
725
809
|
return eff.O.none();
|
|
726
810
|
}
|
|
727
|
-
if (!jsxExpContainer.parent.children.includes(jsxExpContainer))
|
|
811
|
+
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
812
|
+
return eff.O.none();
|
|
813
|
+
}
|
|
728
814
|
return eff.O.some({ messageId: "noComplexConditionalRendering", node: jsxExpContainer });
|
|
729
815
|
}
|
|
730
816
|
const visitorFunction = eff.F.flow(getReportDescriptor, eff.O.map(context.report), eff.F.constVoid);
|
|
@@ -761,7 +847,9 @@ var no_component_will_mount_default = createRule({
|
|
|
761
847
|
},
|
|
762
848
|
name: RULE_NAME16,
|
|
763
849
|
create(context) {
|
|
764
|
-
if (!context.sourceCode.text.includes("componentWillMount"))
|
|
850
|
+
if (!context.sourceCode.text.includes("componentWillMount")) {
|
|
851
|
+
return {};
|
|
852
|
+
}
|
|
765
853
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
766
854
|
return {
|
|
767
855
|
...listeners,
|
|
@@ -775,7 +863,9 @@ var no_component_will_mount_default = createRule({
|
|
|
775
863
|
messageId: "noComponentWillMount",
|
|
776
864
|
node: member,
|
|
777
865
|
fix(fixer) {
|
|
778
|
-
if (!("key" in member))
|
|
866
|
+
if (!("key" in member)) {
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
779
869
|
return fixer.replaceText(member.key, "UNSAFE_componentWillMount");
|
|
780
870
|
}
|
|
781
871
|
});
|
|
@@ -810,7 +900,9 @@ var no_component_will_receive_props_default = createRule({
|
|
|
810
900
|
},
|
|
811
901
|
name: RULE_NAME17,
|
|
812
902
|
create(context) {
|
|
813
|
-
if (!context.sourceCode.text.includes("componentWillReceiveProps"))
|
|
903
|
+
if (!context.sourceCode.text.includes("componentWillReceiveProps")) {
|
|
904
|
+
return {};
|
|
905
|
+
}
|
|
814
906
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
815
907
|
return {
|
|
816
908
|
...listeners,
|
|
@@ -824,7 +916,9 @@ var no_component_will_receive_props_default = createRule({
|
|
|
824
916
|
messageId: "noComponentWillReceiveProps",
|
|
825
917
|
node: member,
|
|
826
918
|
fix(fixer) {
|
|
827
|
-
if (!("key" in member))
|
|
919
|
+
if (!("key" in member)) {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
828
922
|
return fixer.replaceText(member.key, "UNSAFE_componentWillReceiveProps");
|
|
829
923
|
}
|
|
830
924
|
});
|
|
@@ -859,7 +953,9 @@ var no_component_will_update_default = createRule({
|
|
|
859
953
|
},
|
|
860
954
|
name: RULE_NAME18,
|
|
861
955
|
create(context) {
|
|
862
|
-
if (!context.sourceCode.text.includes("componentWillUpdate"))
|
|
956
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
957
|
+
return {};
|
|
958
|
+
}
|
|
863
959
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
864
960
|
return {
|
|
865
961
|
...listeners,
|
|
@@ -873,7 +969,9 @@ var no_component_will_update_default = createRule({
|
|
|
873
969
|
messageId: "noComponentWillUpdate",
|
|
874
970
|
node: member,
|
|
875
971
|
fix(fixer) {
|
|
876
|
-
if (!("key" in member))
|
|
972
|
+
if (!("key" in member)) {
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
877
975
|
return fixer.replaceText(member.key, "UNSAFE_componentWillUpdate");
|
|
878
976
|
}
|
|
879
977
|
});
|
|
@@ -905,13 +1003,19 @@ var no_context_provider_default = createRule({
|
|
|
905
1003
|
},
|
|
906
1004
|
name: RULE_NAME19,
|
|
907
1005
|
create(context) {
|
|
908
|
-
if (!context.sourceCode.text.includes(".Provider"))
|
|
1006
|
+
if (!context.sourceCode.text.includes(".Provider")) {
|
|
1007
|
+
return {};
|
|
1008
|
+
}
|
|
909
1009
|
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
910
|
-
if (compareVersions.compare(version2, "19.0.0", "<"))
|
|
1010
|
+
if (compareVersions.compare(version2, "19.0.0", "<")) {
|
|
1011
|
+
return {};
|
|
1012
|
+
}
|
|
911
1013
|
return {
|
|
912
1014
|
JSXElement(node) {
|
|
913
1015
|
const elementName = JSX7__namespace.getElementName(node.openingElement);
|
|
914
|
-
if (!elementName.endsWith(".Provider"))
|
|
1016
|
+
if (!elementName.endsWith(".Provider")) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
915
1019
|
context.report({
|
|
916
1020
|
messageId: "noContextProvider",
|
|
917
1021
|
node,
|
|
@@ -919,7 +1023,9 @@ var no_context_provider_default = createRule({
|
|
|
919
1023
|
const providerName = elementName.replace(/\.Provider$/, "");
|
|
920
1024
|
const openingElement = node.openingElement;
|
|
921
1025
|
const closingElement = node.closingElement;
|
|
922
|
-
if (!closingElement)
|
|
1026
|
+
if (!closingElement) {
|
|
1027
|
+
return fixer.replaceText(openingElement.name, providerName);
|
|
1028
|
+
}
|
|
923
1029
|
return [
|
|
924
1030
|
fixer.replaceText(openingElement.name, providerName),
|
|
925
1031
|
fixer.replaceText(closingElement.name, providerName)
|
|
@@ -951,8 +1057,12 @@ var no_create_ref_default = createRule({
|
|
|
951
1057
|
create(context) {
|
|
952
1058
|
return {
|
|
953
1059
|
CallExpression(node) {
|
|
954
|
-
if (!core.isCreateRefCall(node, context))
|
|
955
|
-
|
|
1060
|
+
if (!core.isCreateRefCall(node, context)) {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (eff.O.isSome(AST11__namespace.findParentNode(node, core.isClassComponent))) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
956
1066
|
context.report({ messageId: "noCreateRef", node });
|
|
957
1067
|
}
|
|
958
1068
|
};
|
|
@@ -977,25 +1087,41 @@ var no_default_props_default = createRule({
|
|
|
977
1087
|
},
|
|
978
1088
|
name: RULE_NAME21,
|
|
979
1089
|
create(context) {
|
|
980
|
-
if (!context.sourceCode.text.includes("defaultProps"))
|
|
1090
|
+
if (!context.sourceCode.text.includes("defaultProps")) {
|
|
1091
|
+
return {};
|
|
1092
|
+
}
|
|
981
1093
|
return {
|
|
982
1094
|
AssignmentExpression(node) {
|
|
983
|
-
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression)
|
|
1095
|
+
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
984
1098
|
const { object, property } = node.left;
|
|
985
|
-
if (object.type !== types.AST_NODE_TYPES.Identifier)
|
|
986
|
-
|
|
987
|
-
|
|
1099
|
+
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (!core.isComponentName(object.name)) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
988
1108
|
const isComponent = eff.F.pipe(
|
|
989
1109
|
VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node)),
|
|
990
1110
|
eff.O.flatMap(VAR__namespace.getVariableNode(0)),
|
|
991
1111
|
eff.O.exists((n) => AST11__namespace.isFunction(n) || core.isClassComponent(n))
|
|
992
1112
|
);
|
|
993
|
-
if (!isComponent)
|
|
1113
|
+
if (!isComponent) {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
994
1116
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
995
1117
|
},
|
|
996
1118
|
PropertyDefinition(node) {
|
|
997
|
-
if (!core.isClassComponent(node.parent.parent))
|
|
998
|
-
|
|
1119
|
+
if (!core.isClassComponent(node.parent.parent)) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
999
1125
|
context.report({ messageId: "noDefaultProps", node });
|
|
1000
1126
|
}
|
|
1001
1127
|
};
|
|
@@ -1043,7 +1169,9 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1043
1169
|
name: RULE_NAME22,
|
|
1044
1170
|
create(context) {
|
|
1045
1171
|
function getReportDescriptor(node) {
|
|
1046
|
-
if (!isAssignmentToThisState(node))
|
|
1172
|
+
if (!isAssignmentToThisState(node)) {
|
|
1173
|
+
return eff.O.none();
|
|
1174
|
+
}
|
|
1047
1175
|
return eff.F.pipe(
|
|
1048
1176
|
eff.O.Do,
|
|
1049
1177
|
eff.O.bind("parentClass", () => AST11__namespace.findParentNodeGuard(
|
|
@@ -1091,9 +1219,13 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1091
1219
|
JSXOpeningElement(node) {
|
|
1092
1220
|
const props = [];
|
|
1093
1221
|
for (const attr of node.attributes) {
|
|
1094
|
-
if (attr.type === types.AST_NODE_TYPES.JSXSpreadAttribute)
|
|
1222
|
+
if (attr.type === types.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1095
1225
|
const name2 = attr.name.name;
|
|
1096
|
-
if (!eff.isString(name2))
|
|
1226
|
+
if (!eff.isString(name2)) {
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1097
1229
|
if (!props.includes(name2)) {
|
|
1098
1230
|
props.push(name2);
|
|
1099
1231
|
continue;
|
|
@@ -1126,12 +1258,16 @@ var no_duplicate_key_default = createRule({
|
|
|
1126
1258
|
},
|
|
1127
1259
|
name: RULE_NAME24,
|
|
1128
1260
|
create(context) {
|
|
1129
|
-
if (!context.sourceCode.getText().includes("key="))
|
|
1261
|
+
if (!context.sourceCode.getText().includes("key=")) {
|
|
1262
|
+
return {};
|
|
1263
|
+
}
|
|
1130
1264
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1131
1265
|
function isKeyValueEqual(a, b) {
|
|
1132
1266
|
const aValue = a.value;
|
|
1133
1267
|
const bValue = b.value;
|
|
1134
|
-
if (aValue === null || bValue === null)
|
|
1268
|
+
if (aValue === null || bValue === null) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1135
1271
|
return AST11__namespace.isNodeEqual(aValue, bValue);
|
|
1136
1272
|
}
|
|
1137
1273
|
return {
|
|
@@ -1157,9 +1293,13 @@ var no_duplicate_key_default = createRule({
|
|
|
1157
1293
|
eff.O.bind("iter", ({ call: call2 }) => AST11__namespace.findParentNodeStop(jsxElement, call2, AST11__namespace.isFunction)),
|
|
1158
1294
|
eff.O.bind("arg0", ({ call: call2 }) => eff.O.fromNullable(call2.arguments[0]))
|
|
1159
1295
|
);
|
|
1160
|
-
if (eff.O.isNone(mbEntry))
|
|
1296
|
+
if (eff.O.isNone(mbEntry)) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1161
1299
|
const { arg0, call, iter } = mbEntry.value;
|
|
1162
|
-
if (AST11__namespace.unwrapTypeExpression(arg0) !== iter)
|
|
1300
|
+
if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1163
1303
|
keyedEntries.set(call, {
|
|
1164
1304
|
hasDuplicate: node.value?.type === types.AST_NODE_TYPES.Literal,
|
|
1165
1305
|
keys: [node],
|
|
@@ -1170,7 +1310,9 @@ var no_duplicate_key_default = createRule({
|
|
|
1170
1310
|
},
|
|
1171
1311
|
"Program:exit"() {
|
|
1172
1312
|
for (const { hasDuplicate, keys } of keyedEntries.values()) {
|
|
1173
|
-
if (!hasDuplicate)
|
|
1313
|
+
if (!hasDuplicate) {
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1174
1316
|
for (const key of keys) {
|
|
1175
1317
|
context.report({
|
|
1176
1318
|
messageId: "noDuplicateKey",
|
|
@@ -1206,12 +1348,18 @@ var no_forward_ref_default = createRule({
|
|
|
1206
1348
|
},
|
|
1207
1349
|
name: RULE_NAME25,
|
|
1208
1350
|
create(context) {
|
|
1209
|
-
if (!context.sourceCode.text.includes("forwardRef"))
|
|
1351
|
+
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1352
|
+
return {};
|
|
1353
|
+
}
|
|
1210
1354
|
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1211
|
-
if (compareVersions.compare(version2, "19.0.0", "<"))
|
|
1355
|
+
if (compareVersions.compare(version2, "19.0.0", "<")) {
|
|
1356
|
+
return {};
|
|
1357
|
+
}
|
|
1212
1358
|
return {
|
|
1213
1359
|
CallExpression(node) {
|
|
1214
|
-
if (!core.isForwardRefCall(node, context))
|
|
1360
|
+
if (!core.isForwardRefCall(node, context)) {
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1215
1363
|
context.report({
|
|
1216
1364
|
messageId: "noForwardRef",
|
|
1217
1365
|
node,
|
|
@@ -1225,7 +1373,9 @@ var no_forward_ref_default = createRule({
|
|
|
1225
1373
|
function getFix(node, context) {
|
|
1226
1374
|
return (fixer) => {
|
|
1227
1375
|
const [componentNode] = node.arguments;
|
|
1228
|
-
if (!componentNode || !AST11__namespace.isFunction(componentNode))
|
|
1376
|
+
if (!componentNode || !AST11__namespace.isFunction(componentNode)) {
|
|
1377
|
+
return [];
|
|
1378
|
+
}
|
|
1229
1379
|
return [
|
|
1230
1380
|
// unwrap component from forwardRef call
|
|
1231
1381
|
fixer.removeRange([node.range[0], componentNode.range[0]]),
|
|
@@ -1244,10 +1394,14 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1244
1394
|
const getText = (node2) => context.sourceCode.getText(node2);
|
|
1245
1395
|
const [arg0, arg1] = node.params;
|
|
1246
1396
|
const [typeArg0, typeArg1] = typeArguments;
|
|
1247
|
-
if (!arg0)
|
|
1397
|
+
if (!arg0) {
|
|
1398
|
+
return [];
|
|
1399
|
+
}
|
|
1248
1400
|
const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => eff.O.some(`...${n.name}`)).with({ type: types.AST_NODE_TYPES.ObjectPattern }, (n) => eff.O.some(n.properties.map(getText).join(", "))).otherwise(eff.O.none);
|
|
1249
1401
|
const fixedArg1Text = tsPattern.match(arg1).with(tsPattern.P.nullish, () => eff.O.some("ref")).with({ type: types.AST_NODE_TYPES.Identifier, name: "ref" }, () => eff.O.some("ref")).with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.not("ref") }, (n) => eff.O.some(`ref: ${n.name}`)).otherwise(eff.O.none);
|
|
1250
|
-
if (eff.O.isNone(fixedArg0Text) || eff.O.isNone(fixedArg1Text))
|
|
1402
|
+
if (eff.O.isNone(fixedArg0Text) || eff.O.isNone(fixedArg1Text)) {
|
|
1403
|
+
return [];
|
|
1404
|
+
}
|
|
1251
1405
|
const fixedPropsText = fixedArg0Text.value;
|
|
1252
1406
|
const fixedRefText = fixedArg1Text.value;
|
|
1253
1407
|
if (!typeArg0 || !typeArg1) {
|
|
@@ -1427,7 +1581,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1427
1581
|
},
|
|
1428
1582
|
name: RULE_NAME27,
|
|
1429
1583
|
create(context) {
|
|
1430
|
-
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?"))
|
|
1584
|
+
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) {
|
|
1585
|
+
return {};
|
|
1586
|
+
}
|
|
1431
1587
|
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1432
1588
|
const allowedVariants = [
|
|
1433
1589
|
"any",
|
|
@@ -1445,7 +1601,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1445
1601
|
function getReportDescriptor(node) {
|
|
1446
1602
|
return tsPattern.match(node).when(AST11__namespace.isJSX, eff.O.none).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1447
1603
|
const isLeftUnaryNot = tsPattern.isMatching({ type: types.AST_NODE_TYPES.UnaryExpression, operator: "!" }, left);
|
|
1448
|
-
if (isLeftUnaryNot)
|
|
1604
|
+
if (isLeftUnaryNot) {
|
|
1605
|
+
return getReportDescriptor(right);
|
|
1606
|
+
}
|
|
1449
1607
|
const initialScope = context.sourceCode.getScope(left);
|
|
1450
1608
|
const isLeftNan = tsPattern.isMatching({ type: types.AST_NODE_TYPES.Identifier, name: "NaN" }, left) || eff.O.exists(VAR__namespace.getStaticValue(left, initialScope), (v) => v === "NaN");
|
|
1451
1609
|
if (isLeftNan) {
|
|
@@ -1458,7 +1616,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1458
1616
|
const leftType = typeUtils.getConstrainedTypeAtLocation(services, left);
|
|
1459
1617
|
const leftTypeVariants = inspectVariantTypes(tsApiUtils.unionTypeParts(leftType));
|
|
1460
1618
|
const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
|
|
1461
|
-
if (isLeftValid)
|
|
1619
|
+
if (isLeftValid) {
|
|
1620
|
+
return getReportDescriptor(right);
|
|
1621
|
+
}
|
|
1462
1622
|
return eff.O.some({
|
|
1463
1623
|
messageId: "noLeakedConditionalRendering",
|
|
1464
1624
|
node: left,
|
|
@@ -1500,7 +1660,9 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1500
1660
|
},
|
|
1501
1661
|
name: RULE_NAME28,
|
|
1502
1662
|
create(context) {
|
|
1503
|
-
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef"))
|
|
1663
|
+
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1664
|
+
return {};
|
|
1665
|
+
}
|
|
1504
1666
|
const { ctx, listeners } = core.useComponentCollector(context);
|
|
1505
1667
|
return {
|
|
1506
1668
|
...listeners,
|
|
@@ -1508,8 +1670,12 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1508
1670
|
const components = ctx.getAllComponents(node);
|
|
1509
1671
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1510
1672
|
const isMemoOrForwardRef = Boolean(flag & core.ERFunctionComponentFlag.ForwardRef) || Boolean(flag & core.ERFunctionComponentFlag.Memo);
|
|
1511
|
-
if (eff.O.isSome(AST11__namespace.getFunctionIdentifier(node2)))
|
|
1512
|
-
|
|
1673
|
+
if (eff.O.isSome(AST11__namespace.getFunctionIdentifier(node2))) {
|
|
1674
|
+
continue;
|
|
1675
|
+
}
|
|
1676
|
+
if (!isMemoOrForwardRef) {
|
|
1677
|
+
continue;
|
|
1678
|
+
}
|
|
1513
1679
|
if (eff.O.isNone(displayName)) {
|
|
1514
1680
|
context.report({
|
|
1515
1681
|
messageId: "noMissingComponentDisplayName",
|
|
@@ -1567,13 +1733,17 @@ var no_missing_key_default = createRule({
|
|
|
1567
1733
|
function checkExpression(node) {
|
|
1568
1734
|
switch (node.type) {
|
|
1569
1735
|
case types.AST_NODE_TYPES.ConditionalExpression:
|
|
1570
|
-
if (!("consequent" in node))
|
|
1736
|
+
if (!("consequent" in node)) {
|
|
1737
|
+
return eff.O.none();
|
|
1738
|
+
}
|
|
1571
1739
|
return eff.O.orElse(checkIteratorElement(node.consequent), () => checkIteratorElement(node.alternate));
|
|
1572
1740
|
case types.AST_NODE_TYPES.JSXElement:
|
|
1573
1741
|
case types.AST_NODE_TYPES.JSXFragment:
|
|
1574
1742
|
return checkIteratorElement(node);
|
|
1575
1743
|
case types.AST_NODE_TYPES.LogicalExpression:
|
|
1576
|
-
if (!("left" in node))
|
|
1744
|
+
if (!("left" in node)) {
|
|
1745
|
+
return eff.O.none();
|
|
1746
|
+
}
|
|
1577
1747
|
return eff.O.orElse(checkIteratorElement(node.left), () => checkIteratorElement(node.right));
|
|
1578
1748
|
default:
|
|
1579
1749
|
return eff.O.none();
|
|
@@ -1581,16 +1751,22 @@ var no_missing_key_default = createRule({
|
|
|
1581
1751
|
}
|
|
1582
1752
|
function checkBlockStatement(node) {
|
|
1583
1753
|
return AST11__namespace.getNestedReturnStatements(node).reduce((acc, statement) => {
|
|
1584
|
-
if (!statement.argument)
|
|
1754
|
+
if (!statement.argument) {
|
|
1755
|
+
return acc;
|
|
1756
|
+
}
|
|
1585
1757
|
const mbDescriptor = checkIteratorElement(statement.argument);
|
|
1586
1758
|
return eff.O.isNone(mbDescriptor) ? acc : [...acc, mbDescriptor.value];
|
|
1587
1759
|
}, []);
|
|
1588
1760
|
}
|
|
1589
1761
|
return {
|
|
1590
1762
|
ArrayExpression(node) {
|
|
1591
|
-
if (state.isWithinChildrenToArray)
|
|
1763
|
+
if (state.isWithinChildrenToArray) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1592
1766
|
const elements = node.elements.filter(AST11__namespace.is(types.AST_NODE_TYPES.JSXElement));
|
|
1593
|
-
if (elements.length === 0)
|
|
1767
|
+
if (elements.length === 0) {
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1594
1770
|
const initialScope = context.sourceCode.getScope(node);
|
|
1595
1771
|
for (const element of elements) {
|
|
1596
1772
|
if (!JSX7__namespace.hasProp(element.openingElement.attributes, "key", initialScope)) {
|
|
@@ -1603,7 +1779,9 @@ var no_missing_key_default = createRule({
|
|
|
1603
1779
|
},
|
|
1604
1780
|
CallExpression(node) {
|
|
1605
1781
|
state.isWithinChildrenToArray ||= core.isChildrenToArrayCall(node, context);
|
|
1606
|
-
if (state.isWithinChildrenToArray)
|
|
1782
|
+
if (state.isWithinChildrenToArray) {
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1607
1785
|
const isMapCall = AST11__namespace.isMapCallLoose(node);
|
|
1608
1786
|
const isArrayFromCall = tsPattern.isMatching({
|
|
1609
1787
|
type: types.AST_NODE_TYPES.CallExpression,
|
|
@@ -1614,9 +1792,13 @@ var no_missing_key_default = createRule({
|
|
|
1614
1792
|
}
|
|
1615
1793
|
}
|
|
1616
1794
|
}, node);
|
|
1617
|
-
if (!isMapCall && !isArrayFromCall)
|
|
1795
|
+
if (!isMapCall && !isArrayFromCall) {
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1618
1798
|
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1619
|
-
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(fn))
|
|
1799
|
+
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(fn)) {
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1620
1802
|
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
1621
1803
|
for (const descriptor of checkBlockStatement(fn.body)) {
|
|
1622
1804
|
context.report(descriptor);
|
|
@@ -1626,11 +1808,15 @@ var no_missing_key_default = createRule({
|
|
|
1626
1808
|
eff.O.map(checkExpression(fn.body), context.report);
|
|
1627
1809
|
},
|
|
1628
1810
|
"CallExpression:exit"(node) {
|
|
1629
|
-
if (!core.isChildrenToArrayCall(node, context))
|
|
1811
|
+
if (!core.isChildrenToArrayCall(node, context)) {
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1630
1814
|
state.isWithinChildrenToArray = false;
|
|
1631
1815
|
},
|
|
1632
1816
|
JSXFragment(node) {
|
|
1633
|
-
if (state.isWithinChildrenToArray)
|
|
1817
|
+
if (state.isWithinChildrenToArray) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1634
1820
|
if (node.parent.type === types.AST_NODE_TYPES.ArrayExpression) {
|
|
1635
1821
|
context.report({
|
|
1636
1822
|
messageId: "noMissingKeyWithFragment",
|
|
@@ -1661,7 +1847,7 @@ var no_nested_components_default = createRule({
|
|
|
1661
1847
|
},
|
|
1662
1848
|
name: RULE_NAME30,
|
|
1663
1849
|
create(context) {
|
|
1664
|
-
const hint = core.ERComponentHint.SkipMapCallback | core.ERComponentHint.SkipNullLiteral | core.ERComponentHint.
|
|
1850
|
+
const hint = core.ERComponentHint.SkipMapCallback | core.ERComponentHint.SkipNullLiteral | core.ERComponentHint.SkipUndefined | core.ERComponentHint.SkipBooleanLiteral | core.ERComponentHint.SkipStringLiteral | core.ERComponentHint.SkipNumberLiteral | core.ERComponentHint.StrictLogical | core.ERComponentHint.StrictConditional;
|
|
1665
1851
|
const collector = core.useComponentCollector(context, hint);
|
|
1666
1852
|
const collectorLegacy = core.useComponentCollectorLegacy();
|
|
1667
1853
|
return {
|
|
@@ -1677,8 +1863,12 @@ var no_nested_components_default = createRule({
|
|
|
1677
1863
|
return AST11__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1678
1864
|
};
|
|
1679
1865
|
for (const { name: componentName, node: component } of functionComponents) {
|
|
1680
|
-
if (core.isDirectValueOfRenderPropertyLoose(component))
|
|
1681
|
-
|
|
1866
|
+
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
if (eff.O.isNone(componentName)) {
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1682
1872
|
const name2 = componentName.value;
|
|
1683
1873
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1684
1874
|
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || eff.O.isSome(JSX7__namespace.findParentProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer));
|
|
@@ -1766,25 +1956,41 @@ var no_prop_types_default = createRule({
|
|
|
1766
1956
|
},
|
|
1767
1957
|
name: RULE_NAME31,
|
|
1768
1958
|
create(context) {
|
|
1769
|
-
if (!context.sourceCode.text.includes("propTypes"))
|
|
1959
|
+
if (!context.sourceCode.text.includes("propTypes")) {
|
|
1960
|
+
return {};
|
|
1961
|
+
}
|
|
1770
1962
|
return {
|
|
1771
1963
|
AssignmentExpression(node) {
|
|
1772
|
-
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression)
|
|
1964
|
+
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1773
1967
|
const { object, property } = node.left;
|
|
1774
|
-
if (object.type !== types.AST_NODE_TYPES.Identifier)
|
|
1775
|
-
|
|
1776
|
-
|
|
1968
|
+
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
1969
|
+
return;
|
|
1970
|
+
}
|
|
1971
|
+
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
if (!core.isComponentName(object.name)) {
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1777
1977
|
const isComponent = eff.F.pipe(
|
|
1778
1978
|
VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node)),
|
|
1779
1979
|
eff.O.flatMap(VAR__namespace.getVariableNode(0)),
|
|
1780
1980
|
eff.O.exists((n) => AST11__namespace.isFunction(n) || core.isClassComponent(n))
|
|
1781
1981
|
);
|
|
1782
|
-
if (!isComponent)
|
|
1982
|
+
if (!isComponent) {
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1783
1985
|
context.report({ messageId: "noPropTypes", node: property });
|
|
1784
1986
|
},
|
|
1785
1987
|
PropertyDefinition(node) {
|
|
1786
|
-
if (!core.isClassComponent(node.parent.parent))
|
|
1787
|
-
|
|
1988
|
+
if (!core.isClassComponent(node.parent.parent)) {
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1788
1994
|
context.report({ messageId: "noPropTypes", node });
|
|
1789
1995
|
}
|
|
1790
1996
|
};
|
|
@@ -1812,14 +2018,18 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1812
2018
|
},
|
|
1813
2019
|
name: RULE_NAME32,
|
|
1814
2020
|
create(context) {
|
|
1815
|
-
if (!context.sourceCode.text.includes("shouldComponentUpdate"))
|
|
2021
|
+
if (!context.sourceCode.text.includes("shouldComponentUpdate")) {
|
|
2022
|
+
return {};
|
|
2023
|
+
}
|
|
1816
2024
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
1817
2025
|
return {
|
|
1818
2026
|
...listeners,
|
|
1819
2027
|
"Program:exit"(node) {
|
|
1820
2028
|
const components = ctx.getAllComponents(node);
|
|
1821
2029
|
for (const { name: name2, node: component, flag } of components.values()) {
|
|
1822
|
-
if (!(flag & core.ERClassComponentFlag.PureComponent))
|
|
2030
|
+
if (!(flag & core.ERClassComponentFlag.PureComponent)) {
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
1823
2033
|
const { body } = component.body;
|
|
1824
2034
|
for (const member of body) {
|
|
1825
2035
|
if (isShouldComponentUpdate(member)) {
|
|
@@ -1859,9 +2069,13 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1859
2069
|
},
|
|
1860
2070
|
name: RULE_NAME33,
|
|
1861
2071
|
create(context) {
|
|
1862
|
-
if (!context.sourceCode.text.includes("componentDidMount"))
|
|
2072
|
+
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2073
|
+
return {};
|
|
2074
|
+
}
|
|
1863
2075
|
function getReportDescriptor(node) {
|
|
1864
|
-
if (!core.isThisSetState(node))
|
|
2076
|
+
if (!core.isThisSetState(node)) {
|
|
2077
|
+
return eff.O.none();
|
|
2078
|
+
}
|
|
1865
2079
|
return eff.F.pipe(
|
|
1866
2080
|
eff.O.Do,
|
|
1867
2081
|
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
@@ -1909,9 +2123,13 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1909
2123
|
},
|
|
1910
2124
|
name: RULE_NAME34,
|
|
1911
2125
|
create(context) {
|
|
1912
|
-
if (!context.sourceCode.text.includes("componentDidUpdate"))
|
|
2126
|
+
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2127
|
+
return {};
|
|
2128
|
+
}
|
|
1913
2129
|
function getReportDescriptor(node) {
|
|
1914
|
-
if (!core.isThisSetState(node))
|
|
2130
|
+
if (!core.isThisSetState(node)) {
|
|
2131
|
+
return eff.O.none();
|
|
2132
|
+
}
|
|
1915
2133
|
return eff.F.pipe(
|
|
1916
2134
|
eff.O.Do,
|
|
1917
2135
|
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
@@ -1959,9 +2177,13 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1959
2177
|
},
|
|
1960
2178
|
name: RULE_NAME35,
|
|
1961
2179
|
create(context) {
|
|
1962
|
-
if (!context.sourceCode.text.includes("componentWillUpdate"))
|
|
2180
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2181
|
+
return {};
|
|
2182
|
+
}
|
|
1963
2183
|
function getReportDescriptor(node) {
|
|
1964
|
-
if (!core.isThisSetState(node))
|
|
2184
|
+
if (!core.isThisSetState(node)) {
|
|
2185
|
+
return eff.O.none();
|
|
2186
|
+
}
|
|
1965
2187
|
return eff.F.pipe(
|
|
1966
2188
|
eff.O.Do,
|
|
1967
2189
|
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
@@ -1996,8 +2218,12 @@ function containsStringLiteral({ value }) {
|
|
|
1996
2218
|
return value?.type === types.AST_NODE_TYPES.Literal && eff.isString(value.value);
|
|
1997
2219
|
}
|
|
1998
2220
|
function containsStringExpressionContainer({ value }) {
|
|
1999
|
-
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer)
|
|
2000
|
-
|
|
2221
|
+
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2222
|
+
return false;
|
|
2223
|
+
}
|
|
2224
|
+
if (value.expression.type === types.AST_NODE_TYPES.Literal) {
|
|
2225
|
+
return eff.isString(value.expression.value);
|
|
2226
|
+
}
|
|
2001
2227
|
return value.expression.type === types.AST_NODE_TYPES.TemplateLiteral;
|
|
2002
2228
|
}
|
|
2003
2229
|
var no_string_refs_default = createRule({
|
|
@@ -2016,7 +2242,9 @@ var no_string_refs_default = createRule({
|
|
|
2016
2242
|
create(context) {
|
|
2017
2243
|
return {
|
|
2018
2244
|
JSXAttribute(node) {
|
|
2019
|
-
if (node.name.name !== "ref")
|
|
2245
|
+
if (node.name.name !== "ref") {
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2020
2248
|
if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
|
|
2021
2249
|
context.report({
|
|
2022
2250
|
messageId: "noStringRefs",
|
|
@@ -2049,7 +2277,9 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2049
2277
|
},
|
|
2050
2278
|
name: RULE_NAME37,
|
|
2051
2279
|
create(context) {
|
|
2052
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount"))
|
|
2280
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) {
|
|
2281
|
+
return {};
|
|
2282
|
+
}
|
|
2053
2283
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2054
2284
|
return {
|
|
2055
2285
|
...listeners,
|
|
@@ -2092,7 +2322,9 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2092
2322
|
},
|
|
2093
2323
|
name: RULE_NAME38,
|
|
2094
2324
|
create(context) {
|
|
2095
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps"))
|
|
2325
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2326
|
+
return {};
|
|
2327
|
+
}
|
|
2096
2328
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2097
2329
|
return {
|
|
2098
2330
|
...listeners,
|
|
@@ -2135,7 +2367,9 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2135
2367
|
},
|
|
2136
2368
|
name: RULE_NAME39,
|
|
2137
2369
|
create(context) {
|
|
2138
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate"))
|
|
2370
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) {
|
|
2371
|
+
return {};
|
|
2372
|
+
}
|
|
2139
2373
|
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2140
2374
|
return {
|
|
2141
2375
|
...listeners,
|
|
@@ -2183,8 +2417,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2183
2417
|
...listeners,
|
|
2184
2418
|
JSXOpeningElement(node) {
|
|
2185
2419
|
const openingElementName = node.name;
|
|
2186
|
-
if (openingElementName.type !== types.AST_NODE_TYPES.JSXMemberExpression)
|
|
2187
|
-
|
|
2420
|
+
if (openingElementName.type !== types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
2421
|
+
return;
|
|
2422
|
+
}
|
|
2423
|
+
if (openingElementName.property.name !== "Provider") {
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2188
2426
|
eff.F.pipe(
|
|
2189
2427
|
eff.O.Do,
|
|
2190
2428
|
eff.O.bind("function", ctx.getCurrentFunction),
|
|
@@ -2200,8 +2438,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2200
2438
|
return eff.O.some(VAR__namespace.getValueConstruction(valueExpression, initialScope));
|
|
2201
2439
|
}),
|
|
2202
2440
|
eff.O.map((vc) => {
|
|
2203
|
-
if (vc.construction.kind === "None")
|
|
2204
|
-
|
|
2441
|
+
if (vc.construction.kind === "None") {
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
if (core.isReactHookCall(vc.construction.node)) {
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2205
2447
|
const prevs = constructions.get(vc.function.node) ?? [];
|
|
2206
2448
|
constructions.set(vc.function.node, [...prevs, vc.construction]);
|
|
2207
2449
|
})
|
|
@@ -2211,7 +2453,9 @@ var no_unstable_context_value_default = createRule({
|
|
|
2211
2453
|
const components = ctx.getAllComponents(node).values();
|
|
2212
2454
|
for (const { node: component } of components) {
|
|
2213
2455
|
for (const construction of constructions.get(component) ?? []) {
|
|
2214
|
-
if (construction.kind === "None")
|
|
2456
|
+
if (construction.kind === "None") {
|
|
2457
|
+
continue;
|
|
2458
|
+
}
|
|
2215
2459
|
const { kind, node: constructionNode } = construction;
|
|
2216
2460
|
const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
2217
2461
|
context.report({
|
|
@@ -2255,12 +2499,16 @@ var no_unstable_default_props_default = createRule({
|
|
|
2255
2499
|
for (const { node: component } of components.values()) {
|
|
2256
2500
|
const { params } = component;
|
|
2257
2501
|
const [props] = params;
|
|
2258
|
-
if (!props)
|
|
2502
|
+
if (!props) {
|
|
2503
|
+
continue;
|
|
2504
|
+
}
|
|
2259
2505
|
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
|
|
2260
2506
|
return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
|
|
2261
2507
|
}).otherwise(() => []);
|
|
2262
2508
|
for (const prop of properties) {
|
|
2263
|
-
if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern)
|
|
2509
|
+
if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) {
|
|
2510
|
+
continue;
|
|
2511
|
+
}
|
|
2264
2512
|
const { value } = prop;
|
|
2265
2513
|
const { right } = value;
|
|
2266
2514
|
const initialScope = context.sourceCode.getScope(value);
|
|
@@ -2269,8 +2517,12 @@ var no_unstable_default_props_default = createRule({
|
|
|
2269
2517
|
initialScope,
|
|
2270
2518
|
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2271
2519
|
);
|
|
2272
|
-
if (construction.kind === "None")
|
|
2273
|
-
|
|
2520
|
+
if (construction.kind === "None") {
|
|
2521
|
+
continue;
|
|
2522
|
+
}
|
|
2523
|
+
if (core.isReactHookCall(construction.node)) {
|
|
2524
|
+
continue;
|
|
2525
|
+
}
|
|
2274
2526
|
const forbiddenType = AST11__namespace.toReadableNodeType(right);
|
|
2275
2527
|
context.report({
|
|
2276
2528
|
messageId: "noUnstableDefaultProps",
|
|
@@ -2284,7 +2536,9 @@ var no_unstable_default_props_default = createRule({
|
|
|
2284
2536
|
},
|
|
2285
2537
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2286
2538
|
const mbEntry = ctx.getCurrentFunction();
|
|
2287
|
-
if (eff.O.isNone(mbEntry))
|
|
2539
|
+
if (eff.O.isNone(mbEntry)) {
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2288
2542
|
const entry = mbEntry.value;
|
|
2289
2543
|
const prevs = declarators.get(entry.node) ?? [];
|
|
2290
2544
|
declarators.set(entry.node, [...prevs, node]);
|
|
@@ -2349,21 +2603,31 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2349
2603
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2350
2604
|
function classEnter(node) {
|
|
2351
2605
|
classStack.push(node);
|
|
2352
|
-
if (!core.isClassComponent(node))
|
|
2606
|
+
if (!core.isClassComponent(node)) {
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2353
2609
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
2354
2610
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2355
2611
|
}
|
|
2356
2612
|
function classExit() {
|
|
2357
2613
|
const currentClass = classStack.pop();
|
|
2358
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2614
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2359
2617
|
const className = eff.O.map(AST11__namespace.getClassIdentifier(currentClass), (id) => id.name);
|
|
2360
2618
|
const defs = propertyDefs.get(currentClass);
|
|
2361
2619
|
const usages = propertyUsages.get(currentClass);
|
|
2362
|
-
if (!defs)
|
|
2620
|
+
if (!defs) {
|
|
2621
|
+
return;
|
|
2622
|
+
}
|
|
2363
2623
|
for (const def of defs) {
|
|
2364
2624
|
const name2 = getName3(def);
|
|
2365
|
-
if (eff.O.isNone(name2))
|
|
2366
|
-
|
|
2625
|
+
if (eff.O.isNone(name2)) {
|
|
2626
|
+
continue;
|
|
2627
|
+
}
|
|
2628
|
+
if (usages?.has(name2.value) || LIFECYCLE_METHODS.has(name2.value)) {
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2367
2631
|
context.report({
|
|
2368
2632
|
messageId: "noUnusedClassComponentMembers",
|
|
2369
2633
|
node: def,
|
|
@@ -2377,8 +2641,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2377
2641
|
function methodEnter(node) {
|
|
2378
2642
|
methodStack.push(node);
|
|
2379
2643
|
const currentClass = classStack.at(-1);
|
|
2380
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2381
|
-
|
|
2644
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2647
|
+
if (node.static) {
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2382
2650
|
if (AST11__namespace.isKeyLiteralLike(node, node.key)) {
|
|
2383
2651
|
propertyDefs.get(currentClass)?.add(node.key);
|
|
2384
2652
|
}
|
|
@@ -2394,9 +2662,15 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2394
2662
|
MemberExpression(node) {
|
|
2395
2663
|
const currentClass = classStack.at(-1);
|
|
2396
2664
|
const currentMethod = methodStack.at(-1);
|
|
2397
|
-
if (!currentClass || !currentMethod)
|
|
2398
|
-
|
|
2399
|
-
|
|
2665
|
+
if (!currentClass || !currentMethod) {
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2669
|
+
return;
|
|
2670
|
+
}
|
|
2671
|
+
if (!AST11__namespace.isThisExpression(node.object) || !AST11__namespace.isKeyLiteralLike(node, node.property)) {
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2400
2674
|
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2401
2675
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2402
2676
|
return;
|
|
@@ -2410,8 +2684,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2410
2684
|
VariableDeclarator(node) {
|
|
2411
2685
|
const currentClass = classStack.at(-1);
|
|
2412
2686
|
const currentMethod = methodStack.at(-1);
|
|
2413
|
-
if (!currentClass || !currentMethod)
|
|
2414
|
-
|
|
2687
|
+
if (!currentClass || !currentMethod) {
|
|
2688
|
+
return;
|
|
2689
|
+
}
|
|
2690
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2691
|
+
return;
|
|
2692
|
+
}
|
|
2415
2693
|
if (node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2416
2694
|
for (const prop of node.id.properties) {
|
|
2417
2695
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
@@ -2483,10 +2761,14 @@ var no_unused_state_default = createRule({
|
|
|
2483
2761
|
}
|
|
2484
2762
|
function classExit() {
|
|
2485
2763
|
const currentClass = classStack.pop();
|
|
2486
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2764
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2487
2767
|
const className = eff.O.map(AST11__namespace.getClassIdentifier(currentClass), (id) => id.name);
|
|
2488
2768
|
const [def, isUsed] = stateDefs.get(currentClass) ?? [eff.O.none(), false];
|
|
2489
|
-
if (eff.O.isNone(def) || isUsed)
|
|
2769
|
+
if (eff.O.isNone(def) || isUsed) {
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2490
2772
|
context.report({
|
|
2491
2773
|
messageId: "noUnusedState",
|
|
2492
2774
|
node: def.value,
|
|
@@ -2498,7 +2780,9 @@ var no_unused_state_default = createRule({
|
|
|
2498
2780
|
function methodEnter(node) {
|
|
2499
2781
|
methodStack.push(node);
|
|
2500
2782
|
const currentClass = classStack.at(-1);
|
|
2501
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2783
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2502
2786
|
if (node.static) {
|
|
2503
2787
|
if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
|
|
2504
2788
|
const [def] = stateDefs.get(currentClass) ?? [eff.O.none()];
|
|
@@ -2521,11 +2805,17 @@ var no_unused_state_default = createRule({
|
|
|
2521
2805
|
}
|
|
2522
2806
|
return {
|
|
2523
2807
|
AssignmentExpression(node) {
|
|
2524
|
-
if (!isAssignmentToThisState2(node))
|
|
2808
|
+
if (!isAssignmentToThisState2(node)) {
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2525
2811
|
const currentClass = classStack.at(-1);
|
|
2526
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2812
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2527
2815
|
const currentConstructor = constructorStack.at(-1);
|
|
2528
|
-
if (!currentConstructor || !currentClass.body.body.includes(currentConstructor))
|
|
2816
|
+
if (!currentConstructor || !currentClass.body.body.includes(currentConstructor)) {
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2529
2819
|
const [_, isUsed] = stateDefs.get(currentClass) ?? [eff.O.none(), false];
|
|
2530
2820
|
stateDefs.set(currentClass, [eff.O.some(node.left), isUsed]);
|
|
2531
2821
|
},
|
|
@@ -2534,14 +2824,26 @@ var no_unused_state_default = createRule({
|
|
|
2534
2824
|
ClassExpression: classEnter,
|
|
2535
2825
|
"ClassExpression:exit": classExit,
|
|
2536
2826
|
MemberExpression(node) {
|
|
2537
|
-
if (!AST11__namespace.isThisExpression(node.object))
|
|
2538
|
-
|
|
2827
|
+
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
if (!eff.O.exists(getName4(node.property), (name2) => name2 === "state")) {
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2539
2833
|
const currentClass = classStack.at(-1);
|
|
2540
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2834
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2541
2837
|
const currentMethod = methodStack.at(-1);
|
|
2542
|
-
if (!currentMethod || currentMethod.static)
|
|
2543
|
-
|
|
2544
|
-
|
|
2838
|
+
if (!currentMethod || currentMethod.static) {
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
if (currentMethod === constructorStack.at(-1)) {
|
|
2842
|
+
return;
|
|
2843
|
+
}
|
|
2844
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2545
2847
|
const [def] = stateDefs.get(currentClass) ?? [eff.O.none(), false];
|
|
2546
2848
|
stateDefs.set(currentClass, [def, true]);
|
|
2547
2849
|
},
|
|
@@ -2553,19 +2855,31 @@ var no_unused_state_default = createRule({
|
|
|
2553
2855
|
"PropertyDefinition:exit": methodExit,
|
|
2554
2856
|
VariableDeclarator(node) {
|
|
2555
2857
|
const currentClass = classStack.at(-1);
|
|
2556
|
-
if (!currentClass || !core.isClassComponent(currentClass))
|
|
2858
|
+
if (!currentClass || !core.isClassComponent(currentClass)) {
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2557
2861
|
const currentMethod = methodStack.at(-1);
|
|
2558
|
-
if (!currentMethod || currentMethod.static)
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
if (
|
|
2862
|
+
if (!currentMethod || currentMethod.static) {
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
if (currentMethod === constructorStack.at(-1)) {
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2871
|
+
if (!(node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
2872
|
+
return;
|
|
2873
|
+
}
|
|
2562
2874
|
const hasState = node.id.properties.some((prop) => {
|
|
2563
2875
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2564
2876
|
return eff.O.exists(getName4(prop.key), (name2) => name2 === "state");
|
|
2565
2877
|
}
|
|
2566
2878
|
return false;
|
|
2567
2879
|
});
|
|
2568
|
-
if (!hasState)
|
|
2880
|
+
if (!hasState) {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2569
2883
|
const [def] = stateDefs.get(currentClass) ?? [eff.O.none(), false];
|
|
2570
2884
|
stateDefs.set(currentClass, [def, true]);
|
|
2571
2885
|
}
|
|
@@ -2579,8 +2893,12 @@ var defaultOptions = [{
|
|
|
2579
2893
|
}];
|
|
2580
2894
|
function checkAndReport(node, context, allowExpressions) {
|
|
2581
2895
|
const initialScope = context.sourceCode.getScope(node);
|
|
2582
|
-
if (JSX7__namespace.isKeyedElement(node, initialScope))
|
|
2583
|
-
|
|
2896
|
+
if (JSX7__namespace.isKeyedElement(node, initialScope)) {
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
if (JSX7__namespace.isBuiltInElement(node.parent)) {
|
|
2900
|
+
context.report({ messageId: "noUselessFragmentInBuiltIn", node });
|
|
2901
|
+
}
|
|
2584
2902
|
if (node.children.length === 0) {
|
|
2585
2903
|
context.report({ messageId: "noUselessFragment", node });
|
|
2586
2904
|
return;
|
|
@@ -2639,7 +2957,9 @@ var no_useless_fragment_default = createRule({
|
|
|
2639
2957
|
const { allowExpressions = true } = option;
|
|
2640
2958
|
return {
|
|
2641
2959
|
JSXElement(node) {
|
|
2642
|
-
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment")
|
|
2960
|
+
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
2961
|
+
return;
|
|
2962
|
+
}
|
|
2643
2963
|
checkAndReport(node, context, allowExpressions);
|
|
2644
2964
|
},
|
|
2645
2965
|
JSXFragment(node) {
|
|
@@ -2683,7 +3003,9 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2683
3003
|
"Program:exit"(node) {
|
|
2684
3004
|
const components = Array.from(ctx.getAllComponents(node).values());
|
|
2685
3005
|
function isFunctionComponent(block) {
|
|
2686
|
-
if (!AST11__namespace.isFunction(block))
|
|
3006
|
+
if (!AST11__namespace.isFunction(block)) {
|
|
3007
|
+
return false;
|
|
3008
|
+
}
|
|
2687
3009
|
return eff.O.exists(
|
|
2688
3010
|
AST11__namespace.getFunctionIdentifier(block),
|
|
2689
3011
|
(id) => core.isComponentName(id.name) && components.some((component) => component.node === block)
|
|
@@ -2696,9 +3018,13 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2696
3018
|
scope = scope.upper;
|
|
2697
3019
|
isComponent = isFunctionComponent(scope.block);
|
|
2698
3020
|
}
|
|
2699
|
-
if (!isComponent)
|
|
3021
|
+
if (!isComponent) {
|
|
3022
|
+
continue;
|
|
3023
|
+
}
|
|
2700
3024
|
const component = scope.block;
|
|
2701
|
-
if (!("params" in component))
|
|
3025
|
+
if (!("params" in component)) {
|
|
3026
|
+
continue;
|
|
3027
|
+
}
|
|
2702
3028
|
const [props, ctx2] = component.params;
|
|
2703
3029
|
const isMatch = tsPattern.isMatching({ name: memberExpression.object.name });
|
|
2704
3030
|
if (isMatch(props)) {
|
|
@@ -2814,9 +3140,13 @@ var prefer_read_only_props_default = createRule({
|
|
|
2814
3140
|
const components = ctx.getAllComponents(node);
|
|
2815
3141
|
for (const [_, component] of components) {
|
|
2816
3142
|
const [props] = component.node.params;
|
|
2817
|
-
if (!props)
|
|
3143
|
+
if (!props) {
|
|
3144
|
+
continue;
|
|
3145
|
+
}
|
|
2818
3146
|
const propsType = typeUtils.getConstrainedTypeAtLocation(services, props);
|
|
2819
|
-
if (typeUtils.isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services))
|
|
3147
|
+
if (typeUtils.isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services)) {
|
|
3148
|
+
continue;
|
|
3149
|
+
}
|
|
2820
3150
|
context.report({ messageId: "preferReadOnlyProps", node: props });
|
|
2821
3151
|
}
|
|
2822
3152
|
}
|
|
@@ -2848,7 +3178,9 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
2848
3178
|
const { value } = node;
|
|
2849
3179
|
const propName = JSX7__namespace.getPropName(node);
|
|
2850
3180
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
2851
|
-
if (!hasValueTrue)
|
|
3181
|
+
if (!hasValueTrue) {
|
|
3182
|
+
return eff.O.none();
|
|
3183
|
+
}
|
|
2852
3184
|
return eff.O.some({
|
|
2853
3185
|
messageId: "preferShorthandBoolean",
|
|
2854
3186
|
node,
|
|
@@ -2885,15 +3217,21 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
2885
3217
|
name: RULE_NAME49,
|
|
2886
3218
|
create(context) {
|
|
2887
3219
|
function getReportDescriptor(node) {
|
|
2888
|
-
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment")
|
|
3220
|
+
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3221
|
+
return eff.O.none();
|
|
3222
|
+
}
|
|
2889
3223
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
2890
|
-
if (hasAttributes)
|
|
3224
|
+
if (hasAttributes) {
|
|
3225
|
+
return eff.O.none();
|
|
3226
|
+
}
|
|
2891
3227
|
return eff.O.some({
|
|
2892
3228
|
messageId: "preferShorthandFragment",
|
|
2893
3229
|
node,
|
|
2894
3230
|
fix: (fixer) => {
|
|
2895
3231
|
const { closingElement, openingElement } = node;
|
|
2896
|
-
if (!closingElement)
|
|
3232
|
+
if (!closingElement) {
|
|
3233
|
+
return [];
|
|
3234
|
+
}
|
|
2897
3235
|
return [
|
|
2898
3236
|
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
2899
3237
|
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
@@ -2936,7 +3274,9 @@ var use_jsx_vars_default = createRule({
|
|
|
2936
3274
|
}
|
|
2937
3275
|
return {
|
|
2938
3276
|
JSXOpeningElement(node) {
|
|
2939
|
-
if (node.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name))
|
|
3277
|
+
if (node.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) {
|
|
3278
|
+
return;
|
|
3279
|
+
}
|
|
2940
3280
|
for (const name2 of eff.O.toArray(getName5(node.name))) {
|
|
2941
3281
|
context.sourceCode.markVariableAsUsed(name2, node);
|
|
2942
3282
|
}
|