eslint-plugin-react-x 1.23.2 → 1.23.3-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +517 -173
  2. package/dist/index.mjs +517 -173
  3. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
15
15
 
16
16
  // package.json
17
17
  var name = "eslint-plugin-react-x";
18
- var version = "1.23.2";
18
+ var version = "1.23.3-next.0";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -105,11 +105,17 @@ var ensure_forward_ref_using_ref_default = createRule({
105
105
  create(context) {
106
106
  return {
107
107
  CallExpression(node) {
108
- if (!isForwardRefCall(node, context)) return;
108
+ if (!isForwardRefCall(node, context)) {
109
+ return;
110
+ }
109
111
  const [component] = node.arguments;
110
- if (!component || !AST11.isFunction(component)) return;
112
+ if (!component || !AST11.isFunction(component)) {
113
+ return;
114
+ }
111
115
  const [_, ref] = component.params;
112
- if (ref) return;
116
+ if (ref) {
117
+ return;
118
+ }
113
119
  context.report({
114
120
  messageId: "ensureForwardRefUsingRef",
115
121
  node: component
@@ -152,17 +158,23 @@ var no_access_state_in_setstate_default = createRule({
152
158
  },
153
159
  name: RULE_NAME4,
154
160
  create(context) {
155
- if (!context.sourceCode.text.includes("setState")) return {};
161
+ if (!context.sourceCode.text.includes("setState")) {
162
+ return {};
163
+ }
156
164
  const classStack = [];
157
165
  const methodStack = [];
158
166
  const setStateStack = [];
159
167
  return {
160
168
  CallExpression(node) {
161
- if (!isThisSetState(node)) return;
169
+ if (!isThisSetState(node)) {
170
+ return;
171
+ }
162
172
  setStateStack.push([node, false]);
163
173
  },
164
174
  "CallExpression:exit"(node) {
165
- if (!isThisSetState(node)) return;
175
+ if (!isThisSetState(node)) {
176
+ return;
177
+ }
166
178
  setStateStack.pop();
167
179
  },
168
180
  ClassDeclaration(node) {
@@ -178,14 +190,24 @@ var no_access_state_in_setstate_default = createRule({
178
190
  classStack.pop();
179
191
  },
180
192
  MemberExpression(node) {
181
- if (!AST11.isThisExpression(node.object)) return;
193
+ if (!AST11.isThisExpression(node.object)) {
194
+ return;
195
+ }
182
196
  const [currClass, isComponent] = classStack.at(-1) ?? [];
183
- if (!currClass || !isComponent) return;
197
+ if (!currClass || !isComponent) {
198
+ return;
199
+ }
184
200
  const [currMethod, isStatic] = methodStack.at(-1) ?? [];
185
- if (!currMethod || isStatic) return;
201
+ if (!currMethod || isStatic) {
202
+ return;
203
+ }
186
204
  const [setState, hasThisState] = setStateStack.at(-1) ?? [];
187
- if (!setState || hasThisState) return;
188
- if (!O.exists(getName(node.property), (name2) => name2 === "state")) return;
205
+ if (!setState || hasThisState) {
206
+ return;
207
+ }
208
+ if (!O.exists(getName(node.property), (name2) => name2 === "state")) {
209
+ return;
210
+ }
189
211
  context.report({ messageId: "noAccessStateInSetstate", node });
190
212
  },
191
213
  MethodDefinition(node) {
@@ -202,19 +224,29 @@ var no_access_state_in_setstate_default = createRule({
202
224
  },
203
225
  VariableDeclarator(node) {
204
226
  const [currClass, isComponent] = classStack.at(-1) ?? [];
205
- if (!currClass || !isComponent) return;
227
+ if (!currClass || !isComponent) {
228
+ return;
229
+ }
206
230
  const [currMethod, isStatic] = methodStack.at(-1) ?? [];
207
- if (!currMethod || isStatic) return;
231
+ if (!currMethod || isStatic) {
232
+ return;
233
+ }
208
234
  const [setState, hasThisState] = setStateStack.at(-1) ?? [];
209
- if (!setState || hasThisState) return;
210
- if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) return;
235
+ if (!setState || hasThisState) {
236
+ return;
237
+ }
238
+ if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
239
+ return;
240
+ }
211
241
  const hasState = node.id.properties.some((prop) => {
212
242
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
213
243
  return O.exists(getName(prop.key), (name2) => name2 === "state");
214
244
  }
215
245
  return false;
216
246
  });
217
- if (!hasState) return;
247
+ if (!hasState) {
248
+ return;
249
+ }
218
250
  context.report({ messageId: "noAccessStateInSetstate", node });
219
251
  }
220
252
  };
@@ -259,9 +291,13 @@ function isUsingReactChildren(node, context) {
259
291
  if (!("property" in callee) || !("object" in callee) || !("name" in callee.property)) {
260
292
  return false;
261
293
  }
262
- if (!isReactChildrenMethod(callee.property.name)) return false;
294
+ if (!isReactChildrenMethod(callee.property.name)) {
295
+ return false;
296
+ }
263
297
  const initialScope = context.sourceCode.getScope(node);
264
- if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children") return true;
298
+ if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children") {
299
+ return true;
300
+ }
265
301
  if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
266
302
  return isInitializedFromReact(callee.object.object.name, initialScope, settings.importSource);
267
303
  }
@@ -269,19 +305,31 @@ function isUsingReactChildren(node, context) {
269
305
  }
270
306
  function getMapIndexParamName(node, context) {
271
307
  const { callee } = node;
272
- if (callee.type !== AST_NODE_TYPES.MemberExpression) return O.none();
273
- if (callee.property.type !== AST_NODE_TYPES.Identifier) return O.none();
308
+ if (callee.type !== AST_NODE_TYPES.MemberExpression) {
309
+ return O.none();
310
+ }
311
+ if (callee.property.type !== AST_NODE_TYPES.Identifier) {
312
+ return O.none();
313
+ }
274
314
  const { name: name2 } = callee.property;
275
- if (!iteratorFunctionIndexParamPosition.has(name2)) return O.none();
315
+ if (!iteratorFunctionIndexParamPosition.has(name2)) {
316
+ return O.none();
317
+ }
276
318
  const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
277
- if (!callbackArg) return O.none();
319
+ if (!callbackArg) {
320
+ return O.none();
321
+ }
278
322
  if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
279
323
  return O.none();
280
324
  }
281
325
  const { params } = callbackArg;
282
326
  const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
283
- if (isNullable(indexParamPosition)) return O.none();
284
- if (params.length < indexParamPosition + 1) return O.none();
327
+ if (isNullable(indexParamPosition)) {
328
+ return O.none();
329
+ }
330
+ if (params.length < indexParamPosition + 1) {
331
+ return O.none();
332
+ }
285
333
  const param = params.at(indexParamPosition);
286
334
  return param && "name" in param ? O.some(param.name) : O.none();
287
335
  }
@@ -305,16 +353,22 @@ var no_array_index_key_default = createRule({
305
353
  return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
306
354
  }
307
355
  function getReportDescriptor(node) {
308
- if (isArrayIndex(node)) return [{ messageId: "noArrayIndexKey", node }];
356
+ if (isArrayIndex(node)) {
357
+ return [{ messageId: "noArrayIndexKey", node }];
358
+ }
309
359
  if (AST11.isOneOf([AST_NODE_TYPES.TemplateLiteral, AST_NODE_TYPES.BinaryExpression])(node)) {
310
360
  const exps = AST_NODE_TYPES.TemplateLiteral === node.type ? node.expressions : AST11.getIdentifiersFromBinaryExpression(node);
311
361
  return exps.reduce((acc, exp) => {
312
- if (isArrayIndex(exp)) return [...acc, { messageId: "noArrayIndexKey", node: exp }];
362
+ if (isArrayIndex(exp)) {
363
+ return [...acc, { messageId: "noArrayIndexKey", node: exp }];
364
+ }
313
365
  return acc;
314
366
  }, []);
315
367
  }
316
368
  if (isToStringCall(node)) {
317
- if (!("object" in node.callee && isArrayIndex(node.callee.object))) return [];
369
+ if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
370
+ return [];
371
+ }
318
372
  return [{ messageId: "noArrayIndexKey", node: node.callee.object }];
319
373
  }
320
374
  const isStringCall = isMatching({
@@ -326,20 +380,32 @@ var no_array_index_key_default = createRule({
326
380
  }, node);
327
381
  if (isStringCall) {
328
382
  const [arg] = node.arguments;
329
- if (arg && isArrayIndex(arg)) return [{ messageId: "noArrayIndexKey", node: arg }];
383
+ if (arg && isArrayIndex(arg)) {
384
+ return [{ messageId: "noArrayIndexKey", node: arg }];
385
+ }
330
386
  }
331
387
  return [];
332
388
  }
333
389
  return {
334
390
  CallExpression(node) {
335
391
  indexParamNames.push(getMapIndexParamName(node, context));
336
- if (node.arguments.length === 0) return;
337
- if (!isCreateOrCloneElementCall(node)) return;
392
+ if (node.arguments.length === 0) {
393
+ return;
394
+ }
395
+ if (!isCreateOrCloneElementCall(node)) {
396
+ return;
397
+ }
338
398
  const [_, props] = node.arguments;
339
- if (props?.type !== AST_NODE_TYPES.ObjectExpression) return;
399
+ if (props?.type !== AST_NODE_TYPES.ObjectExpression) {
400
+ return;
401
+ }
340
402
  for (const prop of props.properties) {
341
- if (!isMatching({ key: { name: "key" } })(prop)) continue;
342
- if (!("value" in prop)) continue;
403
+ if (!isMatching({ key: { name: "key" } })(prop)) {
404
+ continue;
405
+ }
406
+ if (!("value" in prop)) {
407
+ continue;
408
+ }
343
409
  const descriptors = getReportDescriptor(prop.value);
344
410
  for (const descriptor of descriptors) {
345
411
  context.report(descriptor);
@@ -350,10 +416,16 @@ var no_array_index_key_default = createRule({
350
416
  indexParamNames.pop();
351
417
  },
352
418
  JSXAttribute(node) {
353
- if (node.name.name !== "key") return;
354
- if (indexParamNames.length === 0) return;
419
+ if (node.name.name !== "key") {
420
+ return;
421
+ }
422
+ if (indexParamNames.length === 0) {
423
+ return;
424
+ }
355
425
  const { value } = node;
356
- if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
426
+ if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
427
+ return;
428
+ }
357
429
  const descriptors = getReportDescriptor(value.expression);
358
430
  for (const descriptor of descriptors) {
359
431
  context.report(descriptor);
@@ -581,14 +653,18 @@ var no_class_component_default = createRule({
581
653
  },
582
654
  name: RULE_NAME12,
583
655
  create(context) {
584
- if (!context.sourceCode.text.includes("Component")) return {};
656
+ if (!context.sourceCode.text.includes("Component")) {
657
+ return {};
658
+ }
585
659
  const { ctx, listeners } = useComponentCollectorLegacy();
586
660
  return {
587
661
  ...listeners,
588
662
  "Program:exit"(node) {
589
663
  const components = ctx.getAllComponents(node);
590
664
  for (const { name: name2, node: component } of components.values()) {
591
- if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) continue;
665
+ if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
666
+ continue;
667
+ }
592
668
  context.report({
593
669
  messageId: "noClassComponent",
594
670
  node: component,
@@ -623,7 +699,9 @@ var no_clone_element_default = createRule({
623
699
  create(context) {
624
700
  return {
625
701
  CallExpression(node) {
626
- if (!isCloneElementCall(node, context)) return;
702
+ if (!isCloneElementCall(node, context)) {
703
+ return;
704
+ }
627
705
  context.report({
628
706
  messageId: "noCloneElement",
629
707
  node
@@ -652,14 +730,22 @@ var no_comment_textnodes_default = createRule({
652
730
  name: RULE_NAME14,
653
731
  create(context) {
654
732
  function hasCommentLike(node) {
655
- if (AST11.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) return false;
733
+ if (AST11.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
734
+ return false;
735
+ }
656
736
  const rawValue = context.sourceCode.getText(node);
657
737
  return /^\s*\/(?:\/|\*)/mu.test(rawValue);
658
738
  }
659
739
  const getReportDescriptor = (node) => {
660
- if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) return O.none();
661
- if (!hasCommentLike(node)) return O.none();
662
- if (!node.parent.type.includes("JSX")) return O.none();
740
+ if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
741
+ return O.none();
742
+ }
743
+ if (!hasCommentLike(node)) {
744
+ return O.none();
745
+ }
746
+ if (!node.parent.type.includes("JSX")) {
747
+ return O.none();
748
+ }
663
749
  return O.some({
664
750
  messageId: "noCommentTextnodes",
665
751
  node
@@ -693,11 +779,15 @@ var no_complex_conditional_rendering_default = createRule({
693
779
  create(context) {
694
780
  function getReportDescriptor(node) {
695
781
  const jsxExpContainer = node.parent?.parent;
696
- if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) return O.none();
782
+ if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
783
+ return O.none();
784
+ }
697
785
  if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
698
786
  return O.none();
699
787
  }
700
- if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) return O.none();
788
+ if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
789
+ return O.none();
790
+ }
701
791
  return O.some({ messageId: "noComplexConditionalRendering", node: jsxExpContainer });
702
792
  }
703
793
  const visitorFunction = F.flow(getReportDescriptor, O.map(context.report), F.constVoid);
@@ -734,7 +824,9 @@ var no_component_will_mount_default = createRule({
734
824
  },
735
825
  name: RULE_NAME16,
736
826
  create(context) {
737
- if (!context.sourceCode.text.includes("componentWillMount")) return {};
827
+ if (!context.sourceCode.text.includes("componentWillMount")) {
828
+ return {};
829
+ }
738
830
  const { ctx, listeners } = useComponentCollectorLegacy();
739
831
  return {
740
832
  ...listeners,
@@ -748,7 +840,9 @@ var no_component_will_mount_default = createRule({
748
840
  messageId: "noComponentWillMount",
749
841
  node: member,
750
842
  fix(fixer) {
751
- if (!("key" in member)) return null;
843
+ if (!("key" in member)) {
844
+ return null;
845
+ }
752
846
  return fixer.replaceText(member.key, "UNSAFE_componentWillMount");
753
847
  }
754
848
  });
@@ -783,7 +877,9 @@ var no_component_will_receive_props_default = createRule({
783
877
  },
784
878
  name: RULE_NAME17,
785
879
  create(context) {
786
- if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
880
+ if (!context.sourceCode.text.includes("componentWillReceiveProps")) {
881
+ return {};
882
+ }
787
883
  const { ctx, listeners } = useComponentCollectorLegacy();
788
884
  return {
789
885
  ...listeners,
@@ -797,7 +893,9 @@ var no_component_will_receive_props_default = createRule({
797
893
  messageId: "noComponentWillReceiveProps",
798
894
  node: member,
799
895
  fix(fixer) {
800
- if (!("key" in member)) return null;
896
+ if (!("key" in member)) {
897
+ return null;
898
+ }
801
899
  return fixer.replaceText(member.key, "UNSAFE_componentWillReceiveProps");
802
900
  }
803
901
  });
@@ -832,7 +930,9 @@ var no_component_will_update_default = createRule({
832
930
  },
833
931
  name: RULE_NAME18,
834
932
  create(context) {
835
- if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
933
+ if (!context.sourceCode.text.includes("componentWillUpdate")) {
934
+ return {};
935
+ }
836
936
  const { ctx, listeners } = useComponentCollectorLegacy();
837
937
  return {
838
938
  ...listeners,
@@ -846,7 +946,9 @@ var no_component_will_update_default = createRule({
846
946
  messageId: "noComponentWillUpdate",
847
947
  node: member,
848
948
  fix(fixer) {
849
- if (!("key" in member)) return null;
949
+ if (!("key" in member)) {
950
+ return null;
951
+ }
850
952
  return fixer.replaceText(member.key, "UNSAFE_componentWillUpdate");
851
953
  }
852
954
  });
@@ -878,13 +980,19 @@ var no_context_provider_default = createRule({
878
980
  },
879
981
  name: RULE_NAME19,
880
982
  create(context) {
881
- if (!context.sourceCode.text.includes(".Provider")) return {};
983
+ if (!context.sourceCode.text.includes(".Provider")) {
984
+ return {};
985
+ }
882
986
  const { version: version2 } = getSettingsFromContext(context);
883
- if (compare(version2, "19.0.0", "<")) return {};
987
+ if (compare(version2, "19.0.0", "<")) {
988
+ return {};
989
+ }
884
990
  return {
885
991
  JSXElement(node) {
886
992
  const elementName = JSX7.getElementName(node.openingElement);
887
- if (!elementName.endsWith(".Provider")) return;
993
+ if (!elementName.endsWith(".Provider")) {
994
+ return;
995
+ }
888
996
  context.report({
889
997
  messageId: "noContextProvider",
890
998
  node,
@@ -892,7 +1000,9 @@ var no_context_provider_default = createRule({
892
1000
  const providerName = elementName.replace(/\.Provider$/, "");
893
1001
  const openingElement = node.openingElement;
894
1002
  const closingElement = node.closingElement;
895
- if (!closingElement) return fixer.replaceText(openingElement.name, providerName);
1003
+ if (!closingElement) {
1004
+ return fixer.replaceText(openingElement.name, providerName);
1005
+ }
896
1006
  return [
897
1007
  fixer.replaceText(openingElement.name, providerName),
898
1008
  fixer.replaceText(closingElement.name, providerName)
@@ -924,8 +1034,12 @@ var no_create_ref_default = createRule({
924
1034
  create(context) {
925
1035
  return {
926
1036
  CallExpression(node) {
927
- if (!isCreateRefCall(node, context)) return;
928
- if (O.isSome(AST11.findParentNode(node, isClassComponent))) return;
1037
+ if (!isCreateRefCall(node, context)) {
1038
+ return;
1039
+ }
1040
+ if (O.isSome(AST11.findParentNode(node, isClassComponent))) {
1041
+ return;
1042
+ }
929
1043
  context.report({ messageId: "noCreateRef", node });
930
1044
  }
931
1045
  };
@@ -950,25 +1064,41 @@ var no_default_props_default = createRule({
950
1064
  },
951
1065
  name: RULE_NAME21,
952
1066
  create(context) {
953
- if (!context.sourceCode.text.includes("defaultProps")) return {};
1067
+ if (!context.sourceCode.text.includes("defaultProps")) {
1068
+ return {};
1069
+ }
954
1070
  return {
955
1071
  AssignmentExpression(node) {
956
- if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) return;
1072
+ if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) {
1073
+ return;
1074
+ }
957
1075
  const { object, property } = node.left;
958
- if (object.type !== AST_NODE_TYPES.Identifier) return;
959
- if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") return;
960
- if (!isComponentName(object.name)) return;
1076
+ if (object.type !== AST_NODE_TYPES.Identifier) {
1077
+ return;
1078
+ }
1079
+ if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
1080
+ return;
1081
+ }
1082
+ if (!isComponentName(object.name)) {
1083
+ return;
1084
+ }
961
1085
  const isComponent = F.pipe(
962
1086
  VAR.findVariable(object.name, context.sourceCode.getScope(node)),
963
1087
  O.flatMap(VAR.getVariableNode(0)),
964
1088
  O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
965
1089
  );
966
- if (!isComponent) return;
1090
+ if (!isComponent) {
1091
+ return;
1092
+ }
967
1093
  context.report({ messageId: "noDefaultProps", node: property });
968
1094
  },
969
1095
  PropertyDefinition(node) {
970
- if (!isClassComponent(node.parent.parent)) return;
971
- if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") return;
1096
+ if (!isClassComponent(node.parent.parent)) {
1097
+ return;
1098
+ }
1099
+ if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
1100
+ return;
1101
+ }
972
1102
  context.report({ messageId: "noDefaultProps", node });
973
1103
  }
974
1104
  };
@@ -1016,7 +1146,9 @@ var no_direct_mutation_state_default = createRule({
1016
1146
  name: RULE_NAME22,
1017
1147
  create(context) {
1018
1148
  function getReportDescriptor(node) {
1019
- if (!isAssignmentToThisState(node)) return O.none();
1149
+ if (!isAssignmentToThisState(node)) {
1150
+ return O.none();
1151
+ }
1020
1152
  return F.pipe(
1021
1153
  O.Do,
1022
1154
  O.bind("parentClass", () => AST11.findParentNodeGuard(
@@ -1064,9 +1196,13 @@ var no_duplicate_jsx_props_default = createRule({
1064
1196
  JSXOpeningElement(node) {
1065
1197
  const props = [];
1066
1198
  for (const attr of node.attributes) {
1067
- if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) continue;
1199
+ if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
1200
+ continue;
1201
+ }
1068
1202
  const name2 = attr.name.name;
1069
- if (!isString(name2)) continue;
1203
+ if (!isString(name2)) {
1204
+ continue;
1205
+ }
1070
1206
  if (!props.includes(name2)) {
1071
1207
  props.push(name2);
1072
1208
  continue;
@@ -1099,12 +1235,16 @@ var no_duplicate_key_default = createRule({
1099
1235
  },
1100
1236
  name: RULE_NAME24,
1101
1237
  create(context) {
1102
- if (!context.sourceCode.getText().includes("key=")) return {};
1238
+ if (!context.sourceCode.getText().includes("key=")) {
1239
+ return {};
1240
+ }
1103
1241
  const keyedEntries = /* @__PURE__ */ new Map();
1104
1242
  function isKeyValueEqual(a, b) {
1105
1243
  const aValue = a.value;
1106
1244
  const bValue = b.value;
1107
- if (aValue === null || bValue === null) return false;
1245
+ if (aValue === null || bValue === null) {
1246
+ return false;
1247
+ }
1108
1248
  return AST11.isNodeEqual(aValue, bValue);
1109
1249
  }
1110
1250
  return {
@@ -1130,9 +1270,13 @@ var no_duplicate_key_default = createRule({
1130
1270
  O.bind("iter", ({ call: call2 }) => AST11.findParentNodeStop(jsxElement, call2, AST11.isFunction)),
1131
1271
  O.bind("arg0", ({ call: call2 }) => O.fromNullable(call2.arguments[0]))
1132
1272
  );
1133
- if (O.isNone(mbEntry)) return;
1273
+ if (O.isNone(mbEntry)) {
1274
+ return;
1275
+ }
1134
1276
  const { arg0, call, iter } = mbEntry.value;
1135
- if (AST11.unwrapTypeExpression(arg0) !== iter) return;
1277
+ if (AST11.unwrapTypeExpression(arg0) !== iter) {
1278
+ return;
1279
+ }
1136
1280
  keyedEntries.set(call, {
1137
1281
  hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
1138
1282
  keys: [node],
@@ -1143,7 +1287,9 @@ var no_duplicate_key_default = createRule({
1143
1287
  },
1144
1288
  "Program:exit"() {
1145
1289
  for (const { hasDuplicate, keys } of keyedEntries.values()) {
1146
- if (!hasDuplicate) continue;
1290
+ if (!hasDuplicate) {
1291
+ continue;
1292
+ }
1147
1293
  for (const key of keys) {
1148
1294
  context.report({
1149
1295
  messageId: "noDuplicateKey",
@@ -1179,12 +1325,18 @@ var no_forward_ref_default = createRule({
1179
1325
  },
1180
1326
  name: RULE_NAME25,
1181
1327
  create(context) {
1182
- if (!context.sourceCode.text.includes("forwardRef")) return {};
1328
+ if (!context.sourceCode.text.includes("forwardRef")) {
1329
+ return {};
1330
+ }
1183
1331
  const { version: version2 } = getSettingsFromContext(context);
1184
- if (compare(version2, "19.0.0", "<")) return {};
1332
+ if (compare(version2, "19.0.0", "<")) {
1333
+ return {};
1334
+ }
1185
1335
  return {
1186
1336
  CallExpression(node) {
1187
- if (!isForwardRefCall(node, context)) return;
1337
+ if (!isForwardRefCall(node, context)) {
1338
+ return;
1339
+ }
1188
1340
  context.report({
1189
1341
  messageId: "noForwardRef",
1190
1342
  node,
@@ -1198,7 +1350,9 @@ var no_forward_ref_default = createRule({
1198
1350
  function getFix(node, context) {
1199
1351
  return (fixer) => {
1200
1352
  const [componentNode] = node.arguments;
1201
- if (!componentNode || !AST11.isFunction(componentNode)) return [];
1353
+ if (!componentNode || !AST11.isFunction(componentNode)) {
1354
+ return [];
1355
+ }
1202
1356
  return [
1203
1357
  // unwrap component from forwardRef call
1204
1358
  fixer.removeRange([node.range[0], componentNode.range[0]]),
@@ -1217,10 +1371,14 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
1217
1371
  const getText = (node2) => context.sourceCode.getText(node2);
1218
1372
  const [arg0, arg1] = node.params;
1219
1373
  const [typeArg0, typeArg1] = typeArguments;
1220
- if (!arg0) return [];
1374
+ if (!arg0) {
1375
+ return [];
1376
+ }
1221
1377
  const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => O.some(`...${n.name}`)).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => O.some(n.properties.map(getText).join(", "))).otherwise(O.none);
1222
1378
  const fixedArg1Text = match(arg1).with(P.nullish, () => O.some("ref")).with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => O.some("ref")).with({ type: AST_NODE_TYPES.Identifier, name: P.not("ref") }, (n) => O.some(`ref: ${n.name}`)).otherwise(O.none);
1223
- if (O.isNone(fixedArg0Text) || O.isNone(fixedArg1Text)) return [];
1379
+ if (O.isNone(fixedArg0Text) || O.isNone(fixedArg1Text)) {
1380
+ return [];
1381
+ }
1224
1382
  const fixedPropsText = fixedArg0Text.value;
1225
1383
  const fixedRefText = fixedArg1Text.value;
1226
1384
  if (!typeArg0 || !typeArg1) {
@@ -1400,7 +1558,9 @@ var no_leaked_conditional_rendering_default = createRule({
1400
1558
  },
1401
1559
  name: RULE_NAME27,
1402
1560
  create(context) {
1403
- if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) return {};
1561
+ if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) {
1562
+ return {};
1563
+ }
1404
1564
  const { version: version2 } = getSettingsFromContext(context);
1405
1565
  const allowedVariants = [
1406
1566
  "any",
@@ -1418,7 +1578,9 @@ var no_leaked_conditional_rendering_default = createRule({
1418
1578
  function getReportDescriptor(node) {
1419
1579
  return match(node).when(AST11.isJSX, O.none).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1420
1580
  const isLeftUnaryNot = isMatching({ type: AST_NODE_TYPES.UnaryExpression, operator: "!" }, left);
1421
- if (isLeftUnaryNot) return getReportDescriptor(right);
1581
+ if (isLeftUnaryNot) {
1582
+ return getReportDescriptor(right);
1583
+ }
1422
1584
  const initialScope = context.sourceCode.getScope(left);
1423
1585
  const isLeftNan = isMatching({ type: AST_NODE_TYPES.Identifier, name: "NaN" }, left) || O.exists(VAR.getStaticValue(left, initialScope), (v) => v === "NaN");
1424
1586
  if (isLeftNan) {
@@ -1431,7 +1593,9 @@ var no_leaked_conditional_rendering_default = createRule({
1431
1593
  const leftType = getConstrainedTypeAtLocation(services, left);
1432
1594
  const leftTypeVariants = inspectVariantTypes(unionTypeParts(leftType));
1433
1595
  const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
1434
- if (isLeftValid) return getReportDescriptor(right);
1596
+ if (isLeftValid) {
1597
+ return getReportDescriptor(right);
1598
+ }
1435
1599
  return O.some({
1436
1600
  messageId: "noLeakedConditionalRendering",
1437
1601
  node: left,
@@ -1473,7 +1637,9 @@ var no_missing_component_display_name_default = createRule({
1473
1637
  },
1474
1638
  name: RULE_NAME28,
1475
1639
  create(context) {
1476
- if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
1640
+ if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
1641
+ return {};
1642
+ }
1477
1643
  const { ctx, listeners } = useComponentCollector(context);
1478
1644
  return {
1479
1645
  ...listeners,
@@ -1481,8 +1647,12 @@ var no_missing_component_display_name_default = createRule({
1481
1647
  const components = ctx.getAllComponents(node);
1482
1648
  for (const { node: node2, displayName, flag } of components.values()) {
1483
1649
  const isMemoOrForwardRef = Boolean(flag & ERFunctionComponentFlag.ForwardRef) || Boolean(flag & ERFunctionComponentFlag.Memo);
1484
- if (O.isSome(AST11.getFunctionIdentifier(node2))) continue;
1485
- if (!isMemoOrForwardRef) continue;
1650
+ if (O.isSome(AST11.getFunctionIdentifier(node2))) {
1651
+ continue;
1652
+ }
1653
+ if (!isMemoOrForwardRef) {
1654
+ continue;
1655
+ }
1486
1656
  if (O.isNone(displayName)) {
1487
1657
  context.report({
1488
1658
  messageId: "noMissingComponentDisplayName",
@@ -1540,13 +1710,17 @@ var no_missing_key_default = createRule({
1540
1710
  function checkExpression(node) {
1541
1711
  switch (node.type) {
1542
1712
  case AST_NODE_TYPES.ConditionalExpression:
1543
- if (!("consequent" in node)) return O.none();
1713
+ if (!("consequent" in node)) {
1714
+ return O.none();
1715
+ }
1544
1716
  return O.orElse(checkIteratorElement(node.consequent), () => checkIteratorElement(node.alternate));
1545
1717
  case AST_NODE_TYPES.JSXElement:
1546
1718
  case AST_NODE_TYPES.JSXFragment:
1547
1719
  return checkIteratorElement(node);
1548
1720
  case AST_NODE_TYPES.LogicalExpression:
1549
- if (!("left" in node)) return O.none();
1721
+ if (!("left" in node)) {
1722
+ return O.none();
1723
+ }
1550
1724
  return O.orElse(checkIteratorElement(node.left), () => checkIteratorElement(node.right));
1551
1725
  default:
1552
1726
  return O.none();
@@ -1554,16 +1728,22 @@ var no_missing_key_default = createRule({
1554
1728
  }
1555
1729
  function checkBlockStatement(node) {
1556
1730
  return AST11.getNestedReturnStatements(node).reduce((acc, statement) => {
1557
- if (!statement.argument) return acc;
1731
+ if (!statement.argument) {
1732
+ return acc;
1733
+ }
1558
1734
  const mbDescriptor = checkIteratorElement(statement.argument);
1559
1735
  return O.isNone(mbDescriptor) ? acc : [...acc, mbDescriptor.value];
1560
1736
  }, []);
1561
1737
  }
1562
1738
  return {
1563
1739
  ArrayExpression(node) {
1564
- if (state.isWithinChildrenToArray) return;
1740
+ if (state.isWithinChildrenToArray) {
1741
+ return;
1742
+ }
1565
1743
  const elements = node.elements.filter(AST11.is(AST_NODE_TYPES.JSXElement));
1566
- if (elements.length === 0) return;
1744
+ if (elements.length === 0) {
1745
+ return;
1746
+ }
1567
1747
  const initialScope = context.sourceCode.getScope(node);
1568
1748
  for (const element of elements) {
1569
1749
  if (!JSX7.hasProp(element.openingElement.attributes, "key", initialScope)) {
@@ -1576,7 +1756,9 @@ var no_missing_key_default = createRule({
1576
1756
  },
1577
1757
  CallExpression(node) {
1578
1758
  state.isWithinChildrenToArray ||= isChildrenToArrayCall(node, context);
1579
- if (state.isWithinChildrenToArray) return;
1759
+ if (state.isWithinChildrenToArray) {
1760
+ return;
1761
+ }
1580
1762
  const isMapCall = AST11.isMapCallLoose(node);
1581
1763
  const isArrayFromCall = isMatching({
1582
1764
  type: AST_NODE_TYPES.CallExpression,
@@ -1587,9 +1769,13 @@ var no_missing_key_default = createRule({
1587
1769
  }
1588
1770
  }
1589
1771
  }, node);
1590
- if (!isMapCall && !isArrayFromCall) return;
1772
+ if (!isMapCall && !isArrayFromCall) {
1773
+ return;
1774
+ }
1591
1775
  const fn = node.arguments[isMapCall ? 0 : 1];
1592
- if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) return;
1776
+ if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) {
1777
+ return;
1778
+ }
1593
1779
  if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
1594
1780
  for (const descriptor of checkBlockStatement(fn.body)) {
1595
1781
  context.report(descriptor);
@@ -1599,11 +1785,15 @@ var no_missing_key_default = createRule({
1599
1785
  O.map(checkExpression(fn.body), context.report);
1600
1786
  },
1601
1787
  "CallExpression:exit"(node) {
1602
- if (!isChildrenToArrayCall(node, context)) return;
1788
+ if (!isChildrenToArrayCall(node, context)) {
1789
+ return;
1790
+ }
1603
1791
  state.isWithinChildrenToArray = false;
1604
1792
  },
1605
1793
  JSXFragment(node) {
1606
- if (state.isWithinChildrenToArray) return;
1794
+ if (state.isWithinChildrenToArray) {
1795
+ return;
1796
+ }
1607
1797
  if (node.parent.type === AST_NODE_TYPES.ArrayExpression) {
1608
1798
  context.report({
1609
1799
  messageId: "noMissingKeyWithFragment",
@@ -1650,8 +1840,12 @@ var no_nested_components_default = createRule({
1650
1840
  return AST11.isClass(node2) && classComponents.some((component) => component.node === node2);
1651
1841
  };
1652
1842
  for (const { name: componentName, node: component } of functionComponents) {
1653
- if (isDirectValueOfRenderPropertyLoose(component)) continue;
1654
- if (O.isNone(componentName)) continue;
1843
+ if (isDirectValueOfRenderPropertyLoose(component)) {
1844
+ continue;
1845
+ }
1846
+ if (O.isNone(componentName)) {
1847
+ continue;
1848
+ }
1655
1849
  const name2 = componentName.value;
1656
1850
  const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
1657
1851
  const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
@@ -1739,25 +1933,41 @@ var no_prop_types_default = createRule({
1739
1933
  },
1740
1934
  name: RULE_NAME31,
1741
1935
  create(context) {
1742
- if (!context.sourceCode.text.includes("propTypes")) return {};
1936
+ if (!context.sourceCode.text.includes("propTypes")) {
1937
+ return {};
1938
+ }
1743
1939
  return {
1744
1940
  AssignmentExpression(node) {
1745
- if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) return;
1941
+ if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) {
1942
+ return;
1943
+ }
1746
1944
  const { object, property } = node.left;
1747
- if (object.type !== AST_NODE_TYPES.Identifier) return;
1748
- if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") return;
1749
- if (!isComponentName(object.name)) return;
1945
+ if (object.type !== AST_NODE_TYPES.Identifier) {
1946
+ return;
1947
+ }
1948
+ if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
1949
+ return;
1950
+ }
1951
+ if (!isComponentName(object.name)) {
1952
+ return;
1953
+ }
1750
1954
  const isComponent = F.pipe(
1751
1955
  VAR.findVariable(object.name, context.sourceCode.getScope(node)),
1752
1956
  O.flatMap(VAR.getVariableNode(0)),
1753
1957
  O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
1754
1958
  );
1755
- if (!isComponent) return;
1959
+ if (!isComponent) {
1960
+ return;
1961
+ }
1756
1962
  context.report({ messageId: "noPropTypes", node: property });
1757
1963
  },
1758
1964
  PropertyDefinition(node) {
1759
- if (!isClassComponent(node.parent.parent)) return;
1760
- if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") return;
1965
+ if (!isClassComponent(node.parent.parent)) {
1966
+ return;
1967
+ }
1968
+ if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
1969
+ return;
1970
+ }
1761
1971
  context.report({ messageId: "noPropTypes", node });
1762
1972
  }
1763
1973
  };
@@ -1785,14 +1995,18 @@ var no_redundant_should_component_update_default = createRule({
1785
1995
  },
1786
1996
  name: RULE_NAME32,
1787
1997
  create(context) {
1788
- if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
1998
+ if (!context.sourceCode.text.includes("shouldComponentUpdate")) {
1999
+ return {};
2000
+ }
1789
2001
  const { ctx, listeners } = useComponentCollectorLegacy();
1790
2002
  return {
1791
2003
  ...listeners,
1792
2004
  "Program:exit"(node) {
1793
2005
  const components = ctx.getAllComponents(node);
1794
2006
  for (const { name: name2, node: component, flag } of components.values()) {
1795
- if (!(flag & ERClassComponentFlag.PureComponent)) continue;
2007
+ if (!(flag & ERClassComponentFlag.PureComponent)) {
2008
+ continue;
2009
+ }
1796
2010
  const { body } = component.body;
1797
2011
  for (const member of body) {
1798
2012
  if (isShouldComponentUpdate(member)) {
@@ -1832,9 +2046,13 @@ var no_set_state_in_component_did_mount_default = createRule({
1832
2046
  },
1833
2047
  name: RULE_NAME33,
1834
2048
  create(context) {
1835
- if (!context.sourceCode.text.includes("componentDidMount")) return {};
2049
+ if (!context.sourceCode.text.includes("componentDidMount")) {
2050
+ return {};
2051
+ }
1836
2052
  function getReportDescriptor(node) {
1837
- if (!isThisSetState(node)) return O.none();
2053
+ if (!isThisSetState(node)) {
2054
+ return O.none();
2055
+ }
1838
2056
  return F.pipe(
1839
2057
  O.Do,
1840
2058
  O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
@@ -1882,9 +2100,13 @@ var no_set_state_in_component_did_update_default = createRule({
1882
2100
  },
1883
2101
  name: RULE_NAME34,
1884
2102
  create(context) {
1885
- if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
2103
+ if (!context.sourceCode.text.includes("componentDidUpdate")) {
2104
+ return {};
2105
+ }
1886
2106
  function getReportDescriptor(node) {
1887
- if (!isThisSetState(node)) return O.none();
2107
+ if (!isThisSetState(node)) {
2108
+ return O.none();
2109
+ }
1888
2110
  return F.pipe(
1889
2111
  O.Do,
1890
2112
  O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
@@ -1932,9 +2154,13 @@ var no_set_state_in_component_will_update_default = createRule({
1932
2154
  },
1933
2155
  name: RULE_NAME35,
1934
2156
  create(context) {
1935
- if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
2157
+ if (!context.sourceCode.text.includes("componentWillUpdate")) {
2158
+ return {};
2159
+ }
1936
2160
  function getReportDescriptor(node) {
1937
- if (!isThisSetState(node)) return O.none();
2161
+ if (!isThisSetState(node)) {
2162
+ return O.none();
2163
+ }
1938
2164
  return F.pipe(
1939
2165
  O.Do,
1940
2166
  O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
@@ -1969,8 +2195,12 @@ function containsStringLiteral({ value }) {
1969
2195
  return value?.type === AST_NODE_TYPES.Literal && isString(value.value);
1970
2196
  }
1971
2197
  function containsStringExpressionContainer({ value }) {
1972
- if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return false;
1973
- if (value.expression.type === AST_NODE_TYPES.Literal) return isString(value.expression.value);
2198
+ if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
2199
+ return false;
2200
+ }
2201
+ if (value.expression.type === AST_NODE_TYPES.Literal) {
2202
+ return isString(value.expression.value);
2203
+ }
1974
2204
  return value.expression.type === AST_NODE_TYPES.TemplateLiteral;
1975
2205
  }
1976
2206
  var no_string_refs_default = createRule({
@@ -1989,7 +2219,9 @@ var no_string_refs_default = createRule({
1989
2219
  create(context) {
1990
2220
  return {
1991
2221
  JSXAttribute(node) {
1992
- if (node.name.name !== "ref") return;
2222
+ if (node.name.name !== "ref") {
2223
+ return;
2224
+ }
1993
2225
  if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
1994
2226
  context.report({
1995
2227
  messageId: "noStringRefs",
@@ -2022,7 +2254,9 @@ var no_unsafe_component_will_mount_default = createRule({
2022
2254
  },
2023
2255
  name: RULE_NAME37,
2024
2256
  create(context) {
2025
- if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
2257
+ if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) {
2258
+ return {};
2259
+ }
2026
2260
  const { ctx, listeners } = useComponentCollectorLegacy();
2027
2261
  return {
2028
2262
  ...listeners,
@@ -2065,7 +2299,9 @@ var no_unsafe_component_will_receive_props_default = createRule({
2065
2299
  },
2066
2300
  name: RULE_NAME38,
2067
2301
  create(context) {
2068
- if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
2302
+ if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
2303
+ return {};
2304
+ }
2069
2305
  const { ctx, listeners } = useComponentCollectorLegacy();
2070
2306
  return {
2071
2307
  ...listeners,
@@ -2108,7 +2344,9 @@ var no_unsafe_component_will_update_default = createRule({
2108
2344
  },
2109
2345
  name: RULE_NAME39,
2110
2346
  create(context) {
2111
- if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
2347
+ if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) {
2348
+ return {};
2349
+ }
2112
2350
  const { ctx, listeners } = useComponentCollectorLegacy();
2113
2351
  return {
2114
2352
  ...listeners,
@@ -2156,8 +2394,12 @@ var no_unstable_context_value_default = createRule({
2156
2394
  ...listeners,
2157
2395
  JSXOpeningElement(node) {
2158
2396
  const openingElementName = node.name;
2159
- if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) return;
2160
- if (openingElementName.property.name !== "Provider") return;
2397
+ if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) {
2398
+ return;
2399
+ }
2400
+ if (openingElementName.property.name !== "Provider") {
2401
+ return;
2402
+ }
2161
2403
  F.pipe(
2162
2404
  O.Do,
2163
2405
  O.bind("function", ctx.getCurrentFunction),
@@ -2173,8 +2415,12 @@ var no_unstable_context_value_default = createRule({
2173
2415
  return O.some(VAR.getValueConstruction(valueExpression, initialScope));
2174
2416
  }),
2175
2417
  O.map((vc) => {
2176
- if (vc.construction.kind === "None") return;
2177
- if (isReactHookCall(vc.construction.node)) return;
2418
+ if (vc.construction.kind === "None") {
2419
+ return;
2420
+ }
2421
+ if (isReactHookCall(vc.construction.node)) {
2422
+ return;
2423
+ }
2178
2424
  const prevs = constructions.get(vc.function.node) ?? [];
2179
2425
  constructions.set(vc.function.node, [...prevs, vc.construction]);
2180
2426
  })
@@ -2184,7 +2430,9 @@ var no_unstable_context_value_default = createRule({
2184
2430
  const components = ctx.getAllComponents(node).values();
2185
2431
  for (const { node: component } of components) {
2186
2432
  for (const construction of constructions.get(component) ?? []) {
2187
- if (construction.kind === "None") continue;
2433
+ if (construction.kind === "None") {
2434
+ continue;
2435
+ }
2188
2436
  const { kind, node: constructionNode } = construction;
2189
2437
  const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
2190
2438
  context.report({
@@ -2228,12 +2476,16 @@ var no_unstable_default_props_default = createRule({
2228
2476
  for (const { node: component } of components.values()) {
2229
2477
  const { params } = component;
2230
2478
  const [props] = params;
2231
- if (!props) continue;
2479
+ if (!props) {
2480
+ continue;
2481
+ }
2232
2482
  const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
2233
2483
  return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
2234
2484
  }).otherwise(() => []);
2235
2485
  for (const prop of properties) {
2236
- if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
2486
+ if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) {
2487
+ continue;
2488
+ }
2237
2489
  const { value } = prop;
2238
2490
  const { right } = value;
2239
2491
  const initialScope = context.sourceCode.getScope(value);
@@ -2242,8 +2494,12 @@ var no_unstable_default_props_default = createRule({
2242
2494
  initialScope,
2243
2495
  VAR.ValueConstructionHint.StrictCallExpression
2244
2496
  );
2245
- if (construction.kind === "None") continue;
2246
- if (isReactHookCall(construction.node)) continue;
2497
+ if (construction.kind === "None") {
2498
+ continue;
2499
+ }
2500
+ if (isReactHookCall(construction.node)) {
2501
+ continue;
2502
+ }
2247
2503
  const forbiddenType = AST11.toReadableNodeType(right);
2248
2504
  context.report({
2249
2505
  messageId: "noUnstableDefaultProps",
@@ -2257,7 +2513,9 @@ var no_unstable_default_props_default = createRule({
2257
2513
  },
2258
2514
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2259
2515
  const mbEntry = ctx.getCurrentFunction();
2260
- if (O.isNone(mbEntry)) return;
2516
+ if (O.isNone(mbEntry)) {
2517
+ return;
2518
+ }
2261
2519
  const entry = mbEntry.value;
2262
2520
  const prevs = declarators.get(entry.node) ?? [];
2263
2521
  declarators.set(entry.node, [...prevs, node]);
@@ -2322,21 +2580,31 @@ var no_unused_class_component_members_default = createRule({
2322
2580
  const propertyUsages = /* @__PURE__ */ new WeakMap();
2323
2581
  function classEnter(node) {
2324
2582
  classStack.push(node);
2325
- if (!isClassComponent(node)) return;
2583
+ if (!isClassComponent(node)) {
2584
+ return;
2585
+ }
2326
2586
  propertyDefs.set(node, /* @__PURE__ */ new Set());
2327
2587
  propertyUsages.set(node, /* @__PURE__ */ new Set());
2328
2588
  }
2329
2589
  function classExit() {
2330
2590
  const currentClass = classStack.pop();
2331
- if (!currentClass || !isClassComponent(currentClass)) return;
2591
+ if (!currentClass || !isClassComponent(currentClass)) {
2592
+ return;
2593
+ }
2332
2594
  const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
2333
2595
  const defs = propertyDefs.get(currentClass);
2334
2596
  const usages = propertyUsages.get(currentClass);
2335
- if (!defs) return;
2597
+ if (!defs) {
2598
+ return;
2599
+ }
2336
2600
  for (const def of defs) {
2337
2601
  const name2 = getName3(def);
2338
- if (O.isNone(name2)) continue;
2339
- if (usages?.has(name2.value) || LIFECYCLE_METHODS.has(name2.value)) continue;
2602
+ if (O.isNone(name2)) {
2603
+ continue;
2604
+ }
2605
+ if (usages?.has(name2.value) || LIFECYCLE_METHODS.has(name2.value)) {
2606
+ continue;
2607
+ }
2340
2608
  context.report({
2341
2609
  messageId: "noUnusedClassComponentMembers",
2342
2610
  node: def,
@@ -2350,8 +2618,12 @@ var no_unused_class_component_members_default = createRule({
2350
2618
  function methodEnter(node) {
2351
2619
  methodStack.push(node);
2352
2620
  const currentClass = classStack.at(-1);
2353
- if (!currentClass || !isClassComponent(currentClass)) return;
2354
- if (node.static) return;
2621
+ if (!currentClass || !isClassComponent(currentClass)) {
2622
+ return;
2623
+ }
2624
+ if (node.static) {
2625
+ return;
2626
+ }
2355
2627
  if (AST11.isKeyLiteralLike(node, node.key)) {
2356
2628
  propertyDefs.get(currentClass)?.add(node.key);
2357
2629
  }
@@ -2367,9 +2639,15 @@ var no_unused_class_component_members_default = createRule({
2367
2639
  MemberExpression(node) {
2368
2640
  const currentClass = classStack.at(-1);
2369
2641
  const currentMethod = methodStack.at(-1);
2370
- if (!currentClass || !currentMethod) return;
2371
- if (!isClassComponent(currentClass) || currentMethod.static) return;
2372
- if (!AST11.isThisExpression(node.object) || !AST11.isKeyLiteralLike(node, node.property)) return;
2642
+ if (!currentClass || !currentMethod) {
2643
+ return;
2644
+ }
2645
+ if (!isClassComponent(currentClass) || currentMethod.static) {
2646
+ return;
2647
+ }
2648
+ if (!AST11.isThisExpression(node.object) || !AST11.isKeyLiteralLike(node, node.property)) {
2649
+ return;
2650
+ }
2373
2651
  if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
2374
2652
  propertyDefs.get(currentClass)?.add(node.property);
2375
2653
  return;
@@ -2383,8 +2661,12 @@ var no_unused_class_component_members_default = createRule({
2383
2661
  VariableDeclarator(node) {
2384
2662
  const currentClass = classStack.at(-1);
2385
2663
  const currentMethod = methodStack.at(-1);
2386
- if (!currentClass || !currentMethod) return;
2387
- if (!isClassComponent(currentClass) || currentMethod.static) return;
2664
+ if (!currentClass || !currentMethod) {
2665
+ return;
2666
+ }
2667
+ if (!isClassComponent(currentClass) || currentMethod.static) {
2668
+ return;
2669
+ }
2388
2670
  if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2389
2671
  for (const prop of node.id.properties) {
2390
2672
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
@@ -2456,10 +2738,14 @@ var no_unused_state_default = createRule({
2456
2738
  }
2457
2739
  function classExit() {
2458
2740
  const currentClass = classStack.pop();
2459
- if (!currentClass || !isClassComponent(currentClass)) return;
2741
+ if (!currentClass || !isClassComponent(currentClass)) {
2742
+ return;
2743
+ }
2460
2744
  const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
2461
2745
  const [def, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
2462
- if (O.isNone(def) || isUsed) return;
2746
+ if (O.isNone(def) || isUsed) {
2747
+ return;
2748
+ }
2463
2749
  context.report({
2464
2750
  messageId: "noUnusedState",
2465
2751
  node: def.value,
@@ -2471,7 +2757,9 @@ var no_unused_state_default = createRule({
2471
2757
  function methodEnter(node) {
2472
2758
  methodStack.push(node);
2473
2759
  const currentClass = classStack.at(-1);
2474
- if (!currentClass || !isClassComponent(currentClass)) return;
2760
+ if (!currentClass || !isClassComponent(currentClass)) {
2761
+ return;
2762
+ }
2475
2763
  if (node.static) {
2476
2764
  if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
2477
2765
  const [def] = stateDefs.get(currentClass) ?? [O.none()];
@@ -2494,11 +2782,17 @@ var no_unused_state_default = createRule({
2494
2782
  }
2495
2783
  return {
2496
2784
  AssignmentExpression(node) {
2497
- if (!isAssignmentToThisState2(node)) return;
2785
+ if (!isAssignmentToThisState2(node)) {
2786
+ return;
2787
+ }
2498
2788
  const currentClass = classStack.at(-1);
2499
- if (!currentClass || !isClassComponent(currentClass)) return;
2789
+ if (!currentClass || !isClassComponent(currentClass)) {
2790
+ return;
2791
+ }
2500
2792
  const currentConstructor = constructorStack.at(-1);
2501
- if (!currentConstructor || !currentClass.body.body.includes(currentConstructor)) return;
2793
+ if (!currentConstructor || !currentClass.body.body.includes(currentConstructor)) {
2794
+ return;
2795
+ }
2502
2796
  const [_, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
2503
2797
  stateDefs.set(currentClass, [O.some(node.left), isUsed]);
2504
2798
  },
@@ -2507,14 +2801,26 @@ var no_unused_state_default = createRule({
2507
2801
  ClassExpression: classEnter,
2508
2802
  "ClassExpression:exit": classExit,
2509
2803
  MemberExpression(node) {
2510
- if (!AST11.isThisExpression(node.object)) return;
2511
- if (!O.exists(getName4(node.property), (name2) => name2 === "state")) return;
2804
+ if (!AST11.isThisExpression(node.object)) {
2805
+ return;
2806
+ }
2807
+ if (!O.exists(getName4(node.property), (name2) => name2 === "state")) {
2808
+ return;
2809
+ }
2512
2810
  const currentClass = classStack.at(-1);
2513
- if (!currentClass || !isClassComponent(currentClass)) return;
2811
+ if (!currentClass || !isClassComponent(currentClass)) {
2812
+ return;
2813
+ }
2514
2814
  const currentMethod = methodStack.at(-1);
2515
- if (!currentMethod || currentMethod.static) return;
2516
- if (currentMethod === constructorStack.at(-1)) return;
2517
- if (!currentClass.body.body.includes(currentMethod)) return;
2815
+ if (!currentMethod || currentMethod.static) {
2816
+ return;
2817
+ }
2818
+ if (currentMethod === constructorStack.at(-1)) {
2819
+ return;
2820
+ }
2821
+ if (!currentClass.body.body.includes(currentMethod)) {
2822
+ return;
2823
+ }
2518
2824
  const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
2519
2825
  stateDefs.set(currentClass, [def, true]);
2520
2826
  },
@@ -2526,19 +2832,31 @@ var no_unused_state_default = createRule({
2526
2832
  "PropertyDefinition:exit": methodExit,
2527
2833
  VariableDeclarator(node) {
2528
2834
  const currentClass = classStack.at(-1);
2529
- if (!currentClass || !isClassComponent(currentClass)) return;
2835
+ if (!currentClass || !isClassComponent(currentClass)) {
2836
+ return;
2837
+ }
2530
2838
  const currentMethod = methodStack.at(-1);
2531
- if (!currentMethod || currentMethod.static) return;
2532
- if (currentMethod === constructorStack.at(-1)) return;
2533
- if (!currentClass.body.body.includes(currentMethod)) return;
2534
- if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) return;
2839
+ if (!currentMethod || currentMethod.static) {
2840
+ return;
2841
+ }
2842
+ if (currentMethod === constructorStack.at(-1)) {
2843
+ return;
2844
+ }
2845
+ if (!currentClass.body.body.includes(currentMethod)) {
2846
+ return;
2847
+ }
2848
+ if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
2849
+ return;
2850
+ }
2535
2851
  const hasState = node.id.properties.some((prop) => {
2536
2852
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2537
2853
  return O.exists(getName4(prop.key), (name2) => name2 === "state");
2538
2854
  }
2539
2855
  return false;
2540
2856
  });
2541
- if (!hasState) return;
2857
+ if (!hasState) {
2858
+ return;
2859
+ }
2542
2860
  const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
2543
2861
  stateDefs.set(currentClass, [def, true]);
2544
2862
  }
@@ -2552,8 +2870,12 @@ var defaultOptions = [{
2552
2870
  }];
2553
2871
  function checkAndReport(node, context, allowExpressions) {
2554
2872
  const initialScope = context.sourceCode.getScope(node);
2555
- if (JSX7.isKeyedElement(node, initialScope)) return;
2556
- if (JSX7.isBuiltInElement(node.parent)) context.report({ messageId: "noUselessFragmentInBuiltIn", node });
2873
+ if (JSX7.isKeyedElement(node, initialScope)) {
2874
+ return;
2875
+ }
2876
+ if (JSX7.isBuiltInElement(node.parent)) {
2877
+ context.report({ messageId: "noUselessFragmentInBuiltIn", node });
2878
+ }
2557
2879
  if (node.children.length === 0) {
2558
2880
  context.report({ messageId: "noUselessFragment", node });
2559
2881
  return;
@@ -2612,7 +2934,9 @@ var no_useless_fragment_default = createRule({
2612
2934
  const { allowExpressions = true } = option;
2613
2935
  return {
2614
2936
  JSXElement(node) {
2615
- if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") return;
2937
+ if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
2938
+ return;
2939
+ }
2616
2940
  checkAndReport(node, context, allowExpressions);
2617
2941
  },
2618
2942
  JSXFragment(node) {
@@ -2656,7 +2980,9 @@ var prefer_destructuring_assignment_default = createRule({
2656
2980
  "Program:exit"(node) {
2657
2981
  const components = Array.from(ctx.getAllComponents(node).values());
2658
2982
  function isFunctionComponent(block) {
2659
- if (!AST11.isFunction(block)) return false;
2983
+ if (!AST11.isFunction(block)) {
2984
+ return false;
2985
+ }
2660
2986
  return O.exists(
2661
2987
  AST11.getFunctionIdentifier(block),
2662
2988
  (id) => isComponentName(id.name) && components.some((component) => component.node === block)
@@ -2669,9 +2995,13 @@ var prefer_destructuring_assignment_default = createRule({
2669
2995
  scope = scope.upper;
2670
2996
  isComponent = isFunctionComponent(scope.block);
2671
2997
  }
2672
- if (!isComponent) continue;
2998
+ if (!isComponent) {
2999
+ continue;
3000
+ }
2673
3001
  const component = scope.block;
2674
- if (!("params" in component)) continue;
3002
+ if (!("params" in component)) {
3003
+ continue;
3004
+ }
2675
3005
  const [props, ctx2] = component.params;
2676
3006
  const isMatch = isMatching({ name: memberExpression.object.name });
2677
3007
  if (isMatch(props)) {
@@ -2787,9 +3117,13 @@ var prefer_read_only_props_default = createRule({
2787
3117
  const components = ctx.getAllComponents(node);
2788
3118
  for (const [_, component] of components) {
2789
3119
  const [props] = component.node.params;
2790
- if (!props) continue;
3120
+ if (!props) {
3121
+ continue;
3122
+ }
2791
3123
  const propsType = getConstrainedTypeAtLocation(services, props);
2792
- if (isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services)) continue;
3124
+ if (isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services)) {
3125
+ continue;
3126
+ }
2793
3127
  context.report({ messageId: "preferReadOnlyProps", node: props });
2794
3128
  }
2795
3129
  }
@@ -2821,7 +3155,9 @@ var prefer_shorthand_boolean_default = createRule({
2821
3155
  const { value } = node;
2822
3156
  const propName = JSX7.getPropName(node);
2823
3157
  const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
2824
- if (!hasValueTrue) return O.none();
3158
+ if (!hasValueTrue) {
3159
+ return O.none();
3160
+ }
2825
3161
  return O.some({
2826
3162
  messageId: "preferShorthandBoolean",
2827
3163
  node,
@@ -2858,15 +3194,21 @@ var prefer_shorthand_fragment_default = createRule({
2858
3194
  name: RULE_NAME49,
2859
3195
  create(context) {
2860
3196
  function getReportDescriptor(node) {
2861
- if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") return O.none();
3197
+ if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
3198
+ return O.none();
3199
+ }
2862
3200
  const hasAttributes = node.openingElement.attributes.length > 0;
2863
- if (hasAttributes) return O.none();
3201
+ if (hasAttributes) {
3202
+ return O.none();
3203
+ }
2864
3204
  return O.some({
2865
3205
  messageId: "preferShorthandFragment",
2866
3206
  node,
2867
3207
  fix: (fixer) => {
2868
3208
  const { closingElement, openingElement } = node;
2869
- if (!closingElement) return [];
3209
+ if (!closingElement) {
3210
+ return [];
3211
+ }
2870
3212
  return [
2871
3213
  fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
2872
3214
  fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
@@ -2909,7 +3251,9 @@ var use_jsx_vars_default = createRule({
2909
3251
  }
2910
3252
  return {
2911
3253
  JSXOpeningElement(node) {
2912
- if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
3254
+ if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) {
3255
+ return;
3256
+ }
2913
3257
  for (const name2 of O.toArray(getName5(node.name))) {
2914
3258
  context.sourceCode.markVariableAsUsed(name2, node);
2915
3259
  }