eslint-plugin-react-x 1.33.0 → 1.34.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1784 -1762
- package/dist/index.mjs +1784 -1762
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -136,7 +136,7 @@ var settings3 = {
|
|
|
136
136
|
|
|
137
137
|
// package.json
|
|
138
138
|
var name4 = "eslint-plugin-react-x";
|
|
139
|
-
var version = "1.
|
|
139
|
+
var version = "1.34.0-beta.1";
|
|
140
140
|
var createRule = shared.createRuleForPlugin("x");
|
|
141
141
|
|
|
142
142
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -158,24 +158,25 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
158
158
|
schema: []
|
|
159
159
|
},
|
|
160
160
|
name: RULE_NAME,
|
|
161
|
-
create
|
|
162
|
-
return {
|
|
163
|
-
JSXAttribute(node) {
|
|
164
|
-
if (node.value === null) {
|
|
165
|
-
context.report({
|
|
166
|
-
messageId: "avoidShorthandBoolean",
|
|
167
|
-
node,
|
|
168
|
-
data: {
|
|
169
|
-
propName: JSX8__namespace.getAttributeName(node)
|
|
170
|
-
},
|
|
171
|
-
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
},
|
|
161
|
+
create,
|
|
177
162
|
defaultOptions: []
|
|
178
163
|
});
|
|
164
|
+
function create(context) {
|
|
165
|
+
return {
|
|
166
|
+
JSXAttribute(node) {
|
|
167
|
+
if (node.value === null) {
|
|
168
|
+
context.report({
|
|
169
|
+
messageId: "avoidShorthandBoolean",
|
|
170
|
+
node,
|
|
171
|
+
data: {
|
|
172
|
+
propName: JSX8__namespace.getAttributeName(node)
|
|
173
|
+
},
|
|
174
|
+
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
179
180
|
|
|
180
181
|
// src/rules/avoid-shorthand-fragment.ts
|
|
181
182
|
var RULE_NAME2 = "avoid-shorthand-fragment";
|
|
@@ -195,18 +196,19 @@ var avoid_shorthand_fragment_default = createRule({
|
|
|
195
196
|
schema: []
|
|
196
197
|
},
|
|
197
198
|
name: RULE_NAME2,
|
|
198
|
-
create
|
|
199
|
-
return {
|
|
200
|
-
JSXFragment(node) {
|
|
201
|
-
context.report({
|
|
202
|
-
messageId: "avoidShorthandFragment",
|
|
203
|
-
node
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
},
|
|
199
|
+
create: create2,
|
|
208
200
|
defaultOptions: []
|
|
209
201
|
});
|
|
202
|
+
function create2(context) {
|
|
203
|
+
return {
|
|
204
|
+
JSXFragment(node) {
|
|
205
|
+
context.report({
|
|
206
|
+
messageId: "avoidShorthandFragment",
|
|
207
|
+
node
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
210
212
|
var RULE_NAME3 = "no-access-state-in-setstate";
|
|
211
213
|
var RULE_FEATURES3 = [
|
|
212
214
|
"CHK"
|
|
@@ -227,99 +229,100 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
227
229
|
schema: []
|
|
228
230
|
},
|
|
229
231
|
name: RULE_NAME3,
|
|
230
|
-
create
|
|
231
|
-
if (!context.sourceCode.text.includes("setState")) {
|
|
232
|
-
return {};
|
|
233
|
-
}
|
|
234
|
-
const classEntries = [];
|
|
235
|
-
const methodEntries = [];
|
|
236
|
-
const setStateEntries = [];
|
|
237
|
-
return {
|
|
238
|
-
CallExpression(node) {
|
|
239
|
-
if (!core.isThisSetState(node)) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
setStateEntries.push([node, false]);
|
|
243
|
-
},
|
|
244
|
-
"CallExpression:exit"(node) {
|
|
245
|
-
if (!core.isThisSetState(node)) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
setStateEntries.pop();
|
|
249
|
-
},
|
|
250
|
-
ClassDeclaration(node) {
|
|
251
|
-
classEntries.push([node, core.isClassComponent(node)]);
|
|
252
|
-
},
|
|
253
|
-
"ClassDeclaration:exit"() {
|
|
254
|
-
classEntries.pop();
|
|
255
|
-
},
|
|
256
|
-
ClassExpression(node) {
|
|
257
|
-
classEntries.push([node, core.isClassComponent(node)]);
|
|
258
|
-
},
|
|
259
|
-
"ClassExpression:exit"() {
|
|
260
|
-
classEntries.pop();
|
|
261
|
-
},
|
|
262
|
-
MemberExpression(node) {
|
|
263
|
-
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
267
|
-
if (currClass == null || !isComponent) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
271
|
-
if (currMethod == null || isStatic) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
275
|
-
if (setState == null || hasThisState) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (AST11__namespace.getPropertyName(node.property) !== "state") {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
282
|
-
},
|
|
283
|
-
MethodDefinition(node) {
|
|
284
|
-
methodEntries.push([node, node.static]);
|
|
285
|
-
},
|
|
286
|
-
"MethodDefinition:exit"() {
|
|
287
|
-
methodEntries.pop();
|
|
288
|
-
},
|
|
289
|
-
PropertyDefinition(node) {
|
|
290
|
-
methodEntries.push([node, node.static]);
|
|
291
|
-
},
|
|
292
|
-
"PropertyDefinition:exit"() {
|
|
293
|
-
methodEntries.pop();
|
|
294
|
-
},
|
|
295
|
-
VariableDeclarator(node) {
|
|
296
|
-
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
297
|
-
if (currClass == null || !isComponent) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
301
|
-
if (currMethod == null || isStatic) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
305
|
-
if (setState == null || hasThisState) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const hasState = node.id.properties.some(
|
|
312
|
-
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST11__namespace.getPropertyName(prop.key) === "state"
|
|
313
|
-
);
|
|
314
|
-
if (!hasState) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
},
|
|
232
|
+
create: create3,
|
|
321
233
|
defaultOptions: []
|
|
322
234
|
});
|
|
235
|
+
function create3(context) {
|
|
236
|
+
if (!context.sourceCode.text.includes("setState")) {
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
const classEntries = [];
|
|
240
|
+
const methodEntries = [];
|
|
241
|
+
const setStateEntries = [];
|
|
242
|
+
return {
|
|
243
|
+
CallExpression(node) {
|
|
244
|
+
if (!core.isThisSetState(node)) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
setStateEntries.push([node, false]);
|
|
248
|
+
},
|
|
249
|
+
"CallExpression:exit"(node) {
|
|
250
|
+
if (!core.isThisSetState(node)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
setStateEntries.pop();
|
|
254
|
+
},
|
|
255
|
+
ClassDeclaration(node) {
|
|
256
|
+
classEntries.push([node, core.isClassComponent(node)]);
|
|
257
|
+
},
|
|
258
|
+
"ClassDeclaration:exit"() {
|
|
259
|
+
classEntries.pop();
|
|
260
|
+
},
|
|
261
|
+
ClassExpression(node) {
|
|
262
|
+
classEntries.push([node, core.isClassComponent(node)]);
|
|
263
|
+
},
|
|
264
|
+
"ClassExpression:exit"() {
|
|
265
|
+
classEntries.pop();
|
|
266
|
+
},
|
|
267
|
+
MemberExpression(node) {
|
|
268
|
+
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
272
|
+
if (currClass == null || !isComponent) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
276
|
+
if (currMethod == null || isStatic) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
280
|
+
if (setState == null || hasThisState) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (AST11__namespace.getPropertyName(node.property) !== "state") {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
287
|
+
},
|
|
288
|
+
MethodDefinition(node) {
|
|
289
|
+
methodEntries.push([node, node.static]);
|
|
290
|
+
},
|
|
291
|
+
"MethodDefinition:exit"() {
|
|
292
|
+
methodEntries.pop();
|
|
293
|
+
},
|
|
294
|
+
PropertyDefinition(node) {
|
|
295
|
+
methodEntries.push([node, node.static]);
|
|
296
|
+
},
|
|
297
|
+
"PropertyDefinition:exit"() {
|
|
298
|
+
methodEntries.pop();
|
|
299
|
+
},
|
|
300
|
+
VariableDeclarator(node) {
|
|
301
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
302
|
+
if (currClass == null || !isComponent) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
306
|
+
if (currMethod == null || isStatic) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
310
|
+
if (setState == null || hasThisState) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const hasState = node.id.properties.some(
|
|
317
|
+
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST11__namespace.getPropertyName(prop.key) === "state"
|
|
318
|
+
);
|
|
319
|
+
if (!hasState) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
323
326
|
var RULE_NAME4 = "no-array-index-key";
|
|
324
327
|
var RULE_FEATURES4 = [
|
|
325
328
|
"CHK"
|
|
@@ -390,6 +393,18 @@ function getMapIndexParamName(context, node) {
|
|
|
390
393
|
const param = params.at(indexParamPosition);
|
|
391
394
|
return param != null && "name" in param ? param.name : eff._;
|
|
392
395
|
}
|
|
396
|
+
function getIdentifiersFromBinaryExpression(side) {
|
|
397
|
+
if (side.type === types.AST_NODE_TYPES.Identifier) {
|
|
398
|
+
return [side];
|
|
399
|
+
}
|
|
400
|
+
if (side.type === types.AST_NODE_TYPES.BinaryExpression) {
|
|
401
|
+
return [
|
|
402
|
+
...getIdentifiersFromBinaryExpression(side.left),
|
|
403
|
+
...getIdentifiersFromBinaryExpression(side.right)
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
return [];
|
|
407
|
+
}
|
|
393
408
|
var no_array_index_key_default = createRule({
|
|
394
409
|
meta: {
|
|
395
410
|
type: "problem",
|
|
@@ -403,122 +418,111 @@ var no_array_index_key_default = createRule({
|
|
|
403
418
|
schema: []
|
|
404
419
|
},
|
|
405
420
|
name: RULE_NAME4,
|
|
406
|
-
create
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
421
|
+
create: create4,
|
|
422
|
+
defaultOptions: []
|
|
423
|
+
});
|
|
424
|
+
function create4(context) {
|
|
425
|
+
const indexParamNames = [];
|
|
426
|
+
function isArrayIndex(node) {
|
|
427
|
+
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
428
|
+
}
|
|
429
|
+
function isCreateOrCloneElementCall(node) {
|
|
430
|
+
return core.isCreateElementCall(context, node) || core.isCloneElementCall(context, node);
|
|
431
|
+
}
|
|
432
|
+
function getReportDescriptors(node) {
|
|
433
|
+
switch (node.type) {
|
|
434
|
+
// key={bar}
|
|
435
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
436
|
+
if (indexParamNames.some((name5) => name5 != null && name5 === node.name)) {
|
|
437
|
+
return [{
|
|
438
|
+
messageId: "noArrayIndexKey",
|
|
439
|
+
node
|
|
440
|
+
}];
|
|
441
|
+
}
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
445
|
+
case types.AST_NODE_TYPES.TemplateLiteral:
|
|
446
|
+
case types.AST_NODE_TYPES.BinaryExpression: {
|
|
447
|
+
const descriptors = [];
|
|
448
|
+
const expressions = node.type === types.AST_NODE_TYPES.TemplateLiteral ? node.expressions : getIdentifiersFromBinaryExpression(node);
|
|
449
|
+
for (const expression of expressions) {
|
|
450
|
+
if (isArrayIndex(expression)) {
|
|
451
|
+
descriptors.push({
|
|
420
452
|
messageId: "noArrayIndexKey",
|
|
421
|
-
node
|
|
422
|
-
}
|
|
453
|
+
node: expression
|
|
454
|
+
});
|
|
423
455
|
}
|
|
424
|
-
return [];
|
|
425
456
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
457
|
+
return descriptors;
|
|
458
|
+
}
|
|
459
|
+
// key={bar.toString()} or key={String(bar)}
|
|
460
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
461
|
+
switch (true) {
|
|
462
|
+
// key={bar.toString()}
|
|
463
|
+
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)): {
|
|
464
|
+
return [{
|
|
465
|
+
messageId: "noArrayIndexKey",
|
|
466
|
+
node: node.callee.object
|
|
467
|
+
}];
|
|
438
468
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
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)): {
|
|
446
|
-
return [{
|
|
447
|
-
messageId: "noArrayIndexKey",
|
|
448
|
-
node: node.callee.object
|
|
449
|
-
}];
|
|
450
|
-
}
|
|
451
|
-
// key={String(bar)}
|
|
452
|
-
case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0])): {
|
|
453
|
-
return [{
|
|
454
|
-
messageId: "noArrayIndexKey",
|
|
455
|
-
node: node.arguments[0]
|
|
456
|
-
}];
|
|
457
|
-
}
|
|
469
|
+
// key={String(bar)}
|
|
470
|
+
case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0])): {
|
|
471
|
+
return [{
|
|
472
|
+
messageId: "noArrayIndexKey",
|
|
473
|
+
node: node.arguments[0]
|
|
474
|
+
}];
|
|
458
475
|
}
|
|
459
476
|
}
|
|
460
477
|
}
|
|
461
|
-
return [];
|
|
462
478
|
}
|
|
463
|
-
return
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
const descriptors = getReportDescriptors(prop.value);
|
|
484
|
-
for (const descriptor of descriptors) {
|
|
485
|
-
context.report(descriptor);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
"CallExpression:exit"() {
|
|
490
|
-
indexParamNames.pop();
|
|
491
|
-
},
|
|
492
|
-
JSXAttribute(node) {
|
|
493
|
-
if (node.name.name !== "key") {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
if (indexParamNames.length === 0) {
|
|
497
|
-
return;
|
|
479
|
+
return [];
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
CallExpression(node) {
|
|
483
|
+
indexParamNames.push(getMapIndexParamName(context, node));
|
|
484
|
+
if (node.arguments.length === 0) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (!isCreateOrCloneElementCall(node)) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const [, props] = node.arguments;
|
|
491
|
+
if (props?.type !== types.AST_NODE_TYPES.ObjectExpression) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
for (const prop of props.properties) {
|
|
495
|
+
if (!tsPattern.isMatching({ key: { name: "key" } })(prop)) {
|
|
496
|
+
continue;
|
|
498
497
|
}
|
|
499
|
-
if (
|
|
500
|
-
|
|
498
|
+
if (!("value" in prop)) {
|
|
499
|
+
continue;
|
|
501
500
|
}
|
|
502
|
-
const descriptors = getReportDescriptors(
|
|
501
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
503
502
|
for (const descriptor of descriptors) {
|
|
504
503
|
context.report(descriptor);
|
|
505
504
|
}
|
|
506
505
|
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
506
|
+
},
|
|
507
|
+
"CallExpression:exit"() {
|
|
508
|
+
indexParamNames.pop();
|
|
509
|
+
},
|
|
510
|
+
JSXAttribute(node) {
|
|
511
|
+
if (node.name.name !== "key") {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (indexParamNames.length === 0) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (node.value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
521
|
+
for (const descriptor of descriptors) {
|
|
522
|
+
context.report(descriptor);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
522
526
|
}
|
|
523
527
|
var RULE_NAME5 = "no-children-count";
|
|
524
528
|
var RULE_FEATURES5 = [
|
|
@@ -537,20 +541,21 @@ var no_children_count_default = createRule({
|
|
|
537
541
|
schema: []
|
|
538
542
|
},
|
|
539
543
|
name: RULE_NAME5,
|
|
540
|
-
create
|
|
541
|
-
return {
|
|
542
|
-
MemberExpression(node) {
|
|
543
|
-
if (core.isChildrenCount(context, node)) {
|
|
544
|
-
context.report({
|
|
545
|
-
messageId: "noChildrenCount",
|
|
546
|
-
node: node.property
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
},
|
|
544
|
+
create: create5,
|
|
552
545
|
defaultOptions: []
|
|
553
546
|
});
|
|
547
|
+
function create5(context) {
|
|
548
|
+
return {
|
|
549
|
+
MemberExpression(node) {
|
|
550
|
+
if (core.isChildrenCount(context, node)) {
|
|
551
|
+
context.report({
|
|
552
|
+
messageId: "noChildrenCount",
|
|
553
|
+
node: node.property
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
}
|
|
554
559
|
var RULE_NAME6 = "no-children-for-each";
|
|
555
560
|
var RULE_FEATURES6 = [
|
|
556
561
|
"CHK"
|
|
@@ -568,20 +573,21 @@ var no_children_for_each_default = createRule({
|
|
|
568
573
|
schema: []
|
|
569
574
|
},
|
|
570
575
|
name: RULE_NAME6,
|
|
571
|
-
create
|
|
572
|
-
return {
|
|
573
|
-
MemberExpression(node) {
|
|
574
|
-
if (core.isChildrenForEach(context, node)) {
|
|
575
|
-
context.report({
|
|
576
|
-
messageId: "noChildrenForEach",
|
|
577
|
-
node: node.property
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
},
|
|
576
|
+
create: create6,
|
|
583
577
|
defaultOptions: []
|
|
584
578
|
});
|
|
579
|
+
function create6(context) {
|
|
580
|
+
return {
|
|
581
|
+
MemberExpression(node) {
|
|
582
|
+
if (core.isChildrenForEach(context, node)) {
|
|
583
|
+
context.report({
|
|
584
|
+
messageId: "noChildrenForEach",
|
|
585
|
+
node: node.property
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
}
|
|
585
591
|
var RULE_NAME7 = "no-children-map";
|
|
586
592
|
var RULE_FEATURES7 = [
|
|
587
593
|
"CHK"
|
|
@@ -630,20 +636,21 @@ var no_children_only_default = createRule({
|
|
|
630
636
|
schema: []
|
|
631
637
|
},
|
|
632
638
|
name: RULE_NAME8,
|
|
633
|
-
create
|
|
634
|
-
return {
|
|
635
|
-
MemberExpression(node) {
|
|
636
|
-
if (core.isChildrenOnly(context, node)) {
|
|
637
|
-
context.report({
|
|
638
|
-
messageId: "noChildrenOnly",
|
|
639
|
-
node: node.property
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
},
|
|
639
|
+
create: create7,
|
|
645
640
|
defaultOptions: []
|
|
646
641
|
});
|
|
642
|
+
function create7(context) {
|
|
643
|
+
return {
|
|
644
|
+
MemberExpression(node) {
|
|
645
|
+
if (core.isChildrenOnly(context, node)) {
|
|
646
|
+
context.report({
|
|
647
|
+
messageId: "noChildrenOnly",
|
|
648
|
+
node: node.property
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
647
654
|
var RULE_NAME9 = "no-children-prop";
|
|
648
655
|
var RULE_FEATURES9 = [
|
|
649
656
|
"CHK"
|
|
@@ -661,25 +668,26 @@ var no_children_prop_default = createRule({
|
|
|
661
668
|
schema: []
|
|
662
669
|
},
|
|
663
670
|
name: RULE_NAME9,
|
|
664
|
-
create
|
|
665
|
-
return {
|
|
666
|
-
JSXElement(node) {
|
|
667
|
-
const attribute = JSX8__namespace.getAttribute(
|
|
668
|
-
"children",
|
|
669
|
-
node.openingElement.attributes,
|
|
670
|
-
context.sourceCode.getScope(node)
|
|
671
|
-
);
|
|
672
|
-
if (attribute != null) {
|
|
673
|
-
context.report({
|
|
674
|
-
messageId: "noChildrenProp",
|
|
675
|
-
node: attribute
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
},
|
|
671
|
+
create: create8,
|
|
681
672
|
defaultOptions: []
|
|
682
673
|
});
|
|
674
|
+
function create8(context) {
|
|
675
|
+
return {
|
|
676
|
+
JSXElement(node) {
|
|
677
|
+
const attribute = JSX8__namespace.getAttribute(
|
|
678
|
+
"children",
|
|
679
|
+
node.openingElement.attributes,
|
|
680
|
+
context.sourceCode.getScope(node)
|
|
681
|
+
);
|
|
682
|
+
if (attribute != null) {
|
|
683
|
+
context.report({
|
|
684
|
+
messageId: "noChildrenProp",
|
|
685
|
+
node: attribute
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
683
691
|
var RULE_NAME10 = "no-children-to-array";
|
|
684
692
|
var RULE_FEATURES10 = [
|
|
685
693
|
"CHK"
|
|
@@ -697,20 +705,21 @@ var no_children_to_array_default = createRule({
|
|
|
697
705
|
schema: []
|
|
698
706
|
},
|
|
699
707
|
name: RULE_NAME10,
|
|
700
|
-
create
|
|
701
|
-
return {
|
|
702
|
-
MemberExpression(node) {
|
|
703
|
-
if (core.isChildrenToArray(context, node)) {
|
|
704
|
-
context.report({
|
|
705
|
-
messageId: "noChildrenToArray",
|
|
706
|
-
node: node.property
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
},
|
|
708
|
+
create: create9,
|
|
712
709
|
defaultOptions: []
|
|
713
710
|
});
|
|
711
|
+
function create9(context) {
|
|
712
|
+
return {
|
|
713
|
+
MemberExpression(node) {
|
|
714
|
+
if (core.isChildrenToArray(context, node)) {
|
|
715
|
+
context.report({
|
|
716
|
+
messageId: "noChildrenToArray",
|
|
717
|
+
node: node.property
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
}
|
|
714
723
|
var RULE_NAME11 = "no-class-component";
|
|
715
724
|
var RULE_FEATURES11 = [
|
|
716
725
|
"CHK"
|
|
@@ -728,32 +737,31 @@ var no_class_component_default = createRule({
|
|
|
728
737
|
schema: []
|
|
729
738
|
},
|
|
730
739
|
name: RULE_NAME11,
|
|
731
|
-
create
|
|
732
|
-
if (!context.sourceCode.text.includes("Component")) {
|
|
733
|
-
return {};
|
|
734
|
-
}
|
|
735
|
-
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
736
|
-
return {
|
|
737
|
-
...listeners,
|
|
738
|
-
"Program:exit"(node) {
|
|
739
|
-
const components = ctx.getAllComponents(node);
|
|
740
|
-
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
741
|
-
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) {
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
context.report({
|
|
745
|
-
messageId: "noClassComponent",
|
|
746
|
-
node: component,
|
|
747
|
-
data: {
|
|
748
|
-
name: name5
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
},
|
|
740
|
+
create: create10,
|
|
755
741
|
defaultOptions: []
|
|
756
742
|
});
|
|
743
|
+
function create10(context) {
|
|
744
|
+
if (!context.sourceCode.text.includes("Component")) return {};
|
|
745
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
746
|
+
return {
|
|
747
|
+
...listeners,
|
|
748
|
+
"Program:exit"(node) {
|
|
749
|
+
const components = ctx.getAllComponents(node);
|
|
750
|
+
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
751
|
+
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
context.report({
|
|
755
|
+
messageId: "noClassComponent",
|
|
756
|
+
node: component,
|
|
757
|
+
data: {
|
|
758
|
+
name: name5
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
757
765
|
var RULE_NAME12 = "no-clone-element";
|
|
758
766
|
var RULE_FEATURES12 = [
|
|
759
767
|
"CHK"
|
|
@@ -771,21 +779,22 @@ var no_clone_element_default = createRule({
|
|
|
771
779
|
schema: []
|
|
772
780
|
},
|
|
773
781
|
name: RULE_NAME12,
|
|
774
|
-
create
|
|
775
|
-
return {
|
|
776
|
-
CallExpression(node) {
|
|
777
|
-
if (!core.isCloneElementCall(context, node)) {
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
context.report({
|
|
781
|
-
messageId: "noCloneElement",
|
|
782
|
-
node
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
},
|
|
782
|
+
create: create11,
|
|
787
783
|
defaultOptions: []
|
|
788
784
|
});
|
|
785
|
+
function create11(context) {
|
|
786
|
+
return {
|
|
787
|
+
CallExpression(node) {
|
|
788
|
+
if (!core.isCloneElementCall(context, node)) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
context.report({
|
|
792
|
+
messageId: "noCloneElement",
|
|
793
|
+
node
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
789
798
|
var RULE_NAME13 = "no-comment-textnodes";
|
|
790
799
|
var RULE_FEATURES13 = [
|
|
791
800
|
"CHK"
|
|
@@ -850,33 +859,34 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
850
859
|
schema: []
|
|
851
860
|
},
|
|
852
861
|
name: RULE_NAME14,
|
|
853
|
-
create
|
|
854
|
-
const visitorFunction = (node) => {
|
|
855
|
-
const jsxExpContainer = node.parent?.parent;
|
|
856
|
-
if (!AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
860
|
-
return;
|
|
861
|
-
}
|
|
862
|
-
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
863
|
-
return;
|
|
864
|
-
}
|
|
865
|
-
context.report({
|
|
866
|
-
messageId: "noComplexConditionalRendering",
|
|
867
|
-
node: jsxExpContainer
|
|
868
|
-
});
|
|
869
|
-
};
|
|
870
|
-
return {
|
|
871
|
-
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
872
|
-
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
873
|
-
"JSXExpressionContainer > LogicalExpression > ConditionalExpression": visitorFunction,
|
|
874
|
-
"JSXExpressionContainer > LogicalExpression[operator='&&'] > LogicalExpression[operator='||']": visitorFunction,
|
|
875
|
-
"JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
|
|
876
|
-
};
|
|
877
|
-
},
|
|
862
|
+
create: create12,
|
|
878
863
|
defaultOptions: []
|
|
879
864
|
});
|
|
865
|
+
function create12(context) {
|
|
866
|
+
const visitorFunction = (node) => {
|
|
867
|
+
const jsxExpContainer = node.parent?.parent;
|
|
868
|
+
if (!AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
context.report({
|
|
878
|
+
messageId: "noComplexConditionalRendering",
|
|
879
|
+
node: jsxExpContainer
|
|
880
|
+
});
|
|
881
|
+
};
|
|
882
|
+
return {
|
|
883
|
+
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
884
|
+
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
885
|
+
"JSXExpressionContainer > LogicalExpression > ConditionalExpression": visitorFunction,
|
|
886
|
+
"JSXExpressionContainer > LogicalExpression[operator='&&'] > LogicalExpression[operator='||']": visitorFunction,
|
|
887
|
+
"JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
|
|
888
|
+
};
|
|
889
|
+
}
|
|
880
890
|
var RULE_NAME15 = "no-component-will-mount";
|
|
881
891
|
var RULE_FEATURES15 = [
|
|
882
892
|
"CHK",
|
|
@@ -899,37 +909,36 @@ var no_component_will_mount_default = createRule({
|
|
|
899
909
|
schema: []
|
|
900
910
|
},
|
|
901
911
|
name: RULE_NAME15,
|
|
902
|
-
create
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
return fixer.replaceText(member.key, "UNSAFE_componentWillMount");
|
|
912
|
+
create: create13,
|
|
913
|
+
defaultOptions: []
|
|
914
|
+
});
|
|
915
|
+
function create13(context) {
|
|
916
|
+
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
917
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
918
|
+
return {
|
|
919
|
+
...listeners,
|
|
920
|
+
"Program:exit"(node) {
|
|
921
|
+
const components = ctx.getAllComponents(node);
|
|
922
|
+
for (const { node: component } of components.values()) {
|
|
923
|
+
const { body } = component.body;
|
|
924
|
+
for (const member of body) {
|
|
925
|
+
if (isComponentWillMount(member)) {
|
|
926
|
+
context.report({
|
|
927
|
+
messageId: "noComponentWillMount",
|
|
928
|
+
node: member,
|
|
929
|
+
fix(fixer) {
|
|
930
|
+
if (!("key" in member)) {
|
|
931
|
+
return null;
|
|
923
932
|
}
|
|
924
|
-
|
|
925
|
-
|
|
933
|
+
return fixer.replaceText(member.key, "UNSAFE_componentWillMount");
|
|
934
|
+
}
|
|
935
|
+
});
|
|
926
936
|
}
|
|
927
937
|
}
|
|
928
938
|
}
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
});
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
}
|
|
933
942
|
var RULE_NAME16 = "no-component-will-receive-props";
|
|
934
943
|
var RULE_FEATURES16 = [
|
|
935
944
|
"CHK",
|
|
@@ -952,37 +961,36 @@ var no_component_will_receive_props_default = createRule({
|
|
|
952
961
|
schema: []
|
|
953
962
|
},
|
|
954
963
|
name: RULE_NAME16,
|
|
955
|
-
create
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
return fixer.replaceText(member.key, "UNSAFE_componentWillReceiveProps");
|
|
964
|
+
create: create14,
|
|
965
|
+
defaultOptions: []
|
|
966
|
+
});
|
|
967
|
+
function create14(context) {
|
|
968
|
+
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
969
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
970
|
+
return {
|
|
971
|
+
...listeners,
|
|
972
|
+
"Program:exit"(node) {
|
|
973
|
+
const components = ctx.getAllComponents(node);
|
|
974
|
+
for (const { node: component } of components.values()) {
|
|
975
|
+
const { body } = component.body;
|
|
976
|
+
for (const member of body) {
|
|
977
|
+
if (isComponentWillUpdate(member)) {
|
|
978
|
+
context.report({
|
|
979
|
+
messageId: "noComponentWillReceiveProps",
|
|
980
|
+
node: member,
|
|
981
|
+
fix(fixer) {
|
|
982
|
+
if (!("key" in member)) {
|
|
983
|
+
return null;
|
|
976
984
|
}
|
|
977
|
-
|
|
978
|
-
|
|
985
|
+
return fixer.replaceText(member.key, "UNSAFE_componentWillReceiveProps");
|
|
986
|
+
}
|
|
987
|
+
});
|
|
979
988
|
}
|
|
980
989
|
}
|
|
981
990
|
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
});
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
}
|
|
986
994
|
var RULE_NAME17 = "no-component-will-update";
|
|
987
995
|
var RULE_FEATURES17 = [
|
|
988
996
|
"CHK",
|
|
@@ -1005,37 +1013,36 @@ var no_component_will_update_default = createRule({
|
|
|
1005
1013
|
schema: []
|
|
1006
1014
|
},
|
|
1007
1015
|
name: RULE_NAME17,
|
|
1008
|
-
create
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
return fixer.replaceText(member.key, "UNSAFE_componentWillUpdate");
|
|
1016
|
+
create: create15,
|
|
1017
|
+
defaultOptions: []
|
|
1018
|
+
});
|
|
1019
|
+
function create15(context) {
|
|
1020
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1021
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
1022
|
+
return {
|
|
1023
|
+
...listeners,
|
|
1024
|
+
"Program:exit"(node) {
|
|
1025
|
+
const components = ctx.getAllComponents(node);
|
|
1026
|
+
for (const { node: component } of components.values()) {
|
|
1027
|
+
const { body } = component.body;
|
|
1028
|
+
for (const member of body) {
|
|
1029
|
+
if (isComponentWillUpdate2(member)) {
|
|
1030
|
+
context.report({
|
|
1031
|
+
messageId: "noComponentWillUpdate",
|
|
1032
|
+
node: member,
|
|
1033
|
+
fix(fixer) {
|
|
1034
|
+
if (!("key" in member)) {
|
|
1035
|
+
return null;
|
|
1029
1036
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1037
|
+
return fixer.replaceText(member.key, "UNSAFE_componentWillUpdate");
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1032
1040
|
}
|
|
1033
1041
|
}
|
|
1034
1042
|
}
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
});
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1039
1046
|
var RULE_NAME18 = "no-context-provider";
|
|
1040
1047
|
var RULE_FEATURES18 = [
|
|
1041
1048
|
"CHK",
|
|
@@ -1055,40 +1062,41 @@ var no_context_provider_default = createRule({
|
|
|
1055
1062
|
schema: []
|
|
1056
1063
|
},
|
|
1057
1064
|
name: RULE_NAME18,
|
|
1058
|
-
create
|
|
1059
|
-
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
1060
|
-
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1061
|
-
if (compareVersions.compare(version2, "19.0.0", "<")) return {};
|
|
1062
|
-
return {
|
|
1063
|
-
JSXElement(node) {
|
|
1064
|
-
const fullName = JSX8__namespace.getElementType(node);
|
|
1065
|
-
const parts = fullName.split(".");
|
|
1066
|
-
const selfName = parts.pop();
|
|
1067
|
-
const contextFullName = parts.join(".");
|
|
1068
|
-
const contextSelfName = parts.pop();
|
|
1069
|
-
if (selfName !== "Provider") return;
|
|
1070
|
-
context.report({
|
|
1071
|
-
messageId: "noContextProvider",
|
|
1072
|
-
node,
|
|
1073
|
-
fix(fixer) {
|
|
1074
|
-
if (contextSelfName == null) return null;
|
|
1075
|
-
if (!core.isComponentNameLoose(contextSelfName)) return null;
|
|
1076
|
-
const openingElement = node.openingElement;
|
|
1077
|
-
const closingElement = node.closingElement;
|
|
1078
|
-
if (closingElement == null) {
|
|
1079
|
-
return fixer.replaceText(openingElement.name, contextFullName);
|
|
1080
|
-
}
|
|
1081
|
-
return [
|
|
1082
|
-
fixer.replaceText(openingElement.name, contextFullName),
|
|
1083
|
-
fixer.replaceText(closingElement.name, contextFullName)
|
|
1084
|
-
];
|
|
1085
|
-
}
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
};
|
|
1089
|
-
},
|
|
1065
|
+
create: create16,
|
|
1090
1066
|
defaultOptions: []
|
|
1091
1067
|
});
|
|
1068
|
+
function create16(context) {
|
|
1069
|
+
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
1070
|
+
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1071
|
+
if (compareVersions.compare(version2, "19.0.0", "<")) return {};
|
|
1072
|
+
return {
|
|
1073
|
+
JSXElement(node) {
|
|
1074
|
+
const fullName = JSX8__namespace.getElementType(node);
|
|
1075
|
+
const parts = fullName.split(".");
|
|
1076
|
+
const selfName = parts.pop();
|
|
1077
|
+
const contextFullName = parts.join(".");
|
|
1078
|
+
const contextSelfName = parts.pop();
|
|
1079
|
+
if (selfName !== "Provider") return;
|
|
1080
|
+
context.report({
|
|
1081
|
+
messageId: "noContextProvider",
|
|
1082
|
+
node,
|
|
1083
|
+
fix(fixer) {
|
|
1084
|
+
if (contextSelfName == null) return null;
|
|
1085
|
+
if (!core.isComponentNameLoose(contextSelfName)) return null;
|
|
1086
|
+
const openingElement = node.openingElement;
|
|
1087
|
+
const closingElement = node.closingElement;
|
|
1088
|
+
if (closingElement == null) {
|
|
1089
|
+
return fixer.replaceText(openingElement.name, contextFullName);
|
|
1090
|
+
}
|
|
1091
|
+
return [
|
|
1092
|
+
fixer.replaceText(openingElement.name, contextFullName),
|
|
1093
|
+
fixer.replaceText(closingElement.name, contextFullName)
|
|
1094
|
+
];
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1092
1100
|
var RULE_NAME19 = "no-create-ref";
|
|
1093
1101
|
var RULE_FEATURES19 = [
|
|
1094
1102
|
"CHK"
|
|
@@ -1106,17 +1114,18 @@ var no_create_ref_default = createRule({
|
|
|
1106
1114
|
schema: []
|
|
1107
1115
|
},
|
|
1108
1116
|
name: RULE_NAME19,
|
|
1109
|
-
create
|
|
1110
|
-
return {
|
|
1111
|
-
CallExpression(node) {
|
|
1112
|
-
if (core.isCreateRefCall(context, node) && AST11__namespace.findParentNode(node, core.isClassComponent) == null) {
|
|
1113
|
-
context.report({ messageId: "noCreateRef", node });
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
};
|
|
1117
|
-
},
|
|
1117
|
+
create: create17,
|
|
1118
1118
|
defaultOptions: []
|
|
1119
1119
|
});
|
|
1120
|
+
function create17(context) {
|
|
1121
|
+
return {
|
|
1122
|
+
CallExpression(node) {
|
|
1123
|
+
if (core.isCreateRefCall(context, node) && AST11__namespace.findParentNode(node, core.isClassComponent) == null) {
|
|
1124
|
+
context.report({ messageId: "noCreateRef", node });
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1120
1129
|
var RULE_NAME20 = "no-default-props";
|
|
1121
1130
|
var RULE_FEATURES20 = [
|
|
1122
1131
|
"CHK"
|
|
@@ -1134,44 +1143,43 @@ var no_default_props_default = createRule({
|
|
|
1134
1143
|
schema: []
|
|
1135
1144
|
},
|
|
1136
1145
|
name: RULE_NAME20,
|
|
1137
|
-
create
|
|
1138
|
-
if (!context.sourceCode.text.includes("defaultProps")) {
|
|
1139
|
-
return {};
|
|
1140
|
-
}
|
|
1141
|
-
return {
|
|
1142
|
-
AssignmentExpression(node) {
|
|
1143
|
-
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
const { object, property } = node.left;
|
|
1147
|
-
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
if (!core.isComponentNameLoose(object.name)) {
|
|
1154
|
-
return;
|
|
1155
|
-
}
|
|
1156
|
-
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1157
|
-
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
1158
|
-
if (variableNode == null) return;
|
|
1159
|
-
if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
|
|
1160
|
-
context.report({ messageId: "noDefaultProps", node: property });
|
|
1161
|
-
},
|
|
1162
|
-
PropertyDefinition(node) {
|
|
1163
|
-
if (!core.isClassComponent(node.parent.parent)) {
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
context.report({ messageId: "noDefaultProps", node });
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
},
|
|
1146
|
+
create: create18,
|
|
1173
1147
|
defaultOptions: []
|
|
1174
1148
|
});
|
|
1149
|
+
function create18(context) {
|
|
1150
|
+
if (!context.sourceCode.text.includes("defaultProps")) return {};
|
|
1151
|
+
return {
|
|
1152
|
+
AssignmentExpression(node) {
|
|
1153
|
+
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
const { object, property } = node.left;
|
|
1157
|
+
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
if (!core.isComponentNameLoose(object.name)) {
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1167
|
+
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
1168
|
+
if (variableNode == null) return;
|
|
1169
|
+
if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
|
|
1170
|
+
context.report({ messageId: "noDefaultProps", node: property });
|
|
1171
|
+
},
|
|
1172
|
+
PropertyDefinition(node) {
|
|
1173
|
+
if (!core.isClassComponent(node.parent.parent)) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
context.report({ messageId: "noDefaultProps", node });
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1175
1183
|
var RULE_NAME21 = "no-direct-mutation-state";
|
|
1176
1184
|
var RULE_FEATURES21 = [
|
|
1177
1185
|
"CHK"
|
|
@@ -1192,31 +1200,30 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1192
1200
|
schema: []
|
|
1193
1201
|
},
|
|
1194
1202
|
name: RULE_NAME21,
|
|
1195
|
-
create
|
|
1196
|
-
return {
|
|
1197
|
-
AssignmentExpression(node) {
|
|
1198
|
-
if (!core.isAssignmentToThisState(node)) {
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
const parentClass = AST11__namespace.findParentNode(
|
|
1202
|
-
node,
|
|
1203
|
-
AST11__namespace.isOneOf([
|
|
1204
|
-
types.AST_NODE_TYPES.ClassDeclaration,
|
|
1205
|
-
types.AST_NODE_TYPES.ClassExpression
|
|
1206
|
-
])
|
|
1207
|
-
);
|
|
1208
|
-
if (parentClass == null) return;
|
|
1209
|
-
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1210
|
-
context.report({
|
|
1211
|
-
messageId: "noDirectMutationState",
|
|
1212
|
-
node
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
};
|
|
1217
|
-
},
|
|
1203
|
+
create: create19,
|
|
1218
1204
|
defaultOptions: []
|
|
1219
1205
|
});
|
|
1206
|
+
function create19(context) {
|
|
1207
|
+
return {
|
|
1208
|
+
AssignmentExpression(node) {
|
|
1209
|
+
if (!core.isAssignmentToThisState(node)) return;
|
|
1210
|
+
const parentClass = AST11__namespace.findParentNode(
|
|
1211
|
+
node,
|
|
1212
|
+
AST11__namespace.isOneOf([
|
|
1213
|
+
types.AST_NODE_TYPES.ClassDeclaration,
|
|
1214
|
+
types.AST_NODE_TYPES.ClassExpression
|
|
1215
|
+
])
|
|
1216
|
+
);
|
|
1217
|
+
if (parentClass == null) return;
|
|
1218
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1219
|
+
context.report({
|
|
1220
|
+
messageId: "noDirectMutationState",
|
|
1221
|
+
node
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1220
1227
|
var RULE_NAME22 = "no-duplicate-jsx-props";
|
|
1221
1228
|
var RULE_FEATURES22 = [
|
|
1222
1229
|
"CHK"
|
|
@@ -1234,32 +1241,33 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1234
1241
|
schema: []
|
|
1235
1242
|
},
|
|
1236
1243
|
name: RULE_NAME22,
|
|
1237
|
-
create
|
|
1238
|
-
return {
|
|
1239
|
-
JSXOpeningElement(node) {
|
|
1240
|
-
const props = [];
|
|
1241
|
-
for (const attr of node.attributes) {
|
|
1242
|
-
if (attr.type === types.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1243
|
-
continue;
|
|
1244
|
-
}
|
|
1245
|
-
const name5 = attr.name.name;
|
|
1246
|
-
if (typeof name5 !== "string") {
|
|
1247
|
-
continue;
|
|
1248
|
-
}
|
|
1249
|
-
if (!props.includes(name5)) {
|
|
1250
|
-
props.push(name5);
|
|
1251
|
-
continue;
|
|
1252
|
-
}
|
|
1253
|
-
context.report({
|
|
1254
|
-
messageId: "noDuplicateJsxProps",
|
|
1255
|
-
node: attr
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
};
|
|
1260
|
-
},
|
|
1244
|
+
create: create20,
|
|
1261
1245
|
defaultOptions: []
|
|
1262
1246
|
});
|
|
1247
|
+
function create20(context) {
|
|
1248
|
+
return {
|
|
1249
|
+
JSXOpeningElement(node) {
|
|
1250
|
+
const props = [];
|
|
1251
|
+
for (const attr of node.attributes) {
|
|
1252
|
+
if (attr.type === types.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
const name5 = attr.name.name;
|
|
1256
|
+
if (typeof name5 !== "string") {
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
if (!props.includes(name5)) {
|
|
1260
|
+
props.push(name5);
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
context.report({
|
|
1264
|
+
messageId: "noDuplicateJsxProps",
|
|
1265
|
+
node: attr
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1263
1271
|
var RULE_NAME23 = "no-duplicate-key";
|
|
1264
1272
|
var RULE_FEATURES23 = [
|
|
1265
1273
|
"CHK"
|
|
@@ -1277,72 +1285,73 @@ var no_duplicate_key_default = createRule({
|
|
|
1277
1285
|
schema: []
|
|
1278
1286
|
},
|
|
1279
1287
|
name: RULE_NAME23,
|
|
1280
|
-
create
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1288
|
+
create: create21,
|
|
1289
|
+
defaultOptions: []
|
|
1290
|
+
});
|
|
1291
|
+
function create21(context) {
|
|
1292
|
+
if (!context.sourceCode.getText().includes("key=")) {
|
|
1293
|
+
return {};
|
|
1294
|
+
}
|
|
1295
|
+
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1296
|
+
function isKeyValueEqual(a, b) {
|
|
1297
|
+
const aValue = a.value;
|
|
1298
|
+
const bValue = b.value;
|
|
1299
|
+
if (aValue == null || bValue == null) {
|
|
1300
|
+
return false;
|
|
1292
1301
|
}
|
|
1293
|
-
return
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
hasDuplicate: node.value?.type === types.AST_NODE_TYPES.Literal,
|
|
1320
|
-
keys: [node],
|
|
1321
|
-
root: call
|
|
1322
|
-
});
|
|
1302
|
+
return AST11__namespace.isNodeEqual(aValue, bValue);
|
|
1303
|
+
}
|
|
1304
|
+
return {
|
|
1305
|
+
"JSXAttribute[name.name='key']"(node) {
|
|
1306
|
+
const jsxElement = node.parent.parent;
|
|
1307
|
+
switch (jsxElement.parent.type) {
|
|
1308
|
+
case types.AST_NODE_TYPES.ArrayExpression:
|
|
1309
|
+
case types.AST_NODE_TYPES.JSXElement:
|
|
1310
|
+
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1311
|
+
const root = jsxElement.parent;
|
|
1312
|
+
const prevKeys = keyedEntries.get(root)?.keys ?? [];
|
|
1313
|
+
keyedEntries.set(root, {
|
|
1314
|
+
hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, node)),
|
|
1315
|
+
keys: [...prevKeys, node],
|
|
1316
|
+
root: jsxElement.parent
|
|
1317
|
+
});
|
|
1318
|
+
break;
|
|
1319
|
+
}
|
|
1320
|
+
default: {
|
|
1321
|
+
const call = AST11__namespace.findParentNode(jsxElement, AST11__namespace.isMapCallLoose);
|
|
1322
|
+
const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
|
|
1323
|
+
if (!AST11__namespace.isFunction(iter)) return;
|
|
1324
|
+
const arg0 = call?.arguments[0];
|
|
1325
|
+
if (call == null || arg0 == null) return;
|
|
1326
|
+
if (AST11__namespace.getEcmaExpression(arg0) !== iter) {
|
|
1327
|
+
return;
|
|
1323
1328
|
}
|
|
1329
|
+
keyedEntries.set(call, {
|
|
1330
|
+
hasDuplicate: node.value?.type === types.AST_NODE_TYPES.Literal,
|
|
1331
|
+
keys: [node],
|
|
1332
|
+
root: call
|
|
1333
|
+
});
|
|
1324
1334
|
}
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1335
|
+
}
|
|
1336
|
+
},
|
|
1337
|
+
"Program:exit"() {
|
|
1338
|
+
for (const { hasDuplicate, keys } of keyedEntries.values()) {
|
|
1339
|
+
if (!hasDuplicate) {
|
|
1340
|
+
continue;
|
|
1341
|
+
}
|
|
1342
|
+
for (const key of keys) {
|
|
1343
|
+
context.report({
|
|
1344
|
+
messageId: "noDuplicateKey",
|
|
1345
|
+
node: key,
|
|
1346
|
+
data: {
|
|
1347
|
+
value: context.sourceCode.getText(key)
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1340
1350
|
}
|
|
1341
1351
|
}
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
});
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1346
1355
|
var RULE_NAME24 = "no-forward-ref";
|
|
1347
1356
|
var RULE_FEATURES24 = [
|
|
1348
1357
|
"CHK",
|
|
@@ -1362,29 +1371,30 @@ var no_forward_ref_default = createRule({
|
|
|
1362
1371
|
schema: []
|
|
1363
1372
|
},
|
|
1364
1373
|
name: RULE_NAME24,
|
|
1365
|
-
create
|
|
1366
|
-
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1367
|
-
return {};
|
|
1368
|
-
}
|
|
1369
|
-
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1370
|
-
if (compareVersions.compare(version2, "19.0.0", "<")) {
|
|
1371
|
-
return {};
|
|
1372
|
-
}
|
|
1373
|
-
return {
|
|
1374
|
-
CallExpression(node) {
|
|
1375
|
-
if (!core.isForwardRefCall(context, node)) {
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1378
|
-
context.report({
|
|
1379
|
-
messageId: "noForwardRef",
|
|
1380
|
-
node,
|
|
1381
|
-
fix: getFix(context, node)
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
},
|
|
1374
|
+
create: create22,
|
|
1386
1375
|
defaultOptions: []
|
|
1387
1376
|
});
|
|
1377
|
+
function create22(context) {
|
|
1378
|
+
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1379
|
+
return {};
|
|
1380
|
+
}
|
|
1381
|
+
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1382
|
+
if (compareVersions.compare(version2, "19.0.0", "<")) {
|
|
1383
|
+
return {};
|
|
1384
|
+
}
|
|
1385
|
+
return {
|
|
1386
|
+
CallExpression(node) {
|
|
1387
|
+
if (!core.isForwardRefCall(context, node)) {
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
context.report({
|
|
1391
|
+
messageId: "noForwardRef",
|
|
1392
|
+
node,
|
|
1393
|
+
fix: getFix(context, node)
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1388
1398
|
function getFix(context, node) {
|
|
1389
1399
|
return (fixer) => {
|
|
1390
1400
|
const [componentNode] = node.arguments;
|
|
@@ -1469,22 +1479,23 @@ var no_implicit_key_default = createRule({
|
|
|
1469
1479
|
schema: []
|
|
1470
1480
|
},
|
|
1471
1481
|
name: RULE_NAME25,
|
|
1472
|
-
create
|
|
1473
|
-
return {
|
|
1474
|
-
JSXOpeningElement(node) {
|
|
1475
|
-
const initialScope = context.sourceCode.getScope(node);
|
|
1476
|
-
const keyPropFound = JSX8__namespace.getAttribute("key", node.attributes, initialScope);
|
|
1477
|
-
const keyPropOnElement = node.attributes.some(
|
|
1478
|
-
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1479
|
-
);
|
|
1480
|
-
if (keyPropFound != null && !keyPropOnElement) {
|
|
1481
|
-
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
},
|
|
1482
|
+
create: create23,
|
|
1486
1483
|
defaultOptions: []
|
|
1487
1484
|
});
|
|
1485
|
+
function create23(context) {
|
|
1486
|
+
return {
|
|
1487
|
+
JSXOpeningElement(node) {
|
|
1488
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1489
|
+
const keyPropFound = JSX8__namespace.getAttribute("key", node.attributes, initialScope);
|
|
1490
|
+
const keyPropOnElement = node.attributes.some(
|
|
1491
|
+
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1492
|
+
);
|
|
1493
|
+
if (keyPropFound != null && !keyPropOnElement) {
|
|
1494
|
+
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1488
1499
|
var RULE_NAME26 = "no-leaked-conditional-rendering";
|
|
1489
1500
|
var RULE_FEATURES26 = [
|
|
1490
1501
|
"CHK",
|
|
@@ -1581,71 +1592,70 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1581
1592
|
schema: []
|
|
1582
1593
|
},
|
|
1583
1594
|
name: RULE_NAME26,
|
|
1584
|
-
create
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
]
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
messageId: "noLeakedConditionalRendering",
|
|
1614
|
-
node: left,
|
|
1615
|
-
data: { value: context.sourceCode.getText(left) }
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
const leftType = typeUtils.getConstrainedTypeAtLocation(services, left);
|
|
1619
|
-
const leftTypeVariants = inspectVariantTypes(tsApiUtils.unionTypeParts(leftType));
|
|
1620
|
-
const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
|
|
1621
|
-
if (isLeftValid) {
|
|
1622
|
-
return getReportDescriptor(right);
|
|
1623
|
-
}
|
|
1595
|
+
create: create24,
|
|
1596
|
+
defaultOptions: []
|
|
1597
|
+
});
|
|
1598
|
+
function create24(context) {
|
|
1599
|
+
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) return {};
|
|
1600
|
+
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
1601
|
+
const allowedVariants = [
|
|
1602
|
+
"any",
|
|
1603
|
+
"boolean",
|
|
1604
|
+
"nullish",
|
|
1605
|
+
"object",
|
|
1606
|
+
"falsy boolean",
|
|
1607
|
+
"truthy bigint",
|
|
1608
|
+
"truthy boolean",
|
|
1609
|
+
"truthy number",
|
|
1610
|
+
"truthy string",
|
|
1611
|
+
...compareVersions.compare(version2, "18.0.0", "<") ? [] : ["string", "falsy string"]
|
|
1612
|
+
];
|
|
1613
|
+
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
1614
|
+
function getReportDescriptor(node) {
|
|
1615
|
+
if (node == null) return eff._;
|
|
1616
|
+
return tsPattern.match(node).when(AST11__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1617
|
+
const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1618
|
+
if (isLeftUnaryNot) {
|
|
1619
|
+
return getReportDescriptor(right);
|
|
1620
|
+
}
|
|
1621
|
+
const initialScope = context.sourceCode.getScope(left);
|
|
1622
|
+
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1623
|
+
if (isLeftNan) {
|
|
1624
1624
|
return {
|
|
1625
1625
|
messageId: "noLeakedConditionalRendering",
|
|
1626
1626
|
node: left,
|
|
1627
1627
|
data: { value: context.sourceCode.getText(left) }
|
|
1628
1628
|
};
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
return getReportDescriptor(
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1629
|
+
}
|
|
1630
|
+
const leftType = typeUtils.getConstrainedTypeAtLocation(services, left);
|
|
1631
|
+
const leftTypeVariants = inspectVariantTypes(tsApiUtils.unionTypeParts(leftType));
|
|
1632
|
+
const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
|
|
1633
|
+
if (isLeftValid) {
|
|
1634
|
+
return getReportDescriptor(right);
|
|
1635
|
+
}
|
|
1636
|
+
return {
|
|
1637
|
+
messageId: "noLeakedConditionalRendering",
|
|
1638
|
+
node: left,
|
|
1639
|
+
data: { value: context.sourceCode.getText(left) }
|
|
1640
|
+
};
|
|
1641
|
+
}).with({ type: types.AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
|
|
1642
|
+
return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
|
|
1643
|
+
}).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
1644
|
+
const variable = VAR__namespace.findVariable(n.name, context.sourceCode.getScope(n));
|
|
1645
|
+
const initExpression = tsPattern.match(variable?.defs.at(0)?.node).with({ init: tsPattern.P.select({ type: tsPattern.P.not(types.AST_NODE_TYPES.VariableDeclaration) }) }, eff.identity).otherwise(() => eff._);
|
|
1646
|
+
return getReportDescriptor(initExpression);
|
|
1647
|
+
}).otherwise(() => eff._);
|
|
1648
|
+
}
|
|
1649
|
+
const visitorFunction = (node) => {
|
|
1650
|
+
const descriptor = getReportDescriptor(node);
|
|
1651
|
+
if (descriptor == null) return;
|
|
1652
|
+
context.report(descriptor);
|
|
1653
|
+
};
|
|
1654
|
+
return {
|
|
1655
|
+
"JSXExpressionContainer > ConditionalExpression": visitorFunction,
|
|
1656
|
+
"JSXExpressionContainer > LogicalExpression": visitorFunction
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1649
1659
|
var RULE_NAME27 = "no-missing-component-display-name";
|
|
1650
1660
|
var RULE_FEATURES27 = [
|
|
1651
1661
|
"CHK"
|
|
@@ -1663,45 +1673,44 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1663
1673
|
schema: []
|
|
1664
1674
|
},
|
|
1665
1675
|
name: RULE_NAME27,
|
|
1666
|
-
create
|
|
1667
|
-
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1668
|
-
return {};
|
|
1669
|
-
}
|
|
1670
|
-
const {
|
|
1671
|
-
ctx,
|
|
1672
|
-
listeners
|
|
1673
|
-
} = core.useComponentCollector(
|
|
1674
|
-
context,
|
|
1675
|
-
{
|
|
1676
|
-
collectDisplayName: true,
|
|
1677
|
-
collectHookCalls: false,
|
|
1678
|
-
hint: core.DEFAULT_COMPONENT_HINT
|
|
1679
|
-
}
|
|
1680
|
-
);
|
|
1681
|
-
return {
|
|
1682
|
-
...listeners,
|
|
1683
|
-
"Program:exit"(node) {
|
|
1684
|
-
const components = ctx.getAllComponents(node);
|
|
1685
|
-
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1686
|
-
const isMemoOrForwardRef = (flag & (core.ERComponentFlag.ForwardRef | core.ERComponentFlag.Memo)) > 0n;
|
|
1687
|
-
if (AST11__namespace.getFunctionIdentifier(node2) != null) {
|
|
1688
|
-
continue;
|
|
1689
|
-
}
|
|
1690
|
-
if (!isMemoOrForwardRef) {
|
|
1691
|
-
continue;
|
|
1692
|
-
}
|
|
1693
|
-
if (displayName == null) {
|
|
1694
|
-
context.report({
|
|
1695
|
-
messageId: "noMissingComponentDisplayName",
|
|
1696
|
-
node: node2
|
|
1697
|
-
});
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
};
|
|
1702
|
-
},
|
|
1676
|
+
create: create25,
|
|
1703
1677
|
defaultOptions: []
|
|
1704
1678
|
});
|
|
1679
|
+
function create25(context) {
|
|
1680
|
+
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1681
|
+
const {
|
|
1682
|
+
ctx,
|
|
1683
|
+
listeners
|
|
1684
|
+
} = core.useComponentCollector(
|
|
1685
|
+
context,
|
|
1686
|
+
{
|
|
1687
|
+
collectDisplayName: true,
|
|
1688
|
+
collectHookCalls: false,
|
|
1689
|
+
hint: core.DEFAULT_COMPONENT_HINT
|
|
1690
|
+
}
|
|
1691
|
+
);
|
|
1692
|
+
return {
|
|
1693
|
+
...listeners,
|
|
1694
|
+
"Program:exit"(node) {
|
|
1695
|
+
const components = ctx.getAllComponents(node);
|
|
1696
|
+
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1697
|
+
const isMemoOrForwardRef = (flag & (core.ERComponentFlag.ForwardRef | core.ERComponentFlag.Memo)) > 0n;
|
|
1698
|
+
if (AST11__namespace.getFunctionIdentifier(node2) != null) {
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
if (!isMemoOrForwardRef) {
|
|
1702
|
+
continue;
|
|
1703
|
+
}
|
|
1704
|
+
if (displayName == null) {
|
|
1705
|
+
context.report({
|
|
1706
|
+
messageId: "noMissingComponentDisplayName",
|
|
1707
|
+
node: node2
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1705
1714
|
var RULE_NAME28 = "no-missing-context-display-name";
|
|
1706
1715
|
var RULE_FEATURES28 = [
|
|
1707
1716
|
"CHK"
|
|
@@ -1719,46 +1728,47 @@ var no_missing_context_display_name_default = createRule({
|
|
|
1719
1728
|
schema: []
|
|
1720
1729
|
},
|
|
1721
1730
|
name: RULE_NAME28,
|
|
1722
|
-
create
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1731
|
+
create: create26,
|
|
1732
|
+
defaultOptions: []
|
|
1733
|
+
});
|
|
1734
|
+
function create26(context) {
|
|
1735
|
+
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
1736
|
+
const createCalls = [];
|
|
1737
|
+
const displayNameAssignments = [];
|
|
1738
|
+
return {
|
|
1739
|
+
CallExpression(node) {
|
|
1740
|
+
if (!core.isCreateContextCall(context, node)) return;
|
|
1741
|
+
createCalls.push(node);
|
|
1742
|
+
},
|
|
1743
|
+
[core.DISPLAY_NAME_ASSIGNMENT_SELECTOR](node) {
|
|
1744
|
+
displayNameAssignments.push(node);
|
|
1745
|
+
},
|
|
1746
|
+
"Program:exit"() {
|
|
1747
|
+
for (const call of createCalls) {
|
|
1748
|
+
const id = core.getInstanceId(call);
|
|
1749
|
+
if (id == null) {
|
|
1750
|
+
context.report({
|
|
1751
|
+
messageId: "noMissingContextDisplayName",
|
|
1752
|
+
node: call
|
|
1753
|
+
});
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
const hasDisplayNameAssignment = displayNameAssignments.some((node) => {
|
|
1757
|
+
const left = node.left;
|
|
1758
|
+
if (left.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
1759
|
+
const object = left.object;
|
|
1760
|
+
return core.isInstanceIdEqual(context, id, object);
|
|
1761
|
+
});
|
|
1762
|
+
if (!hasDisplayNameAssignment) {
|
|
1763
|
+
context.report({
|
|
1764
|
+
messageId: "noMissingContextDisplayName",
|
|
1765
|
+
node: call
|
|
1749
1766
|
});
|
|
1750
|
-
if (!hasDisplayNameAssignment) {
|
|
1751
|
-
context.report({
|
|
1752
|
-
messageId: "noMissingContextDisplayName",
|
|
1753
|
-
node: call
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
1767
|
}
|
|
1757
1768
|
}
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
});
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1762
1772
|
var RULE_NAME29 = "no-missing-key";
|
|
1763
1773
|
var RULE_FEATURES29 = [
|
|
1764
1774
|
"CHK"
|
|
@@ -1777,126 +1787,127 @@ var no_missing_key_default = createRule({
|
|
|
1777
1787
|
schema: []
|
|
1778
1788
|
},
|
|
1779
1789
|
name: RULE_NAME29,
|
|
1780
|
-
create
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
return null;
|
|
1793
|
-
}
|
|
1794
|
-
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1790
|
+
create: create27,
|
|
1791
|
+
defaultOptions: []
|
|
1792
|
+
});
|
|
1793
|
+
function create27(context) {
|
|
1794
|
+
const state = { isWithinChildrenToArray: false };
|
|
1795
|
+
function checkIteratorElement(node) {
|
|
1796
|
+
switch (node.type) {
|
|
1797
|
+
case types.AST_NODE_TYPES.JSXElement: {
|
|
1798
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1799
|
+
if (!JSX8__namespace.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1795
1800
|
return {
|
|
1796
|
-
messageId: "
|
|
1801
|
+
messageId: "missingKey",
|
|
1797
1802
|
node
|
|
1798
1803
|
};
|
|
1799
1804
|
}
|
|
1800
|
-
|
|
1801
|
-
return null;
|
|
1805
|
+
return null;
|
|
1802
1806
|
}
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
return checkIteratorElement(node.consequent) ?? checkIteratorElement(node.alternate);
|
|
1809
|
-
}
|
|
1810
|
-
return null;
|
|
1811
|
-
case types.AST_NODE_TYPES.JSXElement:
|
|
1812
|
-
case types.AST_NODE_TYPES.JSXFragment:
|
|
1813
|
-
return checkIteratorElement(node);
|
|
1814
|
-
case types.AST_NODE_TYPES.LogicalExpression:
|
|
1815
|
-
if ("left" in node) {
|
|
1816
|
-
return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
|
|
1817
|
-
}
|
|
1818
|
-
return null;
|
|
1819
|
-
default:
|
|
1820
|
-
return null;
|
|
1807
|
+
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1808
|
+
return {
|
|
1809
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1810
|
+
node
|
|
1811
|
+
};
|
|
1821
1812
|
}
|
|
1813
|
+
default:
|
|
1814
|
+
return null;
|
|
1822
1815
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1816
|
+
}
|
|
1817
|
+
function checkExpression(node) {
|
|
1818
|
+
switch (node.type) {
|
|
1819
|
+
case types.AST_NODE_TYPES.ConditionalExpression:
|
|
1820
|
+
if ("consequent" in node) {
|
|
1821
|
+
return checkIteratorElement(node.consequent) ?? checkIteratorElement(node.alternate);
|
|
1828
1822
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1823
|
+
return null;
|
|
1824
|
+
case types.AST_NODE_TYPES.JSXElement:
|
|
1825
|
+
case types.AST_NODE_TYPES.JSXFragment:
|
|
1826
|
+
return checkIteratorElement(node);
|
|
1827
|
+
case types.AST_NODE_TYPES.LogicalExpression:
|
|
1828
|
+
if ("left" in node) {
|
|
1829
|
+
return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
|
|
1832
1830
|
}
|
|
1831
|
+
return null;
|
|
1832
|
+
default:
|
|
1833
|
+
return null;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
function checkBlockStatement(node) {
|
|
1837
|
+
const descriptors = [];
|
|
1838
|
+
for (const statement of AST11__namespace.getNestedReturnStatements(node)) {
|
|
1839
|
+
if (statement.argument == null) {
|
|
1840
|
+
continue;
|
|
1841
|
+
}
|
|
1842
|
+
const descriptor = checkIteratorElement(statement.argument);
|
|
1843
|
+
if (descriptor != null) {
|
|
1844
|
+
descriptors.push(descriptor);
|
|
1833
1845
|
}
|
|
1834
|
-
return descriptors;
|
|
1835
1846
|
}
|
|
1836
|
-
return
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
node: element
|
|
1851
|
-
});
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
},
|
|
1855
|
-
CallExpression(node) {
|
|
1856
|
-
state.isWithinChildrenToArray ||= core.isChildrenToArrayCall(context, node);
|
|
1857
|
-
if (state.isWithinChildrenToArray) {
|
|
1858
|
-
return;
|
|
1859
|
-
}
|
|
1860
|
-
const isMapCallLike = AST11__namespace.isMapCallLoose(node);
|
|
1861
|
-
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
const fn = node.arguments[isMapCallLike ? 0 : 1];
|
|
1865
|
-
if (fn?.type !== types.AST_NODE_TYPES.ArrowFunctionExpression && fn?.type !== types.AST_NODE_TYPES.FunctionExpression) {
|
|
1866
|
-
return;
|
|
1867
|
-
}
|
|
1868
|
-
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
1869
|
-
for (const descriptor2 of checkBlockStatement(fn.body)) {
|
|
1870
|
-
context.report(descriptor2);
|
|
1871
|
-
}
|
|
1872
|
-
return;
|
|
1873
|
-
}
|
|
1874
|
-
const descriptor = checkExpression(fn.body);
|
|
1875
|
-
if (descriptor != null) {
|
|
1876
|
-
context.report(descriptor);
|
|
1877
|
-
}
|
|
1878
|
-
},
|
|
1879
|
-
"CallExpression:exit"(node) {
|
|
1880
|
-
if (!core.isChildrenToArrayCall(context, node)) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
state.isWithinChildrenToArray = false;
|
|
1884
|
-
},
|
|
1885
|
-
JSXFragment(node) {
|
|
1886
|
-
if (state.isWithinChildrenToArray) {
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
if (node.parent.type === types.AST_NODE_TYPES.ArrayExpression) {
|
|
1847
|
+
return descriptors;
|
|
1848
|
+
}
|
|
1849
|
+
return {
|
|
1850
|
+
ArrayExpression(node) {
|
|
1851
|
+
if (state.isWithinChildrenToArray) {
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
const elements = node.elements.filter(AST11__namespace.is(types.AST_NODE_TYPES.JSXElement));
|
|
1855
|
+
if (elements.length === 0) {
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1859
|
+
for (const element of elements) {
|
|
1860
|
+
if (!JSX8__namespace.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1890
1861
|
context.report({
|
|
1891
|
-
messageId: "
|
|
1892
|
-
node
|
|
1862
|
+
messageId: "missingKey",
|
|
1863
|
+
node: element
|
|
1893
1864
|
});
|
|
1894
1865
|
}
|
|
1895
1866
|
}
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1867
|
+
},
|
|
1868
|
+
CallExpression(node) {
|
|
1869
|
+
state.isWithinChildrenToArray ||= core.isChildrenToArrayCall(context, node);
|
|
1870
|
+
if (state.isWithinChildrenToArray) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
const isMapCallLike = AST11__namespace.isMapCallLoose(node);
|
|
1874
|
+
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
const fn = node.arguments[isMapCallLike ? 0 : 1];
|
|
1878
|
+
if (fn?.type !== types.AST_NODE_TYPES.ArrowFunctionExpression && fn?.type !== types.AST_NODE_TYPES.FunctionExpression) {
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
1882
|
+
for (const descriptor2 of checkBlockStatement(fn.body)) {
|
|
1883
|
+
context.report(descriptor2);
|
|
1884
|
+
}
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const descriptor = checkExpression(fn.body);
|
|
1888
|
+
if (descriptor != null) {
|
|
1889
|
+
context.report(descriptor);
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
"CallExpression:exit"(node) {
|
|
1893
|
+
if (!core.isChildrenToArrayCall(context, node)) {
|
|
1894
|
+
return;
|
|
1895
|
+
}
|
|
1896
|
+
state.isWithinChildrenToArray = false;
|
|
1897
|
+
},
|
|
1898
|
+
JSXFragment(node) {
|
|
1899
|
+
if (state.isWithinChildrenToArray) {
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
if (node.parent.type === types.AST_NODE_TYPES.ArrayExpression) {
|
|
1903
|
+
context.report({
|
|
1904
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1905
|
+
node
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1900
1911
|
function isArrayFromCall(node) {
|
|
1901
1912
|
return node.type === types.AST_NODE_TYPES.CallExpression && node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "from";
|
|
1902
1913
|
}
|
|
@@ -1918,48 +1929,40 @@ var no_nested_components_default = createRule({
|
|
|
1918
1929
|
schema: []
|
|
1919
1930
|
},
|
|
1920
1931
|
name: RULE_NAME30,
|
|
1921
|
-
create
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
data: {
|
|
1956
|
-
name: name5
|
|
1957
|
-
}
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
continue;
|
|
1961
|
-
}
|
|
1962
|
-
if (isInsideCreateElementProps(context, component)) {
|
|
1932
|
+
create: create28,
|
|
1933
|
+
defaultOptions: []
|
|
1934
|
+
});
|
|
1935
|
+
function create28(context) {
|
|
1936
|
+
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;
|
|
1937
|
+
const collector = core.useComponentCollector(context, { hint });
|
|
1938
|
+
const collectorLegacy = core.useComponentCollectorLegacy();
|
|
1939
|
+
return {
|
|
1940
|
+
...collector.listeners,
|
|
1941
|
+
...collectorLegacy.listeners,
|
|
1942
|
+
"Program:exit"(node) {
|
|
1943
|
+
const functionComponents = [
|
|
1944
|
+
...collector.ctx.getAllComponents(node).values()
|
|
1945
|
+
];
|
|
1946
|
+
const classComponents = [
|
|
1947
|
+
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
1948
|
+
];
|
|
1949
|
+
const isFunctionComponent = (node2) => {
|
|
1950
|
+
return AST11__namespace.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
1951
|
+
};
|
|
1952
|
+
const isClassComponent11 = (node2) => {
|
|
1953
|
+
return AST11__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1954
|
+
};
|
|
1955
|
+
for (const { name: name5, node: component } of functionComponents) {
|
|
1956
|
+
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
1957
|
+
continue;
|
|
1958
|
+
}
|
|
1959
|
+
if (name5 == null) {
|
|
1960
|
+
continue;
|
|
1961
|
+
}
|
|
1962
|
+
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1963
|
+
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX8__namespace.findParentAttribute(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1964
|
+
if (isInsideJSXPropValue) {
|
|
1965
|
+
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1963
1966
|
context.report({
|
|
1964
1967
|
messageId: "nestedComponentInProps",
|
|
1965
1968
|
node: component,
|
|
@@ -1967,34 +1970,32 @@ var no_nested_components_default = createRule({
|
|
|
1967
1970
|
name: name5
|
|
1968
1971
|
}
|
|
1969
1972
|
});
|
|
1970
|
-
continue;
|
|
1971
|
-
}
|
|
1972
|
-
const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
|
|
1973
|
-
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1974
|
-
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
1975
|
-
context.report({
|
|
1976
|
-
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
1977
|
-
node: component,
|
|
1978
|
-
data: {
|
|
1979
|
-
name: name5
|
|
1980
|
-
}
|
|
1981
|
-
});
|
|
1982
|
-
continue;
|
|
1983
|
-
}
|
|
1984
|
-
if (core.isInsideRenderMethod(component)) {
|
|
1985
|
-
context.report({
|
|
1986
|
-
messageId: "nestedComponent",
|
|
1987
|
-
node: component,
|
|
1988
|
-
data: {
|
|
1989
|
-
name: name5
|
|
1990
|
-
}
|
|
1991
|
-
});
|
|
1992
1973
|
}
|
|
1974
|
+
continue;
|
|
1993
1975
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1976
|
+
if (isInsideCreateElementProps(context, component)) {
|
|
1977
|
+
context.report({
|
|
1978
|
+
messageId: "nestedComponentInProps",
|
|
1979
|
+
node: component,
|
|
1980
|
+
data: {
|
|
1981
|
+
name: name5
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1986
|
+
const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
|
|
1987
|
+
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1988
|
+
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
1989
|
+
context.report({
|
|
1990
|
+
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
1991
|
+
node: component,
|
|
1992
|
+
data: {
|
|
1993
|
+
name: name5
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
continue;
|
|
1997
|
+
}
|
|
1998
|
+
if (core.isInsideRenderMethod(component)) {
|
|
1998
1999
|
context.report({
|
|
1999
2000
|
messageId: "nestedComponent",
|
|
2000
2001
|
node: component,
|
|
@@ -2004,10 +2005,21 @@ var no_nested_components_default = createRule({
|
|
|
2004
2005
|
});
|
|
2005
2006
|
}
|
|
2006
2007
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
}
|
|
2008
|
+
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2009
|
+
if (AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
context.report({
|
|
2013
|
+
messageId: "nestedComponent",
|
|
2014
|
+
node: component,
|
|
2015
|
+
data: {
|
|
2016
|
+
name: name5
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2011
2023
|
function isInsideCreateElementProps(context, node) {
|
|
2012
2024
|
const call = AST11__namespace.findParentNode(node, core.isCreateElementCall(context));
|
|
2013
2025
|
if (call == null) return false;
|
|
@@ -2032,44 +2044,45 @@ var no_prop_types_default = createRule({
|
|
|
2032
2044
|
schema: []
|
|
2033
2045
|
},
|
|
2034
2046
|
name: RULE_NAME31,
|
|
2035
|
-
create
|
|
2036
|
-
if (!context.sourceCode.text.includes("propTypes")) {
|
|
2037
|
-
return {};
|
|
2038
|
-
}
|
|
2039
|
-
return {
|
|
2040
|
-
AssignmentExpression(node) {
|
|
2041
|
-
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
2042
|
-
return;
|
|
2043
|
-
}
|
|
2044
|
-
const { object, property } = node.left;
|
|
2045
|
-
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
2046
|
-
return;
|
|
2047
|
-
}
|
|
2048
|
-
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2049
|
-
return;
|
|
2050
|
-
}
|
|
2051
|
-
if (!core.isComponentNameLoose(object.name)) {
|
|
2052
|
-
return;
|
|
2053
|
-
}
|
|
2054
|
-
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2055
|
-
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
2056
|
-
if (variableNode != null && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
2057
|
-
context.report({ messageId: "noPropTypes", node: property });
|
|
2058
|
-
}
|
|
2059
|
-
},
|
|
2060
|
-
PropertyDefinition(node) {
|
|
2061
|
-
if (!core.isClassComponent(node.parent.parent)) {
|
|
2062
|
-
return;
|
|
2063
|
-
}
|
|
2064
|
-
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
2065
|
-
return;
|
|
2066
|
-
}
|
|
2067
|
-
context.report({ messageId: "noPropTypes", node });
|
|
2068
|
-
}
|
|
2069
|
-
};
|
|
2070
|
-
},
|
|
2047
|
+
create: create29,
|
|
2071
2048
|
defaultOptions: []
|
|
2072
2049
|
});
|
|
2050
|
+
function create29(context) {
|
|
2051
|
+
if (!context.sourceCode.text.includes("propTypes")) {
|
|
2052
|
+
return {};
|
|
2053
|
+
}
|
|
2054
|
+
return {
|
|
2055
|
+
AssignmentExpression(node) {
|
|
2056
|
+
if (node.operator !== "=" || node.left.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
const { object, property } = node.left;
|
|
2060
|
+
if (object.type !== types.AST_NODE_TYPES.Identifier) {
|
|
2061
|
+
return;
|
|
2062
|
+
}
|
|
2063
|
+
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
if (!core.isComponentNameLoose(object.name)) {
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2070
|
+
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
2071
|
+
if (variableNode != null && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
2072
|
+
context.report({ messageId: "noPropTypes", node: property });
|
|
2073
|
+
}
|
|
2074
|
+
},
|
|
2075
|
+
PropertyDefinition(node) {
|
|
2076
|
+
if (!core.isClassComponent(node.parent.parent)) {
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
context.report({ messageId: "noPropTypes", node });
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2073
2086
|
var RULE_NAME32 = "no-redundant-should-component-update";
|
|
2074
2087
|
var RULE_FEATURES32 = [
|
|
2075
2088
|
"CHK"
|
|
@@ -2090,37 +2103,36 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2090
2103
|
schema: []
|
|
2091
2104
|
},
|
|
2092
2105
|
name: RULE_NAME32,
|
|
2093
|
-
create
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2106
|
+
create: create30,
|
|
2107
|
+
defaultOptions: []
|
|
2108
|
+
});
|
|
2109
|
+
function create30(context) {
|
|
2110
|
+
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2111
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2112
|
+
return {
|
|
2113
|
+
...listeners,
|
|
2114
|
+
"Program:exit"(node) {
|
|
2115
|
+
const components = ctx.getAllComponents(node);
|
|
2116
|
+
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2117
|
+
if ((flag & core.ERComponentFlag.PureComponent) === 0n) {
|
|
2118
|
+
continue;
|
|
2119
|
+
}
|
|
2120
|
+
const { body } = component.body;
|
|
2121
|
+
for (const member of body) {
|
|
2122
|
+
if (isShouldComponentUpdate(member)) {
|
|
2123
|
+
context.report({
|
|
2124
|
+
messageId: "noRedundantShouldComponentUpdate",
|
|
2125
|
+
node: member,
|
|
2126
|
+
data: {
|
|
2127
|
+
componentName: name5
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2117
2130
|
}
|
|
2118
2131
|
}
|
|
2119
2132
|
}
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
});
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2124
2136
|
var RULE_NAME33 = "no-set-state-in-component-did-mount";
|
|
2125
2137
|
var RULE_FEATURES33 = [
|
|
2126
2138
|
"CHK"
|
|
@@ -2141,31 +2153,30 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2141
2153
|
schema: []
|
|
2142
2154
|
},
|
|
2143
2155
|
name: RULE_NAME33,
|
|
2144
|
-
create
|
|
2145
|
-
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2146
|
-
return {};
|
|
2147
|
-
}
|
|
2148
|
-
return {
|
|
2149
|
-
CallExpression(node) {
|
|
2150
|
-
if (!core.isThisSetState(node)) {
|
|
2151
|
-
return;
|
|
2152
|
-
}
|
|
2153
|
-
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2154
|
-
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2155
|
-
if (clazz == null || method == null || method === clazz) return;
|
|
2156
|
-
const methodScope = context.sourceCode.getScope(method);
|
|
2157
|
-
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2158
|
-
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2159
|
-
context.report({
|
|
2160
|
-
messageId: "noSetStateInComponentDidMount",
|
|
2161
|
-
node
|
|
2162
|
-
});
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
};
|
|
2166
|
-
},
|
|
2156
|
+
create: create31,
|
|
2167
2157
|
defaultOptions: []
|
|
2168
2158
|
});
|
|
2159
|
+
function create31(context) {
|
|
2160
|
+
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2161
|
+
return {
|
|
2162
|
+
CallExpression(node) {
|
|
2163
|
+
if (!core.isThisSetState(node)) {
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2167
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2168
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2169
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2170
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2171
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2172
|
+
context.report({
|
|
2173
|
+
messageId: "noSetStateInComponentDidMount",
|
|
2174
|
+
node
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2169
2180
|
var RULE_NAME34 = "no-set-state-in-component-did-update";
|
|
2170
2181
|
var RULE_FEATURES34 = [
|
|
2171
2182
|
"CHK"
|
|
@@ -2186,31 +2197,30 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2186
2197
|
schema: []
|
|
2187
2198
|
},
|
|
2188
2199
|
name: RULE_NAME34,
|
|
2189
|
-
create
|
|
2190
|
-
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2191
|
-
return {};
|
|
2192
|
-
}
|
|
2193
|
-
return {
|
|
2194
|
-
CallExpression(node) {
|
|
2195
|
-
if (!core.isThisSetState(node)) {
|
|
2196
|
-
return;
|
|
2197
|
-
}
|
|
2198
|
-
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2199
|
-
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2200
|
-
if (clazz == null || method == null || method === clazz) return;
|
|
2201
|
-
const methodScope = context.sourceCode.getScope(method);
|
|
2202
|
-
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2203
|
-
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2204
|
-
context.report({
|
|
2205
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
2206
|
-
node
|
|
2207
|
-
});
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
};
|
|
2211
|
-
},
|
|
2200
|
+
create: create32,
|
|
2212
2201
|
defaultOptions: []
|
|
2213
2202
|
});
|
|
2203
|
+
function create32(context) {
|
|
2204
|
+
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2205
|
+
return {
|
|
2206
|
+
CallExpression(node) {
|
|
2207
|
+
if (!core.isThisSetState(node)) {
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2211
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2212
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2213
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2214
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2215
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2216
|
+
context.report({
|
|
2217
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
2218
|
+
node
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2214
2224
|
var RULE_NAME35 = "no-set-state-in-component-will-update";
|
|
2215
2225
|
var RULE_FEATURES35 = [
|
|
2216
2226
|
"CHK"
|
|
@@ -2231,31 +2241,30 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2231
2241
|
schema: []
|
|
2232
2242
|
},
|
|
2233
2243
|
name: RULE_NAME35,
|
|
2234
|
-
create
|
|
2235
|
-
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2236
|
-
return {};
|
|
2237
|
-
}
|
|
2238
|
-
return {
|
|
2239
|
-
CallExpression(node) {
|
|
2240
|
-
if (!core.isThisSetState(node)) {
|
|
2241
|
-
return;
|
|
2242
|
-
}
|
|
2243
|
-
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2244
|
-
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2245
|
-
if (clazz == null || method == null || method === clazz) return;
|
|
2246
|
-
const methodScope = context.sourceCode.getScope(method);
|
|
2247
|
-
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2248
|
-
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2249
|
-
context.report({
|
|
2250
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
2251
|
-
node
|
|
2252
|
-
});
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
};
|
|
2256
|
-
},
|
|
2244
|
+
create: create33,
|
|
2257
2245
|
defaultOptions: []
|
|
2258
2246
|
});
|
|
2247
|
+
function create33(context) {
|
|
2248
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2249
|
+
return {
|
|
2250
|
+
CallExpression(node) {
|
|
2251
|
+
if (!core.isThisSetState(node)) {
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2255
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2256
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2257
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2258
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2259
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2260
|
+
context.report({
|
|
2261
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
2262
|
+
node
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2259
2268
|
var RULE_NAME36 = "no-string-refs";
|
|
2260
2269
|
var RULE_FEATURES36 = [
|
|
2261
2270
|
"CHK"
|
|
@@ -2285,23 +2294,24 @@ var no_string_refs_default = createRule({
|
|
|
2285
2294
|
schema: []
|
|
2286
2295
|
},
|
|
2287
2296
|
name: RULE_NAME36,
|
|
2288
|
-
create
|
|
2289
|
-
return {
|
|
2290
|
-
JSXAttribute(node) {
|
|
2291
|
-
if (node.name.name !== "ref") {
|
|
2292
|
-
return;
|
|
2293
|
-
}
|
|
2294
|
-
if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
|
|
2295
|
-
context.report({
|
|
2296
|
-
messageId: "noStringRefs",
|
|
2297
|
-
node
|
|
2298
|
-
});
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
};
|
|
2302
|
-
},
|
|
2297
|
+
create: create34,
|
|
2303
2298
|
defaultOptions: []
|
|
2304
2299
|
});
|
|
2300
|
+
function create34(context) {
|
|
2301
|
+
return {
|
|
2302
|
+
JSXAttribute(node) {
|
|
2303
|
+
if (node.name.name !== "ref") {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
|
|
2307
|
+
context.report({
|
|
2308
|
+
messageId: "noStringRefs",
|
|
2309
|
+
node
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2305
2315
|
var RULE_NAME37 = "no-unsafe-component-will-mount";
|
|
2306
2316
|
var RULE_FEATURES37 = [
|
|
2307
2317
|
"CHK"
|
|
@@ -2322,31 +2332,30 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2322
2332
|
schema: []
|
|
2323
2333
|
},
|
|
2324
2334
|
name: RULE_NAME37,
|
|
2325
|
-
create
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
}
|
|
2335
|
+
create: create35,
|
|
2336
|
+
defaultOptions: []
|
|
2337
|
+
});
|
|
2338
|
+
function create35(context) {
|
|
2339
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2340
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2341
|
+
return {
|
|
2342
|
+
...listeners,
|
|
2343
|
+
"Program:exit"(node) {
|
|
2344
|
+
const components = ctx.getAllComponents(node);
|
|
2345
|
+
for (const { node: component } of components.values()) {
|
|
2346
|
+
const { body } = component.body;
|
|
2347
|
+
for (const member of body) {
|
|
2348
|
+
if (isUnsafeComponentWillMount(member)) {
|
|
2349
|
+
context.report({
|
|
2350
|
+
messageId: "noUnsafeComponentWillMount",
|
|
2351
|
+
node: member
|
|
2352
|
+
});
|
|
2343
2353
|
}
|
|
2344
2354
|
}
|
|
2345
2355
|
}
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
});
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2350
2359
|
var RULE_NAME38 = "no-unsafe-component-will-receive-props";
|
|
2351
2360
|
var RULE_FEATURES38 = [
|
|
2352
2361
|
"CHK"
|
|
@@ -2367,31 +2376,32 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2367
2376
|
schema: []
|
|
2368
2377
|
},
|
|
2369
2378
|
name: RULE_NAME38,
|
|
2370
|
-
create
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
return {
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2379
|
+
create: create36,
|
|
2380
|
+
defaultOptions: []
|
|
2381
|
+
});
|
|
2382
|
+
function create36(context) {
|
|
2383
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2384
|
+
return {};
|
|
2385
|
+
}
|
|
2386
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2387
|
+
return {
|
|
2388
|
+
...listeners,
|
|
2389
|
+
"Program:exit"(node) {
|
|
2390
|
+
const components = ctx.getAllComponents(node);
|
|
2391
|
+
for (const { node: component } of components.values()) {
|
|
2392
|
+
const { body } = component.body;
|
|
2393
|
+
for (const member of body) {
|
|
2394
|
+
if (isUnsafeComponentWillReceiveProps(member)) {
|
|
2395
|
+
context.report({
|
|
2396
|
+
messageId: "noUnsafeComponentWillReceiveProps",
|
|
2397
|
+
node: member
|
|
2398
|
+
});
|
|
2388
2399
|
}
|
|
2389
2400
|
}
|
|
2390
2401
|
}
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
|
-
});
|
|
2402
|
+
}
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2395
2405
|
var RULE_NAME39 = "no-unsafe-component-will-update";
|
|
2396
2406
|
var RULE_FEATURES39 = [
|
|
2397
2407
|
"CHK"
|
|
@@ -2412,31 +2422,30 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2412
2422
|
schema: []
|
|
2413
2423
|
},
|
|
2414
2424
|
name: RULE_NAME39,
|
|
2415
|
-
create
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
}
|
|
2425
|
+
create: create37,
|
|
2426
|
+
defaultOptions: []
|
|
2427
|
+
});
|
|
2428
|
+
function create37(context) {
|
|
2429
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2430
|
+
const { ctx, listeners } = core.useComponentCollectorLegacy();
|
|
2431
|
+
return {
|
|
2432
|
+
...listeners,
|
|
2433
|
+
"Program:exit"(node) {
|
|
2434
|
+
const components = ctx.getAllComponents(node);
|
|
2435
|
+
for (const { node: component } of components.values()) {
|
|
2436
|
+
const { body } = component.body;
|
|
2437
|
+
for (const member of body) {
|
|
2438
|
+
if (isUnsafeComponentWillUpdate(member)) {
|
|
2439
|
+
context.report({
|
|
2440
|
+
messageId: "noUnsafeComponentWillUpdate",
|
|
2441
|
+
node: member
|
|
2442
|
+
});
|
|
2433
2443
|
}
|
|
2434
2444
|
}
|
|
2435
2445
|
}
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
});
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2440
2449
|
var RULE_NAME40 = "no-unstable-context-value";
|
|
2441
2450
|
var RULE_FEATURES40 = [
|
|
2442
2451
|
"CHK"
|
|
@@ -2454,56 +2463,57 @@ var no_unstable_context_value_default = createRule({
|
|
|
2454
2463
|
schema: []
|
|
2455
2464
|
},
|
|
2456
2465
|
name: RULE_NAME40,
|
|
2457
|
-
create
|
|
2458
|
-
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
2459
|
-
const isReact18OrBelow = compareVersions.compare(version2, "19.0.0", "<");
|
|
2460
|
-
const { ctx, listeners } = core.useComponentCollector(context);
|
|
2461
|
-
const constructions = /* @__PURE__ */ new Map();
|
|
2462
|
-
return {
|
|
2463
|
-
...listeners,
|
|
2464
|
-
JSXOpeningElement(node) {
|
|
2465
|
-
const fullName = JSX8__namespace.getElementType(node.parent);
|
|
2466
|
-
const selfName = fullName.split(".").at(-1);
|
|
2467
|
-
if (selfName == null) return;
|
|
2468
|
-
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
2469
|
-
const functionEntry = ctx.getCurrentEntry();
|
|
2470
|
-
if (functionEntry == null) return;
|
|
2471
|
-
const attribute = node.attributes.find(
|
|
2472
|
-
(attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2473
|
-
);
|
|
2474
|
-
if (attribute == null || !("value" in attribute)) return;
|
|
2475
|
-
const value = attribute.value;
|
|
2476
|
-
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2477
|
-
const valueExpression = value.expression;
|
|
2478
|
-
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2479
|
-
const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
|
|
2480
|
-
if (construction == null) return;
|
|
2481
|
-
if (core.isReactHookCall(construction.node)) {
|
|
2482
|
-
return;
|
|
2483
|
-
}
|
|
2484
|
-
eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2485
|
-
},
|
|
2486
|
-
"Program:exit"(node) {
|
|
2487
|
-
const components = ctx.getAllComponents(node).values();
|
|
2488
|
-
for (const { node: component } of components) {
|
|
2489
|
-
for (const construction of constructions.get(component) ?? []) {
|
|
2490
|
-
const { kind, node: constructionNode } = construction;
|
|
2491
|
-
const suggestion = kind.startsWith("Function") ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
2492
|
-
context.report({
|
|
2493
|
-
messageId: "unstableContextValue",
|
|
2494
|
-
node: constructionNode,
|
|
2495
|
-
data: {
|
|
2496
|
-
type: AST11__namespace.toReadableNodeType(constructionNode),
|
|
2497
|
-
suggestion
|
|
2498
|
-
}
|
|
2499
|
-
});
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
};
|
|
2504
|
-
},
|
|
2466
|
+
create: create38,
|
|
2505
2467
|
defaultOptions: []
|
|
2506
2468
|
});
|
|
2469
|
+
function create38(context) {
|
|
2470
|
+
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
2471
|
+
const isReact18OrBelow = compareVersions.compare(version2, "19.0.0", "<");
|
|
2472
|
+
const { ctx, listeners } = core.useComponentCollector(context);
|
|
2473
|
+
const constructions = /* @__PURE__ */ new Map();
|
|
2474
|
+
return {
|
|
2475
|
+
...listeners,
|
|
2476
|
+
JSXOpeningElement(node) {
|
|
2477
|
+
const fullName = JSX8__namespace.getElementType(node.parent);
|
|
2478
|
+
const selfName = fullName.split(".").at(-1);
|
|
2479
|
+
if (selfName == null) return;
|
|
2480
|
+
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
2481
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2482
|
+
if (functionEntry == null) return;
|
|
2483
|
+
const attribute = node.attributes.find(
|
|
2484
|
+
(attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2485
|
+
);
|
|
2486
|
+
if (attribute == null || !("value" in attribute)) return;
|
|
2487
|
+
const value = attribute.value;
|
|
2488
|
+
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2489
|
+
const valueExpression = value.expression;
|
|
2490
|
+
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2491
|
+
const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
|
|
2492
|
+
if (construction == null) return;
|
|
2493
|
+
if (core.isReactHookCall(construction.node)) {
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2497
|
+
},
|
|
2498
|
+
"Program:exit"(node) {
|
|
2499
|
+
const components = ctx.getAllComponents(node).values();
|
|
2500
|
+
for (const { node: component } of components) {
|
|
2501
|
+
for (const construction of constructions.get(component) ?? []) {
|
|
2502
|
+
const { kind, node: constructionNode } = construction;
|
|
2503
|
+
const suggestion = kind.startsWith("Function") ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
2504
|
+
context.report({
|
|
2505
|
+
messageId: "unstableContextValue",
|
|
2506
|
+
node: constructionNode,
|
|
2507
|
+
data: {
|
|
2508
|
+
type: AST11__namespace.toReadableNodeType(constructionNode),
|
|
2509
|
+
suggestion
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
}
|
|
2507
2517
|
function isContextName(name5, isReact18OrBelow) {
|
|
2508
2518
|
if (name5 === "Provider") return true;
|
|
2509
2519
|
if (!isReact18OrBelow) {
|
|
@@ -2528,64 +2538,65 @@ var no_unstable_default_props_default = createRule({
|
|
|
2528
2538
|
schema: []
|
|
2529
2539
|
},
|
|
2530
2540
|
name: RULE_NAME41,
|
|
2531
|
-
create
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2541
|
+
create: create39,
|
|
2542
|
+
defaultOptions: []
|
|
2543
|
+
});
|
|
2544
|
+
function create39(context) {
|
|
2545
|
+
const { ctx, listeners } = core.useComponentCollector(context);
|
|
2546
|
+
const declarators = /* @__PURE__ */ new Map();
|
|
2547
|
+
return {
|
|
2548
|
+
...listeners,
|
|
2549
|
+
"Program:exit"(node) {
|
|
2550
|
+
const components = ctx.getAllComponents(node);
|
|
2551
|
+
for (const { node: component } of components.values()) {
|
|
2552
|
+
const { params } = component;
|
|
2553
|
+
const [props] = params;
|
|
2554
|
+
if (props == null) {
|
|
2555
|
+
continue;
|
|
2556
|
+
}
|
|
2557
|
+
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name5 }) => {
|
|
2558
|
+
return declarators.get(component)?.filter((d) => d.init.name === name5).flatMap((d) => d.id.properties) ?? [];
|
|
2559
|
+
}).otherwise(() => []);
|
|
2560
|
+
for (const prop of properties) {
|
|
2561
|
+
if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) {
|
|
2542
2562
|
continue;
|
|
2543
2563
|
}
|
|
2544
|
-
const
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2558
|
-
);
|
|
2559
|
-
if (construction == null) {
|
|
2560
|
-
continue;
|
|
2561
|
-
}
|
|
2562
|
-
if (core.isReactHookCall(construction.node)) {
|
|
2563
|
-
continue;
|
|
2564
|
-
}
|
|
2565
|
-
const forbiddenType = AST11__namespace.toReadableNodeType(right);
|
|
2566
|
-
context.report({
|
|
2567
|
-
messageId: "noUnstableDefaultProps",
|
|
2568
|
-
node: right,
|
|
2569
|
-
data: {
|
|
2570
|
-
forbiddenType
|
|
2571
|
-
}
|
|
2572
|
-
});
|
|
2564
|
+
const { value } = prop;
|
|
2565
|
+
const { right } = value;
|
|
2566
|
+
const initialScope = context.sourceCode.getScope(value);
|
|
2567
|
+
const construction = VAR__namespace.getValueConstruction(
|
|
2568
|
+
value,
|
|
2569
|
+
initialScope,
|
|
2570
|
+
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2571
|
+
);
|
|
2572
|
+
if (construction == null) {
|
|
2573
|
+
continue;
|
|
2574
|
+
}
|
|
2575
|
+
if (core.isReactHookCall(construction.node)) {
|
|
2576
|
+
continue;
|
|
2573
2577
|
}
|
|
2578
|
+
const forbiddenType = AST11__namespace.toReadableNodeType(right);
|
|
2579
|
+
context.report({
|
|
2580
|
+
messageId: "noUnstableDefaultProps",
|
|
2581
|
+
node: right,
|
|
2582
|
+
data: {
|
|
2583
|
+
forbiddenType
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2574
2586
|
}
|
|
2575
|
-
},
|
|
2576
|
-
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2577
|
-
const functionEntry = ctx.getCurrentEntry();
|
|
2578
|
-
if (functionEntry == null) return;
|
|
2579
|
-
eff.getOrUpdate(
|
|
2580
|
-
declarators,
|
|
2581
|
-
functionEntry.node,
|
|
2582
|
-
() => []
|
|
2583
|
-
).push(node);
|
|
2584
2587
|
}
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2588
|
+
},
|
|
2589
|
+
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2590
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2591
|
+
if (functionEntry == null) return;
|
|
2592
|
+
eff.getOrUpdate(
|
|
2593
|
+
declarators,
|
|
2594
|
+
functionEntry.node,
|
|
2595
|
+
() => []
|
|
2596
|
+
).push(node);
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2589
2600
|
var RULE_NAME42 = "no-unused-class-component-members";
|
|
2590
2601
|
var RULE_FEATURES42 = [
|
|
2591
2602
|
"CHK"
|
|
@@ -2623,118 +2634,119 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2623
2634
|
schema: []
|
|
2624
2635
|
},
|
|
2625
2636
|
name: RULE_NAME42,
|
|
2626
|
-
create
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2637
|
+
create: create40,
|
|
2638
|
+
defaultOptions: []
|
|
2639
|
+
});
|
|
2640
|
+
function create40(context) {
|
|
2641
|
+
const classEntries = [];
|
|
2642
|
+
const methodEntries = [];
|
|
2643
|
+
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
2644
|
+
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2645
|
+
function classEnter(node) {
|
|
2646
|
+
classEntries.push(node);
|
|
2647
|
+
if (!core.isClassComponent(node)) {
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
2651
|
+
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2652
|
+
}
|
|
2653
|
+
function classExit() {
|
|
2654
|
+
const currentClass = classEntries.pop();
|
|
2655
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2659
|
+
const defs = propertyDefs.get(currentClass);
|
|
2660
|
+
const usages = propertyUsages.get(currentClass);
|
|
2661
|
+
if (defs == null) {
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
for (const def of defs) {
|
|
2665
|
+
const methodName = AST11__namespace.getPropertyName(def);
|
|
2666
|
+
if (methodName == null) {
|
|
2667
|
+
continue;
|
|
2668
|
+
}
|
|
2669
|
+
if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
|
|
2670
|
+
continue;
|
|
2635
2671
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2672
|
+
context.report({
|
|
2673
|
+
messageId: "noUnusedClassComponentMembers",
|
|
2674
|
+
node: def,
|
|
2675
|
+
data: {
|
|
2676
|
+
className: className ?? "Component",
|
|
2677
|
+
methodName
|
|
2678
|
+
}
|
|
2679
|
+
});
|
|
2638
2680
|
}
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2681
|
+
}
|
|
2682
|
+
function methodEnter(node) {
|
|
2683
|
+
methodEntries.push(node);
|
|
2684
|
+
const currentClass = classEntries.at(-1);
|
|
2685
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2686
|
+
return;
|
|
2687
|
+
}
|
|
2688
|
+
if (node.static) {
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
if (isKeyLiteral2(node, node.key)) {
|
|
2692
|
+
propertyDefs.get(currentClass)?.add(node.key);
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
function methodExit() {
|
|
2696
|
+
methodEntries.pop();
|
|
2697
|
+
}
|
|
2698
|
+
return {
|
|
2699
|
+
ClassDeclaration: classEnter,
|
|
2700
|
+
"ClassDeclaration:exit": classExit,
|
|
2701
|
+
ClassExpression: classEnter,
|
|
2702
|
+
"ClassExpression:exit": classExit,
|
|
2703
|
+
MemberExpression(node) {
|
|
2704
|
+
const currentClass = classEntries.at(-1);
|
|
2705
|
+
const currentMethod = methodEntries.at(-1);
|
|
2706
|
+
if (currentClass == null || currentMethod == null) {
|
|
2642
2707
|
return;
|
|
2643
2708
|
}
|
|
2644
|
-
|
|
2645
|
-
const defs = propertyDefs.get(currentClass);
|
|
2646
|
-
const usages = propertyUsages.get(currentClass);
|
|
2647
|
-
if (defs == null) {
|
|
2709
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2648
2710
|
return;
|
|
2649
2711
|
}
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
if (methodName == null) {
|
|
2653
|
-
continue;
|
|
2654
|
-
}
|
|
2655
|
-
if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
|
|
2656
|
-
continue;
|
|
2657
|
-
}
|
|
2658
|
-
context.report({
|
|
2659
|
-
messageId: "noUnusedClassComponentMembers",
|
|
2660
|
-
node: def,
|
|
2661
|
-
data: {
|
|
2662
|
-
className: className ?? "Component",
|
|
2663
|
-
methodName
|
|
2664
|
-
}
|
|
2665
|
-
});
|
|
2712
|
+
if (!AST11__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2713
|
+
return;
|
|
2666
2714
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
methodEntries.push(node);
|
|
2670
|
-
const currentClass = classEntries.at(-1);
|
|
2671
|
-
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2715
|
+
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2716
|
+
propertyDefs.get(currentClass)?.add(node.property);
|
|
2672
2717
|
return;
|
|
2673
2718
|
}
|
|
2674
|
-
|
|
2719
|
+
const propertyName = AST11__namespace.getPropertyName(node.property);
|
|
2720
|
+
if (propertyName != null) {
|
|
2721
|
+
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2722
|
+
}
|
|
2723
|
+
},
|
|
2724
|
+
MethodDefinition: methodEnter,
|
|
2725
|
+
"MethodDefinition:exit": methodExit,
|
|
2726
|
+
PropertyDefinition: methodEnter,
|
|
2727
|
+
"PropertyDefinition:exit": methodExit,
|
|
2728
|
+
VariableDeclarator(node) {
|
|
2729
|
+
const currentClass = classEntries.at(-1);
|
|
2730
|
+
const currentMethod = methodEntries.at(-1);
|
|
2731
|
+
if (currentClass == null || currentMethod == null) {
|
|
2675
2732
|
return;
|
|
2676
2733
|
}
|
|
2677
|
-
if (
|
|
2678
|
-
|
|
2734
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2735
|
+
return;
|
|
2679
2736
|
}
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
"ClassDeclaration:exit": classExit,
|
|
2687
|
-
ClassExpression: classEnter,
|
|
2688
|
-
"ClassExpression:exit": classExit,
|
|
2689
|
-
MemberExpression(node) {
|
|
2690
|
-
const currentClass = classEntries.at(-1);
|
|
2691
|
-
const currentMethod = methodEntries.at(-1);
|
|
2692
|
-
if (currentClass == null || currentMethod == null) {
|
|
2693
|
-
return;
|
|
2694
|
-
}
|
|
2695
|
-
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2696
|
-
return;
|
|
2697
|
-
}
|
|
2698
|
-
if (!AST11__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2699
|
-
return;
|
|
2700
|
-
}
|
|
2701
|
-
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2702
|
-
propertyDefs.get(currentClass)?.add(node.property);
|
|
2703
|
-
return;
|
|
2704
|
-
}
|
|
2705
|
-
const propertyName = AST11__namespace.getPropertyName(node.property);
|
|
2706
|
-
if (propertyName != null) {
|
|
2707
|
-
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2708
|
-
}
|
|
2709
|
-
},
|
|
2710
|
-
MethodDefinition: methodEnter,
|
|
2711
|
-
"MethodDefinition:exit": methodExit,
|
|
2712
|
-
PropertyDefinition: methodEnter,
|
|
2713
|
-
"PropertyDefinition:exit": methodExit,
|
|
2714
|
-
VariableDeclarator(node) {
|
|
2715
|
-
const currentClass = classEntries.at(-1);
|
|
2716
|
-
const currentMethod = methodEntries.at(-1);
|
|
2717
|
-
if (currentClass == null || currentMethod == null) {
|
|
2718
|
-
return;
|
|
2719
|
-
}
|
|
2720
|
-
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2721
|
-
return;
|
|
2722
|
-
}
|
|
2723
|
-
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2724
|
-
for (const prop of node.id.properties) {
|
|
2725
|
-
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2726
|
-
const keyName = AST11__namespace.getPropertyName(prop.key);
|
|
2727
|
-
if (keyName != null) {
|
|
2728
|
-
propertyUsages.get(currentClass)?.add(keyName);
|
|
2729
|
-
}
|
|
2737
|
+
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2738
|
+
for (const prop of node.id.properties) {
|
|
2739
|
+
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2740
|
+
const keyName = AST11__namespace.getPropertyName(prop.key);
|
|
2741
|
+
if (keyName != null) {
|
|
2742
|
+
propertyUsages.get(currentClass)?.add(keyName);
|
|
2730
2743
|
}
|
|
2731
2744
|
}
|
|
2732
2745
|
}
|
|
2733
2746
|
}
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
|
-
});
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2738
2750
|
var RULE_NAME43 = "no-unused-state";
|
|
2739
2751
|
var RULE_FEATURES43 = [
|
|
2740
2752
|
"CHK"
|
|
@@ -2755,142 +2767,143 @@ var no_unused_state_default = createRule({
|
|
|
2755
2767
|
schema: []
|
|
2756
2768
|
},
|
|
2757
2769
|
name: RULE_NAME43,
|
|
2758
|
-
create
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2770
|
+
create: create41,
|
|
2771
|
+
defaultOptions: []
|
|
2772
|
+
});
|
|
2773
|
+
function create41(context) {
|
|
2774
|
+
const classEntries = [];
|
|
2775
|
+
const methodEntries = [];
|
|
2776
|
+
const constructorEntries = [];
|
|
2777
|
+
const stateDefs = /* @__PURE__ */ new WeakMap();
|
|
2778
|
+
function classEnter(node) {
|
|
2779
|
+
classEntries.push(node);
|
|
2780
|
+
}
|
|
2781
|
+
function classExit() {
|
|
2782
|
+
const currentClass = classEntries.pop();
|
|
2783
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2787
|
+
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2788
|
+
if (defNode == null || isUsed) {
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
context.report({
|
|
2792
|
+
messageId: "noUnusedState",
|
|
2793
|
+
node: defNode,
|
|
2794
|
+
data: {
|
|
2795
|
+
className: className ?? "Component"
|
|
2796
|
+
}
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
function methodEnter(node) {
|
|
2800
|
+
methodEntries.push(node);
|
|
2801
|
+
const currentClass = classEntries.at(-1);
|
|
2802
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
if (node.static) {
|
|
2806
|
+
if (core.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
|
|
2807
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2808
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2809
|
+
}
|
|
2810
|
+
return;
|
|
2811
|
+
}
|
|
2812
|
+
if (AST11__namespace.getPropertyName(node.key) === "state") {
|
|
2813
|
+
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
function methodExit() {
|
|
2817
|
+
methodEntries.pop();
|
|
2818
|
+
}
|
|
2819
|
+
function constructorEnter(node) {
|
|
2820
|
+
constructorEntries.push(node);
|
|
2821
|
+
}
|
|
2822
|
+
function constructorExit() {
|
|
2823
|
+
constructorEntries.pop();
|
|
2824
|
+
}
|
|
2825
|
+
return {
|
|
2826
|
+
AssignmentExpression(node) {
|
|
2827
|
+
if (!core.isAssignmentToThisState(node)) {
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
const currentClass = classEntries.at(-1);
|
|
2768
2831
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2769
2832
|
return;
|
|
2770
2833
|
}
|
|
2771
|
-
const
|
|
2772
|
-
|
|
2773
|
-
|
|
2834
|
+
const currentConstructor = constructorEntries.at(-1);
|
|
2835
|
+
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
|
|
2839
|
+
stateDefs.set(currentClass, { node: node.left, isUsed });
|
|
2840
|
+
},
|
|
2841
|
+
ClassDeclaration: classEnter,
|
|
2842
|
+
"ClassDeclaration:exit": classExit,
|
|
2843
|
+
ClassExpression: classEnter,
|
|
2844
|
+
"ClassExpression:exit": classExit,
|
|
2845
|
+
MemberExpression(node) {
|
|
2846
|
+
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
2847
|
+
return;
|
|
2848
|
+
}
|
|
2849
|
+
if (AST11__namespace.getPropertyName(node.property) !== "state") {
|
|
2774
2850
|
return;
|
|
2775
2851
|
}
|
|
2776
|
-
context.report({
|
|
2777
|
-
messageId: "noUnusedState",
|
|
2778
|
-
node: defNode,
|
|
2779
|
-
data: {
|
|
2780
|
-
className: className ?? "Component"
|
|
2781
|
-
}
|
|
2782
|
-
});
|
|
2783
|
-
}
|
|
2784
|
-
function methodEnter(node) {
|
|
2785
|
-
methodEntries.push(node);
|
|
2786
2852
|
const currentClass = classEntries.at(-1);
|
|
2787
2853
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2788
2854
|
return;
|
|
2789
2855
|
}
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2856
|
+
const currentMethod = methodEntries.at(-1);
|
|
2857
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2867
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2868
|
+
},
|
|
2869
|
+
MethodDefinition: methodEnter,
|
|
2870
|
+
"MethodDefinition:exit": methodExit,
|
|
2871
|
+
"MethodDefinition[key.name='constructor']": constructorEnter,
|
|
2872
|
+
"MethodDefinition[key.name='constructor']:exit": constructorExit,
|
|
2873
|
+
PropertyDefinition: methodEnter,
|
|
2874
|
+
"PropertyDefinition:exit": methodExit,
|
|
2875
|
+
VariableDeclarator(node) {
|
|
2876
|
+
const currentClass = classEntries.at(-1);
|
|
2877
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
const currentMethod = methodEntries.at(-1);
|
|
2881
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2888
|
+
return;
|
|
2889
|
+
}
|
|
2890
|
+
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
const hasState = node.id.properties.some((prop) => {
|
|
2894
|
+
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2895
|
+
return AST11__namespace.getPropertyName(prop.key) === "state";
|
|
2794
2896
|
}
|
|
2897
|
+
return false;
|
|
2898
|
+
});
|
|
2899
|
+
if (!hasState) {
|
|
2795
2900
|
return;
|
|
2796
2901
|
}
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
function methodExit() {
|
|
2802
|
-
methodEntries.pop();
|
|
2803
|
-
}
|
|
2804
|
-
function constructorEnter(node) {
|
|
2805
|
-
constructorEntries.push(node);
|
|
2902
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2903
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2806
2904
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
}
|
|
2810
|
-
return {
|
|
2811
|
-
AssignmentExpression(node) {
|
|
2812
|
-
if (!core.isAssignmentToThisState(node)) {
|
|
2813
|
-
return;
|
|
2814
|
-
}
|
|
2815
|
-
const currentClass = classEntries.at(-1);
|
|
2816
|
-
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2817
|
-
return;
|
|
2818
|
-
}
|
|
2819
|
-
const currentConstructor = constructorEntries.at(-1);
|
|
2820
|
-
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2821
|
-
return;
|
|
2822
|
-
}
|
|
2823
|
-
const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
|
|
2824
|
-
stateDefs.set(currentClass, { node: node.left, isUsed });
|
|
2825
|
-
},
|
|
2826
|
-
ClassDeclaration: classEnter,
|
|
2827
|
-
"ClassDeclaration:exit": classExit,
|
|
2828
|
-
ClassExpression: classEnter,
|
|
2829
|
-
"ClassExpression:exit": classExit,
|
|
2830
|
-
MemberExpression(node) {
|
|
2831
|
-
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
2832
|
-
return;
|
|
2833
|
-
}
|
|
2834
|
-
if (AST11__namespace.getPropertyName(node.property) !== "state") {
|
|
2835
|
-
return;
|
|
2836
|
-
}
|
|
2837
|
-
const currentClass = classEntries.at(-1);
|
|
2838
|
-
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2839
|
-
return;
|
|
2840
|
-
}
|
|
2841
|
-
const currentMethod = methodEntries.at(-1);
|
|
2842
|
-
if (currentMethod == null || currentMethod.static) {
|
|
2843
|
-
return;
|
|
2844
|
-
}
|
|
2845
|
-
if (currentMethod === constructorEntries.at(-1)) {
|
|
2846
|
-
return;
|
|
2847
|
-
}
|
|
2848
|
-
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2849
|
-
return;
|
|
2850
|
-
}
|
|
2851
|
-
const defNode = stateDefs.get(currentClass)?.node;
|
|
2852
|
-
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2853
|
-
},
|
|
2854
|
-
MethodDefinition: methodEnter,
|
|
2855
|
-
"MethodDefinition:exit": methodExit,
|
|
2856
|
-
"MethodDefinition[key.name='constructor']": constructorEnter,
|
|
2857
|
-
"MethodDefinition[key.name='constructor']:exit": constructorExit,
|
|
2858
|
-
PropertyDefinition: methodEnter,
|
|
2859
|
-
"PropertyDefinition:exit": methodExit,
|
|
2860
|
-
VariableDeclarator(node) {
|
|
2861
|
-
const currentClass = classEntries.at(-1);
|
|
2862
|
-
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2863
|
-
return;
|
|
2864
|
-
}
|
|
2865
|
-
const currentMethod = methodEntries.at(-1);
|
|
2866
|
-
if (currentMethod == null || currentMethod.static) {
|
|
2867
|
-
return;
|
|
2868
|
-
}
|
|
2869
|
-
if (currentMethod === constructorEntries.at(-1)) {
|
|
2870
|
-
return;
|
|
2871
|
-
}
|
|
2872
|
-
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2873
|
-
return;
|
|
2874
|
-
}
|
|
2875
|
-
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
2876
|
-
return;
|
|
2877
|
-
}
|
|
2878
|
-
const hasState = node.id.properties.some((prop) => {
|
|
2879
|
-
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2880
|
-
return AST11__namespace.getPropertyName(prop.key) === "state";
|
|
2881
|
-
}
|
|
2882
|
-
return false;
|
|
2883
|
-
});
|
|
2884
|
-
if (!hasState) {
|
|
2885
|
-
return;
|
|
2886
|
-
}
|
|
2887
|
-
const defNode = stateDefs.get(currentClass)?.node;
|
|
2888
|
-
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2889
|
-
}
|
|
2890
|
-
};
|
|
2891
|
-
},
|
|
2892
|
-
defaultOptions: []
|
|
2893
|
-
});
|
|
2905
|
+
};
|
|
2906
|
+
}
|
|
2894
2907
|
var RULE_NAME44 = "no-use-context";
|
|
2895
2908
|
var RULE_FEATURES44 = [
|
|
2896
2909
|
"CHK",
|
|
@@ -2910,72 +2923,73 @@ var no_use_context_default = createRule({
|
|
|
2910
2923
|
schema: []
|
|
2911
2924
|
},
|
|
2912
2925
|
name: RULE_NAME44,
|
|
2913
|
-
create
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2926
|
+
create: create42,
|
|
2927
|
+
defaultOptions: []
|
|
2928
|
+
});
|
|
2929
|
+
function create42(context) {
|
|
2930
|
+
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
2931
|
+
const settings4 = shared.getSettingsFromContext(context);
|
|
2932
|
+
const useContextAlias = /* @__PURE__ */ new Set();
|
|
2933
|
+
if (compareVersions.compare(settings4.version, "19.0.0", "<")) {
|
|
2934
|
+
return {};
|
|
2935
|
+
}
|
|
2936
|
+
return {
|
|
2937
|
+
CallExpression(node) {
|
|
2938
|
+
if (!core.isReactHookCall(node)) {
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
if (!core.isReactHookCallWithNameAlias(context, "useContext", [...useContextAlias])(node)) {
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
context.report({
|
|
2945
|
+
messageId: "noUseContext",
|
|
2946
|
+
node: node.callee,
|
|
2947
|
+
fix(fixer) {
|
|
2948
|
+
switch (node.callee.type) {
|
|
2949
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
2950
|
+
return fixer.replaceText(node.callee, "use");
|
|
2951
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
2952
|
+
return fixer.replaceText(node.callee.property, "use");
|
|
2939
2953
|
}
|
|
2940
|
-
|
|
2941
|
-
},
|
|
2942
|
-
ImportDeclaration(node) {
|
|
2943
|
-
if (node.source.value !== settings4.importSource) {
|
|
2944
|
-
return;
|
|
2954
|
+
return null;
|
|
2945
2955
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
const tokenBefore = context.sourceCode.getTokenBefore(specifier);
|
|
2960
|
-
return [
|
|
2961
|
-
fixer.remove(specifier),
|
|
2962
|
-
...tokenBefore?.value === "," ? [fixer.replaceTextRange([tokenBefore.range[1], specifier.range[0]], "")] : [],
|
|
2963
|
-
...getAssociatedTokens(
|
|
2964
|
-
context,
|
|
2965
|
-
specifier
|
|
2966
|
-
).map((token) => fixer.remove(token))
|
|
2967
|
-
];
|
|
2968
|
-
}
|
|
2969
|
-
return fixer.replaceText(specifier.imported, "use");
|
|
2970
|
-
}
|
|
2971
|
-
});
|
|
2956
|
+
});
|
|
2957
|
+
},
|
|
2958
|
+
ImportDeclaration(node) {
|
|
2959
|
+
if (node.source.value !== settings4.importSource) {
|
|
2960
|
+
return;
|
|
2961
|
+
}
|
|
2962
|
+
const isUseImported = node.specifiers.some(tsPattern.isMatching({ local: { type: types.AST_NODE_TYPES.Identifier, name: "use" } }));
|
|
2963
|
+
for (const specifier of node.specifiers) {
|
|
2964
|
+
if (specifier.type !== types.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
2965
|
+
if (specifier.imported.type !== types.AST_NODE_TYPES.Identifier) continue;
|
|
2966
|
+
if (specifier.imported.name === "useContext") {
|
|
2967
|
+
if (specifier.local.name !== "useContext") {
|
|
2968
|
+
useContextAlias.add(specifier.local.name);
|
|
2972
2969
|
}
|
|
2970
|
+
context.report({
|
|
2971
|
+
messageId: "noUseContext",
|
|
2972
|
+
node: specifier,
|
|
2973
|
+
fix(fixer) {
|
|
2974
|
+
if (isUseImported) {
|
|
2975
|
+
const tokenBefore = context.sourceCode.getTokenBefore(specifier);
|
|
2976
|
+
return [
|
|
2977
|
+
fixer.remove(specifier),
|
|
2978
|
+
...tokenBefore?.value === "," ? [fixer.replaceTextRange([tokenBefore.range[1], specifier.range[0]], "")] : [],
|
|
2979
|
+
...getAssociatedTokens(
|
|
2980
|
+
context,
|
|
2981
|
+
specifier
|
|
2982
|
+
).map((token) => fixer.remove(token))
|
|
2983
|
+
];
|
|
2984
|
+
}
|
|
2985
|
+
return fixer.replaceText(specifier.imported, "use");
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2973
2988
|
}
|
|
2974
2989
|
}
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
|
|
2978
|
-
});
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
}
|
|
2979
2993
|
function getAssociatedTokens(context, node) {
|
|
2980
2994
|
{
|
|
2981
2995
|
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
@@ -3007,29 +3021,30 @@ var no_useless_forward_ref_default = createRule({
|
|
|
3007
3021
|
schema: []
|
|
3008
3022
|
},
|
|
3009
3023
|
name: RULE_NAME45,
|
|
3010
|
-
create
|
|
3011
|
-
return {
|
|
3012
|
-
CallExpression(node) {
|
|
3013
|
-
if (!core.isForwardRefCall(context, node)) {
|
|
3014
|
-
return;
|
|
3015
|
-
}
|
|
3016
|
-
const [component] = node.arguments;
|
|
3017
|
-
if (component == null || !AST11__namespace.isFunction(component)) {
|
|
3018
|
-
return;
|
|
3019
|
-
}
|
|
3020
|
-
const ref = component.params[1];
|
|
3021
|
-
if (ref != null) {
|
|
3022
|
-
return;
|
|
3023
|
-
}
|
|
3024
|
-
context.report({
|
|
3025
|
-
messageId: "noUselessForwardRef",
|
|
3026
|
-
node: component
|
|
3027
|
-
});
|
|
3028
|
-
}
|
|
3029
|
-
};
|
|
3030
|
-
},
|
|
3024
|
+
create: create43,
|
|
3031
3025
|
defaultOptions: []
|
|
3032
3026
|
});
|
|
3027
|
+
function create43(context) {
|
|
3028
|
+
return {
|
|
3029
|
+
CallExpression(node) {
|
|
3030
|
+
if (!core.isForwardRefCall(context, node)) {
|
|
3031
|
+
return;
|
|
3032
|
+
}
|
|
3033
|
+
const [component] = node.arguments;
|
|
3034
|
+
if (component == null || !AST11__namespace.isFunction(component)) {
|
|
3035
|
+
return;
|
|
3036
|
+
}
|
|
3037
|
+
const ref = component.params[1];
|
|
3038
|
+
if (ref != null) {
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3041
|
+
context.report({
|
|
3042
|
+
messageId: "noUselessForwardRef",
|
|
3043
|
+
node: component
|
|
3044
|
+
});
|
|
3045
|
+
}
|
|
3046
|
+
};
|
|
3047
|
+
}
|
|
3033
3048
|
var RULE_NAME46 = "no-useless-fragment";
|
|
3034
3049
|
var defaultOptions = [{
|
|
3035
3050
|
allowExpressions: true
|
|
@@ -3157,20 +3172,21 @@ var no_useless_fragment_default = createRule({
|
|
|
3157
3172
|
}]
|
|
3158
3173
|
},
|
|
3159
3174
|
name: RULE_NAME46,
|
|
3160
|
-
create
|
|
3161
|
-
const { allowExpressions = true } = option;
|
|
3162
|
-
return {
|
|
3163
|
-
JSXElement(node) {
|
|
3164
|
-
if (!JSX8__namespace.isFragmentElement(node)) return;
|
|
3165
|
-
checkAndReport(context, node, allowExpressions);
|
|
3166
|
-
},
|
|
3167
|
-
JSXFragment(node) {
|
|
3168
|
-
checkAndReport(context, node, allowExpressions);
|
|
3169
|
-
}
|
|
3170
|
-
};
|
|
3171
|
-
},
|
|
3175
|
+
create: create44,
|
|
3172
3176
|
defaultOptions
|
|
3173
3177
|
});
|
|
3178
|
+
function create44(context, [option]) {
|
|
3179
|
+
const { allowExpressions = true } = option;
|
|
3180
|
+
return {
|
|
3181
|
+
JSXElement(node) {
|
|
3182
|
+
if (!JSX8__namespace.isFragmentElement(node)) return;
|
|
3183
|
+
checkAndReport(context, node, allowExpressions);
|
|
3184
|
+
},
|
|
3185
|
+
JSXFragment(node) {
|
|
3186
|
+
checkAndReport(context, node, allowExpressions);
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
}
|
|
3174
3190
|
var RULE_NAME47 = "prefer-destructuring-assignment";
|
|
3175
3191
|
var RULE_FEATURES46 = [
|
|
3176
3192
|
"CHK"
|
|
@@ -3191,68 +3207,69 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3191
3207
|
schema: []
|
|
3192
3208
|
},
|
|
3193
3209
|
name: RULE_NAME47,
|
|
3194
|
-
create
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3210
|
+
create: create45,
|
|
3211
|
+
defaultOptions: []
|
|
3212
|
+
});
|
|
3213
|
+
function create45(context) {
|
|
3214
|
+
const { ctx, listeners } = core.useComponentCollector(context);
|
|
3215
|
+
const memberExpressionWithNames = [];
|
|
3216
|
+
return {
|
|
3217
|
+
...listeners,
|
|
3218
|
+
MemberExpression(node) {
|
|
3219
|
+
if (isMemberExpressionWithObjectName(node)) {
|
|
3220
|
+
const scope = context.sourceCode.getScope(node);
|
|
3221
|
+
memberExpressionWithNames.push([scope, node]);
|
|
3222
|
+
}
|
|
3223
|
+
},
|
|
3224
|
+
"Program:exit"(node) {
|
|
3225
|
+
const components = [
|
|
3226
|
+
...ctx.getAllComponents(node).values()
|
|
3227
|
+
];
|
|
3228
|
+
function isFunctionComponent(block) {
|
|
3229
|
+
if (!AST11__namespace.isFunction(block)) {
|
|
3230
|
+
return false;
|
|
3203
3231
|
}
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
const id = AST11__namespace.getFunctionIdentifier(block);
|
|
3214
|
-
return id != null && core.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3232
|
+
const id = AST11__namespace.getFunctionIdentifier(block);
|
|
3233
|
+
return id != null && core.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3234
|
+
}
|
|
3235
|
+
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3236
|
+
let scope = initialScope;
|
|
3237
|
+
let isComponent = isFunctionComponent(scope.block);
|
|
3238
|
+
while (!isComponent && scope.upper != null && scope.upper !== scope) {
|
|
3239
|
+
scope = scope.upper;
|
|
3240
|
+
isComponent = isFunctionComponent(scope.block);
|
|
3215
3241
|
}
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
context.report({
|
|
3243
|
-
messageId: "preferDestructuringAssignment",
|
|
3244
|
-
node: memberExpression,
|
|
3245
|
-
data: {
|
|
3246
|
-
name: "context"
|
|
3247
|
-
}
|
|
3248
|
-
});
|
|
3249
|
-
}
|
|
3242
|
+
if (!isComponent) {
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
const component = scope.block;
|
|
3246
|
+
if (!("params" in component)) {
|
|
3247
|
+
continue;
|
|
3248
|
+
}
|
|
3249
|
+
const [props, ctx2] = component.params;
|
|
3250
|
+
const isMatch = (node2) => node2 != null && node2.type === types.AST_NODE_TYPES.Identifier && node2.name === memberExpression.object.name;
|
|
3251
|
+
if (isMatch(props)) {
|
|
3252
|
+
context.report({
|
|
3253
|
+
messageId: "preferDestructuringAssignment",
|
|
3254
|
+
node: memberExpression,
|
|
3255
|
+
data: {
|
|
3256
|
+
name: "props"
|
|
3257
|
+
}
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
if (isMatch(ctx2)) {
|
|
3261
|
+
context.report({
|
|
3262
|
+
messageId: "preferDestructuringAssignment",
|
|
3263
|
+
node: memberExpression,
|
|
3264
|
+
data: {
|
|
3265
|
+
name: "context"
|
|
3266
|
+
}
|
|
3267
|
+
});
|
|
3250
3268
|
}
|
|
3251
3269
|
}
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
|
-
|
|
3255
|
-
});
|
|
3270
|
+
}
|
|
3271
|
+
};
|
|
3272
|
+
}
|
|
3256
3273
|
var RULE_NAME48 = "prefer-react-namespace-import";
|
|
3257
3274
|
var RULE_FEATURES47 = [
|
|
3258
3275
|
"CHK",
|
|
@@ -3272,41 +3289,42 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
3272
3289
|
schema: []
|
|
3273
3290
|
},
|
|
3274
3291
|
name: RULE_NAME48,
|
|
3275
|
-
create
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
);
|
|
3296
|
-
}
|
|
3297
|
-
const specifiers = sourceCode.slice(sourceCode.indexOf("{"), sourceCode.indexOf("}") + 1);
|
|
3292
|
+
create: create46,
|
|
3293
|
+
defaultOptions: []
|
|
3294
|
+
});
|
|
3295
|
+
function create46(context) {
|
|
3296
|
+
const { importSource } = shared.getSettingsFromContext(context);
|
|
3297
|
+
return {
|
|
3298
|
+
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3299
|
+
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
3300
|
+
context.report({
|
|
3301
|
+
messageId: "preferReactNamespaceImport",
|
|
3302
|
+
node: hasOtherSpecifiers ? node : node.parent,
|
|
3303
|
+
data: { importSource },
|
|
3304
|
+
fix(fixer) {
|
|
3305
|
+
const quote = node.parent.source.raw.at(0) ?? "'";
|
|
3306
|
+
const isTypeImport = node.parent.importKind === "type";
|
|
3307
|
+
const importStringPrefix = `import${isTypeImport ? " type" : ""}`;
|
|
3308
|
+
const importSourceQuoted = `${quote}${importSource}${quote}`;
|
|
3309
|
+
const sourceCode = context.sourceCode.getText(node.parent);
|
|
3310
|
+
const semiColon = sourceCode.endsWith(";") ? ";" : "";
|
|
3311
|
+
if (!hasOtherSpecifiers) {
|
|
3298
3312
|
return fixer.replaceText(
|
|
3299
3313
|
node.parent,
|
|
3300
|
-
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semiColon}
|
|
3301
|
-
${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semiColon}`
|
|
3314
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semiColon}`
|
|
3302
3315
|
);
|
|
3303
3316
|
}
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3317
|
+
const specifiers = sourceCode.slice(sourceCode.indexOf("{"), sourceCode.indexOf("}") + 1);
|
|
3318
|
+
return fixer.replaceText(
|
|
3319
|
+
node.parent,
|
|
3320
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semiColon}
|
|
3321
|
+
${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semiColon}`
|
|
3322
|
+
);
|
|
3323
|
+
}
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
};
|
|
3327
|
+
}
|
|
3310
3328
|
var RULE_NAME49 = "prefer-read-only-props";
|
|
3311
3329
|
var RULE_FEATURES48 = [
|
|
3312
3330
|
"CHK",
|
|
@@ -3325,29 +3343,30 @@ var prefer_read_only_props_default = createRule({
|
|
|
3325
3343
|
schema: []
|
|
3326
3344
|
},
|
|
3327
3345
|
name: RULE_NAME49,
|
|
3328
|
-
create
|
|
3329
|
-
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
3330
|
-
const { ctx, listeners } = core.useComponentCollector(context);
|
|
3331
|
-
return {
|
|
3332
|
-
...listeners,
|
|
3333
|
-
"Program:exit"(node) {
|
|
3334
|
-
const components = ctx.getAllComponents(node);
|
|
3335
|
-
for (const [, component] of components) {
|
|
3336
|
-
const [props] = component.node.params;
|
|
3337
|
-
if (props == null) {
|
|
3338
|
-
continue;
|
|
3339
|
-
}
|
|
3340
|
-
const propsType = typeUtils.getConstrainedTypeAtLocation(services, props);
|
|
3341
|
-
if (typeUtils.isTypeReadonly(services.program, propsType)) {
|
|
3342
|
-
continue;
|
|
3343
|
-
}
|
|
3344
|
-
context.report({ messageId: "preferReadOnlyProps", node: props });
|
|
3345
|
-
}
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
},
|
|
3346
|
+
create: create47,
|
|
3349
3347
|
defaultOptions: []
|
|
3350
3348
|
});
|
|
3349
|
+
function create47(context) {
|
|
3350
|
+
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
3351
|
+
const { ctx, listeners } = core.useComponentCollector(context);
|
|
3352
|
+
return {
|
|
3353
|
+
...listeners,
|
|
3354
|
+
"Program:exit"(node) {
|
|
3355
|
+
const components = ctx.getAllComponents(node);
|
|
3356
|
+
for (const [, component] of components) {
|
|
3357
|
+
const [props] = component.node.params;
|
|
3358
|
+
if (props == null) {
|
|
3359
|
+
continue;
|
|
3360
|
+
}
|
|
3361
|
+
const propsType = typeUtils.getConstrainedTypeAtLocation(services, props);
|
|
3362
|
+
if (typeUtils.isTypeReadonly(services.program, propsType)) {
|
|
3363
|
+
continue;
|
|
3364
|
+
}
|
|
3365
|
+
context.report({ messageId: "preferReadOnlyProps", node: props });
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
};
|
|
3369
|
+
}
|
|
3351
3370
|
var RULE_NAME50 = "prefer-shorthand-boolean";
|
|
3352
3371
|
var RULE_FEATURES49 = [
|
|
3353
3372
|
"CHK",
|
|
@@ -3367,28 +3386,29 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3367
3386
|
schema: []
|
|
3368
3387
|
},
|
|
3369
3388
|
name: RULE_NAME50,
|
|
3370
|
-
create
|
|
3371
|
-
return {
|
|
3372
|
-
JSXAttribute(node) {
|
|
3373
|
-
const { value } = node;
|
|
3374
|
-
const propName = JSX8__namespace.getAttributeName(node);
|
|
3375
|
-
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3376
|
-
if (!hasValueTrue) {
|
|
3377
|
-
return;
|
|
3378
|
-
}
|
|
3379
|
-
context.report({
|
|
3380
|
-
messageId: "preferShorthandBoolean",
|
|
3381
|
-
node,
|
|
3382
|
-
data: {
|
|
3383
|
-
propName
|
|
3384
|
-
},
|
|
3385
|
-
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3386
|
-
});
|
|
3387
|
-
}
|
|
3388
|
-
};
|
|
3389
|
-
},
|
|
3389
|
+
create: create48,
|
|
3390
3390
|
defaultOptions: []
|
|
3391
3391
|
});
|
|
3392
|
+
function create48(context) {
|
|
3393
|
+
return {
|
|
3394
|
+
JSXAttribute(node) {
|
|
3395
|
+
const { value } = node;
|
|
3396
|
+
const propName = JSX8__namespace.getAttributeName(node);
|
|
3397
|
+
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3398
|
+
if (!hasValueTrue) {
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
context.report({
|
|
3402
|
+
messageId: "preferShorthandBoolean",
|
|
3403
|
+
node,
|
|
3404
|
+
data: {
|
|
3405
|
+
propName
|
|
3406
|
+
},
|
|
3407
|
+
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3392
3412
|
var RULE_NAME51 = "prefer-shorthand-fragment";
|
|
3393
3413
|
var RULE_FEATURES50 = [
|
|
3394
3414
|
"CHK",
|
|
@@ -3408,33 +3428,34 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3408
3428
|
schema: []
|
|
3409
3429
|
},
|
|
3410
3430
|
name: RULE_NAME51,
|
|
3411
|
-
create
|
|
3412
|
-
return {
|
|
3413
|
-
JSXElement(node) {
|
|
3414
|
-
if (!JSX8__namespace.isFragmentElement(node)) return;
|
|
3415
|
-
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3416
|
-
if (hasAttributes) {
|
|
3417
|
-
return;
|
|
3418
|
-
}
|
|
3419
|
-
context.report({
|
|
3420
|
-
messageId: "preferShorthandFragment",
|
|
3421
|
-
node,
|
|
3422
|
-
fix: (fixer) => {
|
|
3423
|
-
const { closingElement, openingElement } = node;
|
|
3424
|
-
if (closingElement == null) {
|
|
3425
|
-
return [];
|
|
3426
|
-
}
|
|
3427
|
-
return [
|
|
3428
|
-
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3429
|
-
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3430
|
-
];
|
|
3431
|
-
}
|
|
3432
|
-
});
|
|
3433
|
-
}
|
|
3434
|
-
};
|
|
3435
|
-
},
|
|
3431
|
+
create: create49,
|
|
3436
3432
|
defaultOptions: []
|
|
3437
3433
|
});
|
|
3434
|
+
function create49(context) {
|
|
3435
|
+
return {
|
|
3436
|
+
JSXElement(node) {
|
|
3437
|
+
if (!JSX8__namespace.isFragmentElement(node)) return;
|
|
3438
|
+
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3439
|
+
if (hasAttributes) {
|
|
3440
|
+
return;
|
|
3441
|
+
}
|
|
3442
|
+
context.report({
|
|
3443
|
+
messageId: "preferShorthandFragment",
|
|
3444
|
+
node,
|
|
3445
|
+
fix: (fixer) => {
|
|
3446
|
+
const { closingElement, openingElement } = node;
|
|
3447
|
+
if (closingElement == null) {
|
|
3448
|
+
return [];
|
|
3449
|
+
}
|
|
3450
|
+
return [
|
|
3451
|
+
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3452
|
+
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3453
|
+
];
|
|
3454
|
+
}
|
|
3455
|
+
});
|
|
3456
|
+
}
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3438
3459
|
var RULE_NAME52 = "use-jsx-vars";
|
|
3439
3460
|
var RULE_FEATURES51 = [];
|
|
3440
3461
|
var use_jsx_vars_default = createRule({
|
|
@@ -3450,30 +3471,31 @@ var use_jsx_vars_default = createRule({
|
|
|
3450
3471
|
schema: []
|
|
3451
3472
|
},
|
|
3452
3473
|
name: RULE_NAME52,
|
|
3453
|
-
create
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3474
|
+
create: create50,
|
|
3475
|
+
defaultOptions: []
|
|
3476
|
+
});
|
|
3477
|
+
function create50(context) {
|
|
3478
|
+
return {
|
|
3479
|
+
JSXOpeningElement(node) {
|
|
3480
|
+
switch (node.name.type) {
|
|
3481
|
+
case types.AST_NODE_TYPES.JSXIdentifier: {
|
|
3482
|
+
if (/^[a-z]/u.test(node.name.name)) {
|
|
3483
|
+
return;
|
|
3463
3484
|
}
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3485
|
+
context.sourceCode.markVariableAsUsed(node.name.name, node);
|
|
3486
|
+
break;
|
|
3487
|
+
}
|
|
3488
|
+
case types.AST_NODE_TYPES.JSXMemberExpression: {
|
|
3489
|
+
const { object } = node.name;
|
|
3490
|
+
if (object.type === types.AST_NODE_TYPES.JSXIdentifier) {
|
|
3491
|
+
context.sourceCode.markVariableAsUsed(object.name, node);
|
|
3470
3492
|
}
|
|
3493
|
+
break;
|
|
3471
3494
|
}
|
|
3472
3495
|
}
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
|
|
3476
|
-
});
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
}
|
|
3477
3499
|
|
|
3478
3500
|
// src/plugin.ts
|
|
3479
3501
|
var plugin = {
|