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