eslint-plugin-react-x 1.23.3-next.8 → 1.24.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.
Files changed (3) hide show
  1. package/dist/index.js +414 -478
  2. package/dist/index.mjs +414 -478
  3. package/package.json +13 -13
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { F, O, isString, not, or, isNullable } from '@eslint-react/eff';
2
1
  import * as JSX7 from '@eslint-react/jsx';
3
2
  import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
4
3
  import * as AST11 from '@eslint-react/ast';
5
4
  import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
5
+ import { _ } from '@eslint-react/eff';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
7
7
  import { isMatching, match, P } from 'ts-pattern';
8
8
  import { compare } from 'compare-versions';
@@ -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.3-next.8";
18
+ var version = "1.24.0-beta.1";
19
19
  var createRule = createRuleForPlugin("x");
20
20
 
21
21
  // src/rules/avoid-shorthand-boolean.ts
@@ -38,18 +38,19 @@ var avoid_shorthand_boolean_default = createRule({
38
38
  },
39
39
  name: RULE_NAME,
40
40
  create(context) {
41
- function getReportDescriptor(node) {
42
- return node.value != null ? O.none() : O.some({
43
- messageId: "avoidShorthandBoolean",
44
- node,
45
- data: {
46
- propName: JSX7.getPropName(node)
47
- },
48
- fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
49
- });
50
- }
51
41
  return {
52
- JSXAttribute: F.flow(getReportDescriptor, O.map(context.report))
42
+ JSXAttribute(node) {
43
+ if (node.value === null) {
44
+ context.report({
45
+ messageId: "avoidShorthandBoolean",
46
+ node,
47
+ data: {
48
+ propName: JSX7.getPropName(node)
49
+ },
50
+ fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
51
+ });
52
+ }
53
+ }
53
54
  };
54
55
  },
55
56
  defaultOptions: []
@@ -112,7 +113,7 @@ var ensure_forward_ref_using_ref_default = createRule({
112
113
  if (component == null || !AST11.isFunction(component)) {
113
114
  return;
114
115
  }
115
- const [_, ref] = component.params;
116
+ const ref = component.params[1];
116
117
  if (ref != null) {
117
118
  return;
118
119
  }
@@ -134,15 +135,15 @@ function getName(node) {
134
135
  return getName(node.expression);
135
136
  }
136
137
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
137
- return O.some(node.name);
138
+ return node.name;
138
139
  }
139
140
  if (node.type === AST_NODE_TYPES.Literal) {
140
- return O.some(String(node.value));
141
+ return String(node.value);
141
142
  }
142
143
  if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
143
- return O.fromNullable(node.quasis[0]?.value.raw);
144
+ return node.quasis[0]?.value.raw;
144
145
  }
145
- return O.none();
146
+ return _;
146
147
  }
147
148
  var no_access_state_in_setstate_default = createRule({
148
149
  meta: {
@@ -161,89 +162,86 @@ var no_access_state_in_setstate_default = createRule({
161
162
  if (!context.sourceCode.text.includes("setState")) {
162
163
  return {};
163
164
  }
164
- const classStack = [];
165
- const methodStack = [];
166
- const setStateStack = [];
165
+ const classEntries = [];
166
+ const methodEntries = [];
167
+ const setStateEntries = [];
167
168
  return {
168
169
  CallExpression(node) {
169
170
  if (!isThisSetState(node)) {
170
171
  return;
171
172
  }
172
- setStateStack.push([node, false]);
173
+ setStateEntries.push([node, false]);
173
174
  },
174
175
  "CallExpression:exit"(node) {
175
176
  if (!isThisSetState(node)) {
176
177
  return;
177
178
  }
178
- setStateStack.pop();
179
+ setStateEntries.pop();
179
180
  },
180
181
  ClassDeclaration(node) {
181
- classStack.push([node, isClassComponent(node)]);
182
+ classEntries.push([node, isClassComponent(node)]);
182
183
  },
183
184
  "ClassDeclaration:exit"() {
184
- classStack.pop();
185
+ classEntries.pop();
185
186
  },
186
187
  ClassExpression(node) {
187
- classStack.push([node, isClassComponent(node)]);
188
+ classEntries.push([node, isClassComponent(node)]);
188
189
  },
189
190
  "ClassExpression:exit"() {
190
- classStack.pop();
191
+ classEntries.pop();
191
192
  },
192
193
  MemberExpression(node) {
193
194
  if (!AST11.isThisExpression(node.object)) {
194
195
  return;
195
196
  }
196
- const [currClass, isComponent] = classStack.at(-1) ?? [];
197
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
197
198
  if (currClass == null || !isComponent) {
198
199
  return;
199
200
  }
200
- const [currMethod, isStatic] = methodStack.at(-1) ?? [];
201
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
201
202
  if (currMethod == null || isStatic) {
202
203
  return;
203
204
  }
204
- const [setState, hasThisState] = setStateStack.at(-1) ?? [];
205
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
205
206
  if (setState == null || hasThisState) {
206
207
  return;
207
208
  }
208
- if (!O.exists(getName(node.property), (name2) => name2 === "state")) {
209
+ if (getName(node.property) !== "state") {
209
210
  return;
210
211
  }
211
212
  context.report({ messageId: "noAccessStateInSetstate", node });
212
213
  },
213
214
  MethodDefinition(node) {
214
- methodStack.push([node, node.static]);
215
+ methodEntries.push([node, node.static]);
215
216
  },
216
217
  "MethodDefinition:exit"() {
217
- methodStack.pop();
218
+ methodEntries.pop();
218
219
  },
219
220
  PropertyDefinition(node) {
220
- methodStack.push([node, node.static]);
221
+ methodEntries.push([node, node.static]);
221
222
  },
222
223
  "PropertyDefinition:exit"() {
223
- methodStack.pop();
224
+ methodEntries.pop();
224
225
  },
225
226
  VariableDeclarator(node) {
226
- const [currClass, isComponent] = classStack.at(-1) ?? [];
227
+ const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
227
228
  if (currClass == null || !isComponent) {
228
229
  return;
229
230
  }
230
- const [currMethod, isStatic] = methodStack.at(-1) ?? [];
231
+ const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
231
232
  if (currMethod == null || isStatic) {
232
233
  return;
233
234
  }
234
- const [setState, hasThisState] = setStateStack.at(-1) ?? [];
235
+ const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
235
236
  if (setState == null || hasThisState) {
236
237
  return;
237
238
  }
238
239
  if (!(node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
239
240
  return;
240
241
  }
241
- const hasState = node.id.properties.some((prop) => {
242
- if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
243
- return O.exists(getName(prop.key), (name2) => name2 === "state");
244
- }
245
- return false;
246
- });
242
+ const hasState = node.id.properties.some(
243
+ (prop) => prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key) && getName(prop.key) === "state"
244
+ );
247
245
  if (!hasState) {
248
246
  return;
249
247
  }
@@ -296,32 +294,32 @@ function isUsingReactChildren(node, context) {
296
294
  function getMapIndexParamName(node, context) {
297
295
  const { callee } = node;
298
296
  if (callee.type !== AST_NODE_TYPES.MemberExpression) {
299
- return O.none();
297
+ return _;
300
298
  }
301
299
  if (callee.property.type !== AST_NODE_TYPES.Identifier) {
302
- return O.none();
300
+ return _;
303
301
  }
304
302
  const { name: name2 } = callee.property;
305
303
  if (!iteratorFunctionIndexParamPosition.has(name2)) {
306
- return O.none();
304
+ return _;
307
305
  }
308
306
  const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
309
307
  if (callbackArg == null) {
310
- return O.none();
308
+ return _;
311
309
  }
312
310
  if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
313
- return O.none();
311
+ return _;
314
312
  }
315
313
  const { params } = callbackArg;
316
314
  const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
317
- if (isNullable(indexParamPosition)) {
318
- return O.none();
315
+ if (indexParamPosition == null) {
316
+ return _;
319
317
  }
320
318
  if (params.length < indexParamPosition + 1) {
321
- return O.none();
319
+ return _;
322
320
  }
323
321
  const param = params.at(indexParamPosition);
324
- return param != null && "name" in param ? O.some(param.name) : O.none();
322
+ return param != null && "name" in param ? param.name : _;
325
323
  }
326
324
  var no_array_index_key_default = createRule({
327
325
  meta: {
@@ -339,7 +337,7 @@ var no_array_index_key_default = createRule({
339
337
  create(context) {
340
338
  const indexParamNames = [];
341
339
  function isArrayIndex(node) {
342
- return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
340
+ return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name2) => name2 != null && name2 === node.name);
343
341
  }
344
342
  function isCreateOrCloneElementCall(node) {
345
343
  return isCreateElementCall(node, context) || isCloneElementCall(node, context);
@@ -348,7 +346,7 @@ var no_array_index_key_default = createRule({
348
346
  switch (node.type) {
349
347
  // key={bar}
350
348
  case AST_NODE_TYPES.Identifier: {
351
- if (indexParamNames.some(O.exists((name2) => name2 === node.name))) {
349
+ if (indexParamNames.some((name2) => name2 != null && name2 === node.name)) {
352
350
  return [{
353
351
  messageId: "noArrayIndexKey",
354
352
  node
@@ -402,7 +400,7 @@ var no_array_index_key_default = createRule({
402
400
  if (!isCreateOrCloneElementCall(node)) {
403
401
  return;
404
402
  }
405
- const [_, props] = node.arguments;
403
+ const [, props] = node.arguments;
406
404
  if (props?.type !== AST_NODE_TYPES.ObjectExpression) {
407
405
  return;
408
406
  }
@@ -585,10 +583,17 @@ var no_children_prop_default = createRule({
585
583
  create(context) {
586
584
  return {
587
585
  JSXElement(node) {
588
- const initialScope = context.sourceCode.getScope(node);
589
- const prop = JSX7.getProp(node.openingElement.attributes, "children", initialScope);
590
- const reportDescriptor = O.map(prop, (prop2) => ({ messageId: "noChildrenProp", node: prop2 }));
591
- O.map(reportDescriptor, context.report);
586
+ const prop = JSX7.getProp(
587
+ "children",
588
+ context.sourceCode.getScope(node),
589
+ node.openingElement.attributes
590
+ );
591
+ if (prop != null) {
592
+ context.report({
593
+ messageId: "noChildrenProp",
594
+ node: prop
595
+ });
596
+ }
592
597
  }
593
598
  };
594
599
  },
@@ -657,7 +662,7 @@ var no_class_component_default = createRule({
657
662
  ...listeners,
658
663
  "Program:exit"(node) {
659
664
  const components = ctx.getAllComponents(node);
660
- for (const { name: name2, node: component } of components.values()) {
665
+ for (const { name: name2 = "anonymous", node: component } of components.values()) {
661
666
  if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
662
667
  continue;
663
668
  }
@@ -666,7 +671,7 @@ var no_class_component_default = createRule({
666
671
  node: component,
667
672
  data: {
668
673
  // eslint-disable-next-line eslint-plugin/no-unused-placeholders
669
- name: O.getOrElse(F.constant("anonymous"))(name2)
674
+ name: name2
670
675
  }
671
676
  });
672
677
  }
@@ -732,22 +737,21 @@ var no_comment_textnodes_default = createRule({
732
737
  const rawValue = context.sourceCode.getText(node);
733
738
  return /^\s*\/(?:\/|\*)/mu.test(rawValue);
734
739
  }
735
- const getReportDescriptor = (node) => {
740
+ const visitorFunction = (node) => {
736
741
  if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
737
- return O.none();
742
+ return;
738
743
  }
739
744
  if (!hasCommentLike(node)) {
740
- return O.none();
745
+ return;
741
746
  }
742
747
  if (!node.parent.type.includes("JSX")) {
743
- return O.none();
748
+ return;
744
749
  }
745
- return O.some({
750
+ context.report({
746
751
  messageId: "noCommentTextnodes",
747
752
  node
748
753
  });
749
754
  };
750
- const visitorFunction = F.flow(getReportDescriptor, O.map(context.report), F.constVoid);
751
755
  return {
752
756
  JSXText: visitorFunction,
753
757
  Literal: visitorFunction
@@ -773,20 +777,22 @@ var no_complex_conditional_rendering_default = createRule({
773
777
  },
774
778
  name: RULE_NAME15,
775
779
  create(context) {
776
- function getReportDescriptor(node) {
780
+ const visitorFunction = (node) => {
777
781
  const jsxExpContainer = node.parent?.parent;
778
782
  if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
779
- return O.none();
783
+ return;
780
784
  }
781
785
  if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
782
- return O.none();
786
+ return;
783
787
  }
784
788
  if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
785
- return O.none();
789
+ return;
786
790
  }
787
- return O.some({ messageId: "noComplexConditionalRendering", node: jsxExpContainer });
788
- }
789
- const visitorFunction = F.flow(getReportDescriptor, O.map(context.report), F.constVoid);
791
+ context.report({
792
+ messageId: "noComplexConditionalRendering",
793
+ node: jsxExpContainer
794
+ });
795
+ };
790
796
  return {
791
797
  "JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
792
798
  "JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
@@ -1030,13 +1036,9 @@ var no_create_ref_default = createRule({
1030
1036
  create(context) {
1031
1037
  return {
1032
1038
  CallExpression(node) {
1033
- if (!isCreateRefCall(node, context)) {
1034
- return;
1039
+ if (isCreateRefCall(node, context) && AST11.findParentNode(node, isClassComponent) == null) {
1040
+ context.report({ messageId: "noCreateRef", node });
1035
1041
  }
1036
- if (O.isSome(AST11.findParentNode(node, isClassComponent))) {
1037
- return;
1038
- }
1039
- context.report({ messageId: "noCreateRef", node });
1040
1042
  }
1041
1043
  };
1042
1044
  },
@@ -1078,14 +1080,10 @@ var no_default_props_default = createRule({
1078
1080
  if (!isComponentName(object.name)) {
1079
1081
  return;
1080
1082
  }
1081
- const isComponent = F.pipe(
1082
- VAR.findVariable(object.name, context.sourceCode.getScope(node)),
1083
- O.flatMap(VAR.getVariableNode(0)),
1084
- O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
1085
- );
1086
- if (!isComponent) {
1087
- return;
1088
- }
1083
+ const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1084
+ const variableNode = VAR.getVariableNode(variable, 0);
1085
+ if (variableNode == null) return;
1086
+ if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
1089
1087
  context.report({ messageId: "noDefaultProps", node: property });
1090
1088
  },
1091
1089
  PropertyDefinition(node) {
@@ -1110,19 +1108,19 @@ function getName2(node) {
1110
1108
  return getName2(node.expression);
1111
1109
  }
1112
1110
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
1113
- return O.some(node.name);
1111
+ return node.name;
1114
1112
  }
1115
1113
  if (node.type === AST_NODE_TYPES.Literal) {
1116
- return O.some(String(node.value));
1114
+ return node.value?.toString();
1117
1115
  }
1118
1116
  if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
1119
- return O.fromNullable(node.quasis[0]?.value.raw);
1117
+ return node.quasis[0]?.value.raw;
1120
1118
  }
1121
- return O.none();
1119
+ return _;
1122
1120
  }
1123
1121
  function isAssignmentToThisState(node) {
1124
1122
  const { left } = node;
1125
- return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && O.exists(getName2(left.property), (name2) => name2 === "state");
1123
+ return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName2(left.property) === "state";
1126
1124
  }
1127
1125
  function isConstructorFunction(node) {
1128
1126
  return AST11.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
@@ -1141,31 +1139,26 @@ var no_direct_mutation_state_default = createRule({
1141
1139
  },
1142
1140
  name: RULE_NAME22,
1143
1141
  create(context) {
1144
- function getReportDescriptor(node) {
1145
- if (!isAssignmentToThisState(node)) {
1146
- return O.none();
1147
- }
1148
- return F.pipe(
1149
- O.Do,
1150
- O.bind("parentClass", () => AST11.findParentNodeGuard(
1142
+ return {
1143
+ AssignmentExpression(node) {
1144
+ if (!isAssignmentToThisState(node)) {
1145
+ return;
1146
+ }
1147
+ const parentClass = AST11.findParentNodeGuard(
1151
1148
  node,
1152
1149
  AST11.isOneOf([
1153
1150
  AST_NODE_TYPES.ClassDeclaration,
1154
1151
  AST_NODE_TYPES.ClassExpression
1155
1152
  ])
1156
- )),
1157
- O.bind("parentConstructor", () => AST11.findParentNodeGuard(node, isConstructorFunction)),
1158
- O.filter(
1159
- ({ parentClass, parentConstructor }) => isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== parentConstructor
1160
- ),
1161
- O.map(() => ({
1162
- messageId: "noDirectMutationState",
1163
- node
1164
- }))
1165
- );
1166
- }
1167
- return {
1168
- AssignmentExpression: F.flow(getReportDescriptor, O.map(context.report))
1153
+ );
1154
+ if (parentClass == null) return;
1155
+ if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNodeGuard(node, isConstructorFunction)) {
1156
+ context.report({
1157
+ messageId: "noDirectMutationState",
1158
+ node
1159
+ });
1160
+ }
1161
+ }
1169
1162
  };
1170
1163
  },
1171
1164
  defaultOptions: []
@@ -1196,7 +1189,7 @@ var no_duplicate_jsx_props_default = createRule({
1196
1189
  continue;
1197
1190
  }
1198
1191
  const name2 = attr.name.name;
1199
- if (!isString(name2)) {
1192
+ if (typeof name2 !== "string") {
1200
1193
  continue;
1201
1194
  }
1202
1195
  if (!props.includes(name2)) {
@@ -1260,16 +1253,11 @@ var no_duplicate_key_default = createRule({
1260
1253
  break;
1261
1254
  }
1262
1255
  default: {
1263
- const mbEntry = F.pipe(
1264
- O.Do,
1265
- O.bind("call", () => AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose)),
1266
- O.bind("iter", ({ call: call2 }) => AST11.findParentNodeStop(jsxElement, call2, AST11.isFunction)),
1267
- O.bind("arg0", ({ call: call2 }) => O.fromNullable(call2.arguments[0]))
1268
- );
1269
- if (O.isNone(mbEntry)) {
1270
- return;
1271
- }
1272
- const { arg0, call, iter } = mbEntry.value;
1256
+ const call = AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose);
1257
+ const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
1258
+ if (!AST11.isFunction(iter)) return;
1259
+ const arg0 = call?.arguments[0];
1260
+ if (call == null || arg0 == null) return;
1273
1261
  if (AST11.unwrapTypeExpression(arg0) !== iter) {
1274
1262
  return;
1275
1263
  }
@@ -1370,21 +1358,19 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
1370
1358
  if (arg0 == null) {
1371
1359
  return [];
1372
1360
  }
1373
- 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);
1374
- 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);
1375
- if (O.isNone(fixedArg0Text) || O.isNone(fixedArg1Text)) {
1361
+ const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => _);
1362
+ const fixedArg1Text = match(arg1).with(P.nullish, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: P.not("ref") }, (n) => `ref: ${n.name}`).otherwise(() => _);
1363
+ if (fixedArg0Text == null || fixedArg1Text == null) {
1376
1364
  return [];
1377
1365
  }
1378
- const fixedPropsText = fixedArg0Text.value;
1379
- const fixedRefText = fixedArg1Text.value;
1380
1366
  if (typeArg0 == null || typeArg1 == null) {
1381
1367
  return [
1382
1368
  fixer.replaceText(
1383
1369
  arg0,
1384
1370
  [
1385
1371
  "{",
1386
- fixedRefText + ",",
1387
- fixedPropsText,
1372
+ fixedArg1Text + ",",
1373
+ fixedArg0Text,
1388
1374
  "}"
1389
1375
  ].join(" ")
1390
1376
  ),
@@ -1396,8 +1382,8 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
1396
1382
  arg0,
1397
1383
  [
1398
1384
  "{",
1399
- fixedRefText + ",",
1400
- fixedPropsText,
1385
+ fixedArg1Text + ",",
1386
+ fixedArg0Text,
1401
1387
  "}:",
1402
1388
  getText(typeArg1),
1403
1389
  "&",
@@ -1428,17 +1414,17 @@ var no_implicit_key_default = createRule({
1428
1414
  },
1429
1415
  name: RULE_NAME26,
1430
1416
  create(context) {
1431
- function getReportDescriptor(node) {
1432
- const initialScope = context.sourceCode.getScope(node);
1433
- const keyPropFound = JSX7.findPropInAttributes(node.attributes, initialScope)("key");
1434
- const keyPropOnElement = node.attributes.some((n) => AST11.is(AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key");
1435
- if (O.isSome(keyPropFound) && !keyPropOnElement) {
1436
- return O.some({ messageId: "noImplicitKey", node: keyPropFound.value });
1437
- }
1438
- return O.none();
1439
- }
1440
1417
  return {
1441
- JSXOpeningElement: F.flow(getReportDescriptor, O.map(context.report))
1418
+ JSXOpeningElement(node) {
1419
+ const initialScope = context.sourceCode.getScope(node);
1420
+ const keyPropFound = JSX7.findPropInAttributes("key", initialScope, node.attributes);
1421
+ const keyPropOnElement = node.attributes.some(
1422
+ (n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1423
+ );
1424
+ if (keyPropFound != null && !keyPropOnElement) {
1425
+ context.report({ messageId: "noImplicitKey", node: keyPropFound });
1426
+ }
1427
+ }
1442
1428
  };
1443
1429
  },
1444
1430
  defaultOptions: []
@@ -1484,11 +1470,12 @@ function inspectVariantTypes(types) {
1484
1470
  const booleans = types.filter(tsHelpers.isBooleanType);
1485
1471
  switch (true) {
1486
1472
  case (booleans.length === 1 && booleans[0] != null): {
1487
- const [first] = booleans;
1488
- const evaluated = F.pipe(
1489
- match(first).when(isTrueLiteralType, () => O.some("truthy boolean")).when(isFalseLiteralType, () => O.some("falsy boolean")).otherwise(O.none)
1490
- );
1491
- O.map(evaluated, (v) => variantTypes.add(v));
1473
+ const first = booleans[0];
1474
+ if (isTrueLiteralType(first)) {
1475
+ variantTypes.add("truthy boolean");
1476
+ } else if (isFalseLiteralType(first)) {
1477
+ variantTypes.add("falsy boolean");
1478
+ }
1492
1479
  break;
1493
1480
  }
1494
1481
  case booleans.length === 2: {
@@ -1498,17 +1485,17 @@ function inspectVariantTypes(types) {
1498
1485
  }
1499
1486
  const strings = types.filter(tsHelpers.isStringType);
1500
1487
  if (strings.length > 0) {
1501
- const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), F.constant("truthy string")).when((types2) => types2.every(tsHelpers.isFalsyStringType), F.constant("falsy string")).otherwise(F.constant("string"));
1488
+ const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), () => "truthy string").when((types2) => types2.every(tsHelpers.isFalsyStringType), () => "falsy string").otherwise(() => "string");
1502
1489
  variantTypes.add(evaluated);
1503
1490
  }
1504
1491
  const bigints = types.filter(tsHelpers.isBigIntType);
1505
1492
  if (bigints.length > 0) {
1506
- const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), F.constant("truthy bigint")).when((types2) => types2.every(tsHelpers.isFalsyBigIntType), F.constant("falsy bigint")).otherwise(F.constant("bigint"));
1493
+ const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(tsHelpers.isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
1507
1494
  variantTypes.add(evaluated);
1508
1495
  }
1509
1496
  const numbers = types.filter(tsHelpers.isNumberType);
1510
1497
  if (numbers.length > 0) {
1511
- const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), F.constant("truthy number")).when((types2) => types2.every(tsHelpers.isFalsyNumberType), F.constant("falsy number")).otherwise(F.constant("number"));
1498
+ const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), () => "truthy number").when((types2) => types2.every(tsHelpers.isFalsyNumberType), () => "falsy number").otherwise(() => "number");
1512
1499
  variantTypes.add(evaluated);
1513
1500
  }
1514
1501
  if (types.some(tsHelpers.isEnumType)) {
@@ -1526,19 +1513,15 @@ function inspectVariantTypes(types) {
1526
1513
  return variantTypes;
1527
1514
  }
1528
1515
  function isInitExpression(node) {
1516
+ if (node == null) return false;
1529
1517
  return node.type !== AST_NODE_TYPES.VariableDeclaration;
1530
1518
  }
1531
- function getVariableInitExpression(at) {
1532
- return (variable) => {
1533
- return F.pipe(
1534
- O.some(variable),
1535
- O.flatMapNullable((v) => v.defs.at(at)),
1536
- O.flatMap(
1537
- (d) => "init" in d.node ? O.fromNullable(d.node.init) : O.none()
1538
- ),
1539
- O.filter(isInitExpression)
1540
- );
1541
- };
1519
+ function getVariableInitExpression(variable, at) {
1520
+ const def = variable?.defs[at];
1521
+ if (def?.node == null || !("init" in def.node)) {
1522
+ return _;
1523
+ }
1524
+ return isInitExpression(def.node.init) ? def.node.init : _;
1542
1525
  }
1543
1526
  var no_leaked_conditional_rendering_default = createRule({
1544
1527
  meta: {
@@ -1572,19 +1555,20 @@ var no_leaked_conditional_rendering_default = createRule({
1572
1555
  ];
1573
1556
  const services = ESLintUtils.getParserServices(context, false);
1574
1557
  function getReportDescriptor(node) {
1575
- return match(node).when(AST11.isJSX, O.none).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1558
+ if (node == null) return _;
1559
+ return match(node).when(AST11.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
1576
1560
  const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
1577
1561
  if (isLeftUnaryNot) {
1578
1562
  return getReportDescriptor(right);
1579
1563
  }
1580
1564
  const initialScope = context.sourceCode.getScope(left);
1581
- const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || O.exists(VAR.getStaticValue(left, initialScope), (v) => v === "NaN");
1565
+ const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.toResolved({ kind: "lazy", node: left, initialScope }).value === "NaN";
1582
1566
  if (isLeftNan) {
1583
- return O.some({
1567
+ return {
1584
1568
  messageId: "noLeakedConditionalRendering",
1585
1569
  node: left,
1586
1570
  data: { value: context.sourceCode.getText(left) }
1587
- });
1571
+ };
1588
1572
  }
1589
1573
  const leftType = getConstrainedTypeAtLocation(services, left);
1590
1574
  const leftTypeVariants = inspectVariantTypes(unionTypeParts(leftType));
@@ -1592,22 +1576,24 @@ var no_leaked_conditional_rendering_default = createRule({
1592
1576
  if (isLeftValid) {
1593
1577
  return getReportDescriptor(right);
1594
1578
  }
1595
- return O.some({
1579
+ return {
1596
1580
  messageId: "noLeakedConditionalRendering",
1597
1581
  node: left,
1598
1582
  data: { value: context.sourceCode.getText(left) }
1599
- });
1583
+ };
1600
1584
  }).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
1601
- return O.orElse(getReportDescriptor(consequent), () => getReportDescriptor(alternate));
1585
+ return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
1602
1586
  }).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
1603
- return F.pipe(
1604
- VAR.findVariable(n.name, context.sourceCode.getScope(n)),
1605
- O.flatMap(getVariableInitExpression(0)),
1606
- O.flatMap(getReportDescriptor)
1607
- );
1608
- }).otherwise(O.none);
1587
+ const variable = VAR.findVariable(n.name, context.sourceCode.getScope(n));
1588
+ const initExpression = getVariableInitExpression(variable, 0);
1589
+ return getReportDescriptor(initExpression);
1590
+ }).otherwise(() => _);
1609
1591
  }
1610
- const visitorFunction = F.flow(getReportDescriptor, O.map(context.report));
1592
+ const visitorFunction = (node) => {
1593
+ const descriptor = getReportDescriptor(node);
1594
+ if (descriptor == null) return;
1595
+ context.report(descriptor);
1596
+ };
1611
1597
  return {
1612
1598
  "JSXExpressionContainer > ConditionalExpression": visitorFunction,
1613
1599
  "JSXExpressionContainer > LogicalExpression": visitorFunction
@@ -1643,13 +1629,13 @@ var no_missing_component_display_name_default = createRule({
1643
1629
  const components = ctx.getAllComponents(node);
1644
1630
  for (const { node: node2, displayName, flag } of components.values()) {
1645
1631
  const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
1646
- if (O.isSome(AST11.getFunctionIdentifier(node2))) {
1632
+ if (AST11.getFunctionIdentifier(node2) != null) {
1647
1633
  continue;
1648
1634
  }
1649
1635
  if (!isMemoOrForwardRef) {
1650
1636
  continue;
1651
1637
  }
1652
- if (O.isNone(displayName)) {
1638
+ if (displayName == null) {
1653
1639
  context.report({
1654
1640
  messageId: "noMissingComponentDisplayName",
1655
1641
  node: node2
@@ -1685,51 +1671,55 @@ var no_missing_key_default = createRule({
1685
1671
  switch (node.type) {
1686
1672
  case AST_NODE_TYPES.JSXElement: {
1687
1673
  const initialScope = context.sourceCode.getScope(node);
1688
- if (!JSX7.hasProp(node.openingElement.attributes, "key", initialScope)) {
1689
- return O.some({
1674
+ if (!JSX7.hasProp("key", initialScope, node.openingElement.attributes)) {
1675
+ return {
1690
1676
  messageId: "noMissingKey",
1691
1677
  node
1692
- });
1678
+ };
1693
1679
  }
1694
- return O.none();
1680
+ return null;
1695
1681
  }
1696
1682
  case AST_NODE_TYPES.JSXFragment: {
1697
- return O.some({
1683
+ return {
1698
1684
  messageId: "noMissingKeyWithFragment",
1699
1685
  node
1700
- });
1686
+ };
1701
1687
  }
1702
1688
  default:
1703
- return O.none();
1689
+ return null;
1704
1690
  }
1705
1691
  }
1706
1692
  function checkExpression(node) {
1707
1693
  switch (node.type) {
1708
1694
  case AST_NODE_TYPES.ConditionalExpression:
1709
- if (!("consequent" in node)) {
1710
- return O.none();
1695
+ if ("consequent" in node) {
1696
+ return checkIteratorElement(node.consequent) ?? checkIteratorElement(node.alternate);
1711
1697
  }
1712
- return O.orElse(checkIteratorElement(node.consequent), () => checkIteratorElement(node.alternate));
1698
+ return null;
1713
1699
  case AST_NODE_TYPES.JSXElement:
1714
1700
  case AST_NODE_TYPES.JSXFragment:
1715
1701
  return checkIteratorElement(node);
1716
1702
  case AST_NODE_TYPES.LogicalExpression:
1717
- if (!("left" in node)) {
1718
- return O.none();
1703
+ if ("left" in node) {
1704
+ return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
1719
1705
  }
1720
- return O.orElse(checkIteratorElement(node.left), () => checkIteratorElement(node.right));
1706
+ return null;
1721
1707
  default:
1722
- return O.none();
1708
+ return null;
1723
1709
  }
1724
1710
  }
1725
1711
  function checkBlockStatement(node) {
1726
- return AST11.getNestedReturnStatements(node).reduce((acc, statement) => {
1712
+ const descriptors = [];
1713
+ for (const statement of AST11.getNestedReturnStatements(node)) {
1727
1714
  if (statement.argument == null) {
1728
- return acc;
1715
+ continue;
1716
+ }
1717
+ const descriptor = checkIteratorElement(statement.argument);
1718
+ if (descriptor != null) {
1719
+ descriptors.push(descriptor);
1729
1720
  }
1730
- const mbDescriptor = checkIteratorElement(statement.argument);
1731
- return O.isNone(mbDescriptor) ? acc : [...acc, mbDescriptor.value];
1732
- }, []);
1721
+ }
1722
+ return descriptors;
1733
1723
  }
1734
1724
  return {
1735
1725
  ArrayExpression(node) {
@@ -1742,7 +1732,7 @@ var no_missing_key_default = createRule({
1742
1732
  }
1743
1733
  const initialScope = context.sourceCode.getScope(node);
1744
1734
  for (const element of elements) {
1745
- if (!JSX7.hasProp(element.openingElement.attributes, "key", initialScope)) {
1735
+ if (!JSX7.hasProp("key", initialScope, element.openingElement.attributes)) {
1746
1736
  context.report({
1747
1737
  messageId: "noMissingKey",
1748
1738
  node: element
@@ -1755,30 +1745,24 @@ var no_missing_key_default = createRule({
1755
1745
  if (state.isWithinChildrenToArray) {
1756
1746
  return;
1757
1747
  }
1758
- const isMapCall = AST11.isMapCallLoose(node);
1759
- const isArrayFromCall = isMatching({
1760
- type: AST_NODE_TYPES.CallExpression,
1761
- callee: {
1762
- type: AST_NODE_TYPES.MemberExpression,
1763
- property: {
1764
- name: "from"
1765
- }
1766
- }
1767
- }, node);
1768
- if (!isMapCall && !isArrayFromCall) {
1748
+ const isMapCallLike = AST11.isMapCallLoose(node);
1749
+ if (!isMapCallLike && !isArrayFromCall(node)) {
1769
1750
  return;
1770
1751
  }
1771
- const fn = node.arguments[isMapCall ? 0 : 1];
1772
- if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) {
1752
+ const fn = node.arguments[isMapCallLike ? 0 : 1];
1753
+ if (fn?.type !== AST_NODE_TYPES.ArrowFunctionExpression && fn?.type !== AST_NODE_TYPES.FunctionExpression) {
1773
1754
  return;
1774
1755
  }
1775
1756
  if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
1776
- for (const descriptor of checkBlockStatement(fn.body)) {
1777
- context.report(descriptor);
1757
+ for (const descriptor2 of checkBlockStatement(fn.body)) {
1758
+ context.report(descriptor2);
1778
1759
  }
1779
1760
  return;
1780
1761
  }
1781
- O.map(checkExpression(fn.body), context.report);
1762
+ const descriptor = checkExpression(fn.body);
1763
+ if (descriptor != null) {
1764
+ context.report(descriptor);
1765
+ }
1782
1766
  },
1783
1767
  "CallExpression:exit"(node) {
1784
1768
  if (!isChildrenToArrayCall(node, context)) {
@@ -1801,6 +1785,9 @@ var no_missing_key_default = createRule({
1801
1785
  },
1802
1786
  defaultOptions: []
1803
1787
  });
1788
+ function isArrayFromCall(node) {
1789
+ 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";
1790
+ }
1804
1791
  var RULE_NAME30 = "no-nested-components";
1805
1792
  var RULE_FEATURES30 = [
1806
1793
  "CHK"
@@ -1839,16 +1826,15 @@ var no_nested_components_default = createRule({
1839
1826
  const isClassComponent11 = (node2) => {
1840
1827
  return AST11.isClass(node2) && classComponents.some((component) => component.node === node2);
1841
1828
  };
1842
- for (const { name: componentName, node: component } of functionComponents) {
1829
+ for (const { name: name2, node: component } of functionComponents) {
1843
1830
  if (isDirectValueOfRenderPropertyLoose(component)) {
1844
1831
  continue;
1845
1832
  }
1846
- if (O.isNone(componentName)) {
1833
+ if (name2 === _) {
1847
1834
  continue;
1848
1835
  }
1849
- const name2 = componentName.value;
1850
1836
  const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
1851
- const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
1837
+ const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
1852
1838
  if (isInsideJSXPropValue) {
1853
1839
  if (!isDeclaredInRenderPropLoose(component)) {
1854
1840
  context.report({
@@ -1871,13 +1857,8 @@ var no_nested_components_default = createRule({
1871
1857
  });
1872
1858
  continue;
1873
1859
  }
1874
- const isParnetComponentNotDirectValueOfRenderProperty = O.exists(
1875
- AST11.findParentNodeGuard(
1876
- component,
1877
- isFunctionComponent
1878
- ),
1879
- not(isDirectValueOfRenderPropertyLoose)
1880
- );
1860
+ const parentComponent = AST11.findParentNodeGuard(component, isFunctionComponent);
1861
+ const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
1881
1862
  if (isParnetComponentNotDirectValueOfRenderProperty) {
1882
1863
  context.report({
1883
1864
  messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
@@ -1898,15 +1879,15 @@ var no_nested_components_default = createRule({
1898
1879
  });
1899
1880
  }
1900
1881
  }
1901
- for (const { name: name2, node: component } of classComponents) {
1902
- if (O.isNone(AST11.findParentNode(component, or(isClassComponent11, isFunctionComponent)))) {
1882
+ for (const { name: name2 = "unknown", node: component } of classComponents) {
1883
+ if (AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
1903
1884
  continue;
1904
1885
  }
1905
1886
  context.report({
1906
1887
  messageId: "nestedComponent",
1907
1888
  node: component,
1908
1889
  data: {
1909
- name: O.getOrElse(() => "unknown")(name2)
1890
+ name: name2
1910
1891
  }
1911
1892
  });
1912
1893
  }
@@ -1951,15 +1932,11 @@ var no_prop_types_default = createRule({
1951
1932
  if (!isComponentName(object.name)) {
1952
1933
  return;
1953
1934
  }
1954
- const isComponent = F.pipe(
1955
- VAR.findVariable(object.name, context.sourceCode.getScope(node)),
1956
- O.flatMap(VAR.getVariableNode(0)),
1957
- O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
1958
- );
1959
- if (!isComponent) {
1960
- return;
1935
+ const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
1936
+ const variableNode = VAR.getVariableNode(variable, 0);
1937
+ if (variableNode != null && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
1938
+ context.report({ messageId: "noPropTypes", node: property });
1961
1939
  }
1962
- context.report({ messageId: "noPropTypes", node: property });
1963
1940
  },
1964
1941
  PropertyDefinition(node) {
1965
1942
  if (!isClassComponent(node.parent.parent)) {
@@ -2003,7 +1980,7 @@ var no_redundant_should_component_update_default = createRule({
2003
1980
  ...listeners,
2004
1981
  "Program:exit"(node) {
2005
1982
  const components = ctx.getAllComponents(node);
2006
- for (const { name: name2, node: component, flag } of components.values()) {
1983
+ for (const { name: name2 = "PureComponent", node: component, flag } of components.values()) {
2007
1984
  if ((flag & ERClassComponentFlag.PureComponent) === 0n) {
2008
1985
  continue;
2009
1986
  }
@@ -2014,7 +1991,7 @@ var no_redundant_should_component_update_default = createRule({
2014
1991
  messageId: "noRedundantShouldComponentUpdate",
2015
1992
  node: member,
2016
1993
  data: {
2017
- componentName: O.getOrElse(() => "PureComponent")(name2)
1994
+ componentName: name2
2018
1995
  }
2019
1996
  });
2020
1997
  }
@@ -2049,32 +2026,23 @@ var no_set_state_in_component_did_mount_default = createRule({
2049
2026
  if (!context.sourceCode.text.includes("componentDidMount")) {
2050
2027
  return {};
2051
2028
  }
2052
- function getReportDescriptor(node) {
2053
- if (!isThisSetState(node)) {
2054
- return O.none();
2055
- }
2056
- return F.pipe(
2057
- O.Do,
2058
- O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
2059
- O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentDidMount)),
2060
- O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
2061
- O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
2062
- O.filter(
2063
- ({
2064
- clazz,
2065
- method,
2066
- methodScope,
2067
- upperScope
2068
- }) => method.parent === clazz.body && upperScope === methodScope
2069
- ),
2070
- O.map(() => ({
2071
- messageId: "noSetStateInComponentDidMount",
2072
- node
2073
- }))
2074
- );
2075
- }
2076
2029
  return {
2077
- CallExpression: F.flow(getReportDescriptor, O.map(context.report))
2030
+ CallExpression(node) {
2031
+ if (!isThisSetState(node)) {
2032
+ return;
2033
+ }
2034
+ const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2035
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
2036
+ if (clazz == null || method == null || method === clazz) return;
2037
+ const methodScope = context.sourceCode.getScope(method);
2038
+ const upperScope = context.sourceCode.getScope(node).upper;
2039
+ if (method.parent === clazz.body && upperScope === methodScope) {
2040
+ context.report({
2041
+ messageId: "noSetStateInComponentDidMount",
2042
+ node
2043
+ });
2044
+ }
2045
+ }
2078
2046
  };
2079
2047
  },
2080
2048
  defaultOptions: []
@@ -2103,32 +2071,23 @@ var no_set_state_in_component_did_update_default = createRule({
2103
2071
  if (!context.sourceCode.text.includes("componentDidUpdate")) {
2104
2072
  return {};
2105
2073
  }
2106
- function getReportDescriptor(node) {
2107
- if (!isThisSetState(node)) {
2108
- return O.none();
2109
- }
2110
- return F.pipe(
2111
- O.Do,
2112
- O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
2113
- O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentDidUpdate)),
2114
- O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
2115
- O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
2116
- O.filter(
2117
- ({
2118
- clazz,
2119
- method,
2120
- methodScope,
2121
- upperScope
2122
- }) => method.parent === clazz.body && upperScope === methodScope
2123
- ),
2124
- O.map(() => ({
2125
- messageId: "noSetStateInComponentDidUpdate",
2126
- node
2127
- }))
2128
- );
2129
- }
2130
2074
  return {
2131
- CallExpression: F.flow(getReportDescriptor, O.map(context.report))
2075
+ CallExpression(node) {
2076
+ if (!isThisSetState(node)) {
2077
+ return;
2078
+ }
2079
+ const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2080
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
2081
+ if (clazz == null || method == null || method === clazz) return;
2082
+ const methodScope = context.sourceCode.getScope(method);
2083
+ const upperScope = context.sourceCode.getScope(node).upper;
2084
+ if (method.parent === clazz.body && upperScope === methodScope) {
2085
+ context.report({
2086
+ messageId: "noSetStateInComponentDidUpdate",
2087
+ node
2088
+ });
2089
+ }
2090
+ }
2132
2091
  };
2133
2092
  },
2134
2093
  defaultOptions: []
@@ -2157,32 +2116,23 @@ var no_set_state_in_component_will_update_default = createRule({
2157
2116
  if (!context.sourceCode.text.includes("componentWillUpdate")) {
2158
2117
  return {};
2159
2118
  }
2160
- function getReportDescriptor(node) {
2161
- if (!isThisSetState(node)) {
2162
- return O.none();
2163
- }
2164
- return F.pipe(
2165
- O.Do,
2166
- O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
2167
- O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentWillUpdate3)),
2168
- O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
2169
- O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
2170
- O.filter(
2171
- ({
2172
- clazz,
2173
- method,
2174
- methodScope,
2175
- upperScope
2176
- }) => method.parent === clazz.body && upperScope === methodScope
2177
- ),
2178
- O.map(() => ({
2179
- messageId: "noSetStateInComponentWillUpdate",
2180
- node
2181
- }))
2182
- );
2183
- }
2184
2119
  return {
2185
- CallExpression: F.flow(getReportDescriptor, O.map(context.report))
2120
+ CallExpression(node) {
2121
+ if (!isThisSetState(node)) {
2122
+ return;
2123
+ }
2124
+ const clazz = AST11.findParentNodeGuard(node, isClassComponent);
2125
+ const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
2126
+ if (clazz == null || method == null || method === clazz) return;
2127
+ const methodScope = context.sourceCode.getScope(method);
2128
+ const upperScope = context.sourceCode.getScope(node).upper;
2129
+ if (method.parent === clazz.body && upperScope === methodScope) {
2130
+ context.report({
2131
+ messageId: "noSetStateInComponentWillUpdate",
2132
+ node
2133
+ });
2134
+ }
2135
+ }
2186
2136
  };
2187
2137
  },
2188
2138
  defaultOptions: []
@@ -2192,14 +2142,14 @@ var RULE_FEATURES36 = [
2192
2142
  "CHK"
2193
2143
  ];
2194
2144
  function containsStringLiteral({ value }) {
2195
- return value?.type === AST_NODE_TYPES.Literal && isString(value.value);
2145
+ return value?.type === AST_NODE_TYPES.Literal && typeof value.value === "string";
2196
2146
  }
2197
2147
  function containsStringExpressionContainer({ value }) {
2198
2148
  if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
2199
2149
  return false;
2200
2150
  }
2201
2151
  if (value.expression.type === AST_NODE_TYPES.Literal) {
2202
- return isString(value.expression.value);
2152
+ return typeof value.expression.value === "string";
2203
2153
  }
2204
2154
  return value.expression.type === AST_NODE_TYPES.TemplateLiteral;
2205
2155
  }
@@ -2400,39 +2350,28 @@ var no_unstable_context_value_default = createRule({
2400
2350
  if (openingElementName.property.name !== "Provider") {
2401
2351
  return;
2402
2352
  }
2403
- F.pipe(
2404
- O.Do,
2405
- O.bind("function", ctx.getCurrentFunction),
2406
- O.bind("attribute", () => O.fromNullable(
2407
- node.attributes.find((attribute) => {
2408
- return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
2409
- })
2410
- )),
2411
- O.bind("value", ({ attribute }) => "value" in attribute ? O.some(attribute.value) : O.none()),
2412
- O.bind("valueExpression", ({ value }) => value?.type === AST_NODE_TYPES.JSXExpressionContainer ? O.some(value.expression) : O.none()),
2413
- O.bind("construction", ({ valueExpression }) => {
2414
- const initialScope = context.sourceCode.getScope(valueExpression);
2415
- return O.some(VAR.getValueConstruction(valueExpression, initialScope));
2416
- }),
2417
- O.map((vc) => {
2418
- if (vc.construction.kind === "None") {
2419
- return;
2420
- }
2421
- if (isReactHookCall(vc.construction.node)) {
2422
- return;
2423
- }
2424
- const prevs = constructions.get(vc.function.node) ?? [];
2425
- constructions.set(vc.function.node, [...prevs, vc.construction]);
2426
- })
2353
+ const functionEntry = ctx.getCurrentEntry();
2354
+ if (functionEntry == null) return;
2355
+ const attribute = node.attributes.find(
2356
+ (attribute2) => attribute2.type === AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
2427
2357
  );
2358
+ if (attribute == null || !("value" in attribute)) return;
2359
+ const value = attribute.value;
2360
+ if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
2361
+ const valueExpression = value.expression;
2362
+ const initialScope = context.sourceCode.getScope(valueExpression);
2363
+ const construction = VAR.getValueConstruction(valueExpression, initialScope);
2364
+ if (construction == null) return;
2365
+ if (isReactHookCall(construction.node)) {
2366
+ return;
2367
+ }
2368
+ const prevs = constructions.get(functionEntry.node) ?? [];
2369
+ constructions.set(functionEntry.node, [...prevs, construction]);
2428
2370
  },
2429
2371
  "Program:exit"(node) {
2430
2372
  const components = ctx.getAllComponents(node).values();
2431
2373
  for (const { node: component } of components) {
2432
2374
  for (const construction of constructions.get(component) ?? []) {
2433
- if (construction.kind === "None") {
2434
- continue;
2435
- }
2436
2375
  const { kind, node: constructionNode } = construction;
2437
2376
  const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
2438
2377
  context.report({
@@ -2494,7 +2433,7 @@ var no_unstable_default_props_default = createRule({
2494
2433
  initialScope,
2495
2434
  VAR.ValueConstructionHint.StrictCallExpression
2496
2435
  );
2497
- if (construction.kind === "None") {
2436
+ if (construction == null) {
2498
2437
  continue;
2499
2438
  }
2500
2439
  if (isReactHookCall(construction.node)) {
@@ -2512,13 +2451,10 @@ var no_unstable_default_props_default = createRule({
2512
2451
  }
2513
2452
  },
2514
2453
  "VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
2515
- const mbEntry = ctx.getCurrentFunction();
2516
- if (O.isNone(mbEntry)) {
2517
- return;
2518
- }
2519
- const entry = mbEntry.value;
2520
- const prevs = declarators.get(entry.node) ?? [];
2521
- declarators.set(entry.node, [...prevs, node]);
2454
+ const functionEntry = ctx.getCurrentEntry();
2455
+ if (functionEntry == null) return;
2456
+ const prevs = declarators.get(functionEntry.node) ?? [];
2457
+ declarators.set(functionEntry.node, [...prevs, node]);
2522
2458
  }
2523
2459
  };
2524
2460
  },
@@ -2550,15 +2486,15 @@ function getName3(node) {
2550
2486
  return getName3(node.expression);
2551
2487
  }
2552
2488
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
2553
- return O.some(node.name);
2489
+ return node.name;
2554
2490
  }
2555
2491
  if (node.type === AST_NODE_TYPES.Literal) {
2556
- return O.some(String(node.value));
2492
+ return node.value?.toString();
2557
2493
  }
2558
2494
  if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
2559
- return O.fromNullable(node.quasis[0]?.value.raw);
2495
+ return node.quasis[0]?.value.raw;
2560
2496
  }
2561
- return O.none();
2497
+ return _;
2562
2498
  }
2563
2499
  var no_unused_class_component_members_default = createRule({
2564
2500
  meta: {
@@ -2574,12 +2510,12 @@ var no_unused_class_component_members_default = createRule({
2574
2510
  },
2575
2511
  name: RULE_NAME42,
2576
2512
  create(context) {
2577
- const classStack = [];
2578
- const methodStack = [];
2513
+ const classEntries = [];
2514
+ const methodEntries = [];
2579
2515
  const propertyDefs = /* @__PURE__ */ new WeakMap();
2580
2516
  const propertyUsages = /* @__PURE__ */ new WeakMap();
2581
2517
  function classEnter(node) {
2582
- classStack.push(node);
2518
+ classEntries.push(node);
2583
2519
  if (!isClassComponent(node)) {
2584
2520
  return;
2585
2521
  }
@@ -2587,37 +2523,37 @@ var no_unused_class_component_members_default = createRule({
2587
2523
  propertyUsages.set(node, /* @__PURE__ */ new Set());
2588
2524
  }
2589
2525
  function classExit() {
2590
- const currentClass = classStack.pop();
2526
+ const currentClass = classEntries.pop();
2591
2527
  if (currentClass == null || !isClassComponent(currentClass)) {
2592
2528
  return;
2593
2529
  }
2594
- const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
2530
+ const className = AST11.getClassIdentifier(currentClass)?.name;
2595
2531
  const defs = propertyDefs.get(currentClass);
2596
2532
  const usages = propertyUsages.get(currentClass);
2597
2533
  if (defs == null) {
2598
2534
  return;
2599
2535
  }
2600
2536
  for (const def of defs) {
2601
- const name2 = getName3(def);
2602
- if (O.isNone(name2)) {
2537
+ const methodName = getName3(def);
2538
+ if (methodName == null) {
2603
2539
  continue;
2604
2540
  }
2605
- if (usages?.has(name2.value) || LIFECYCLE_METHODS.has(name2.value)) {
2541
+ if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
2606
2542
  continue;
2607
2543
  }
2608
2544
  context.report({
2609
2545
  messageId: "noUnusedClassComponentMembers",
2610
2546
  node: def,
2611
2547
  data: {
2612
- className: O.getOrElse(className, () => "Component"),
2613
- methodName: name2.value
2548
+ className: className ?? "Component",
2549
+ methodName
2614
2550
  }
2615
2551
  });
2616
2552
  }
2617
2553
  }
2618
2554
  function methodEnter(node) {
2619
- methodStack.push(node);
2620
- const currentClass = classStack.at(-1);
2555
+ methodEntries.push(node);
2556
+ const currentClass = classEntries.at(-1);
2621
2557
  if (currentClass == null || !isClassComponent(currentClass)) {
2622
2558
  return;
2623
2559
  }
@@ -2629,7 +2565,7 @@ var no_unused_class_component_members_default = createRule({
2629
2565
  }
2630
2566
  }
2631
2567
  function methodExit() {
2632
- methodStack.pop();
2568
+ methodEntries.pop();
2633
2569
  }
2634
2570
  return {
2635
2571
  ClassDeclaration: classEnter,
@@ -2637,8 +2573,8 @@ var no_unused_class_component_members_default = createRule({
2637
2573
  ClassExpression: classEnter,
2638
2574
  "ClassExpression:exit": classExit,
2639
2575
  MemberExpression(node) {
2640
- const currentClass = classStack.at(-1);
2641
- const currentMethod = methodStack.at(-1);
2576
+ const currentClass = classEntries.at(-1);
2577
+ const currentMethod = methodEntries.at(-1);
2642
2578
  if (currentClass == null || currentMethod == null) {
2643
2579
  return;
2644
2580
  }
@@ -2652,15 +2588,18 @@ var no_unused_class_component_members_default = createRule({
2652
2588
  propertyDefs.get(currentClass)?.add(node.property);
2653
2589
  return;
2654
2590
  }
2655
- O.map(getName3(node.property), (name2) => propertyUsages.get(currentClass)?.add(name2));
2591
+ const propertyName = getName3(node.property);
2592
+ if (propertyName != null) {
2593
+ propertyUsages.get(currentClass)?.add(propertyName);
2594
+ }
2656
2595
  },
2657
2596
  MethodDefinition: methodEnter,
2658
2597
  "MethodDefinition:exit": methodExit,
2659
2598
  PropertyDefinition: methodEnter,
2660
2599
  "PropertyDefinition:exit": methodExit,
2661
2600
  VariableDeclarator(node) {
2662
- const currentClass = classStack.at(-1);
2663
- const currentMethod = methodStack.at(-1);
2601
+ const currentClass = classEntries.at(-1);
2602
+ const currentMethod = methodEntries.at(-1);
2664
2603
  if (currentClass == null || currentMethod == null) {
2665
2604
  return;
2666
2605
  }
@@ -2670,10 +2609,9 @@ var no_unused_class_component_members_default = createRule({
2670
2609
  if (node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
2671
2610
  for (const prop of node.id.properties) {
2672
2611
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2673
- const mbName = getName3(prop.key);
2674
- if (O.isSome(mbName)) {
2675
- const name2 = mbName.value;
2676
- propertyUsages.get(currentClass)?.add(name2);
2612
+ const keyName = getName3(prop.key);
2613
+ if (keyName != null) {
2614
+ propertyUsages.get(currentClass)?.add(keyName);
2677
2615
  }
2678
2616
  }
2679
2617
  }
@@ -2692,19 +2630,19 @@ function getName4(node) {
2692
2630
  return getName4(node.expression);
2693
2631
  }
2694
2632
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
2695
- return O.some(node.name);
2633
+ return node.name;
2696
2634
  }
2697
2635
  if (node.type === AST_NODE_TYPES.Literal) {
2698
- return O.some(String(node.value));
2636
+ return String(node.value);
2699
2637
  }
2700
2638
  if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
2701
- return O.fromNullable(node.quasis[0]?.value.raw);
2639
+ return node.quasis[0]?.value.raw;
2702
2640
  }
2703
- return O.none();
2641
+ return _;
2704
2642
  }
2705
2643
  function isAssignmentToThisState2(node) {
2706
2644
  const { left } = node;
2707
- return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && O.exists(getName4(left.property), (name2) => name2 === "state");
2645
+ return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
2708
2646
  }
2709
2647
  var isGetDerivedStateFromProps = isMatching({
2710
2648
  key: {
@@ -2729,72 +2667,72 @@ var no_unused_state_default = createRule({
2729
2667
  },
2730
2668
  name: RULE_NAME43,
2731
2669
  create(context) {
2732
- const classStack = [];
2733
- const methodStack = [];
2734
- const constructorStack = [];
2670
+ const classEntries = [];
2671
+ const methodEntries = [];
2672
+ const constructorEntries = [];
2735
2673
  const stateDefs = /* @__PURE__ */ new WeakMap();
2736
2674
  function classEnter(node) {
2737
- classStack.push(node);
2675
+ classEntries.push(node);
2738
2676
  }
2739
2677
  function classExit() {
2740
- const currentClass = classStack.pop();
2678
+ const currentClass = classEntries.pop();
2741
2679
  if (currentClass == null || !isClassComponent(currentClass)) {
2742
2680
  return;
2743
2681
  }
2744
- const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
2745
- const [def, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
2746
- if (O.isNone(def) || isUsed) {
2682
+ const className = AST11.getClassIdentifier(currentClass)?.name;
2683
+ const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
2684
+ if (defNode == null || isUsed) {
2747
2685
  return;
2748
2686
  }
2749
2687
  context.report({
2750
2688
  messageId: "noUnusedState",
2751
- node: def.value,
2689
+ node: defNode,
2752
2690
  data: {
2753
- className: O.getOrElse(className, () => "Component")
2691
+ className: className ?? "Component"
2754
2692
  }
2755
2693
  });
2756
2694
  }
2757
2695
  function methodEnter(node) {
2758
- methodStack.push(node);
2759
- const currentClass = classStack.at(-1);
2696
+ methodEntries.push(node);
2697
+ const currentClass = classEntries.at(-1);
2760
2698
  if (currentClass == null || !isClassComponent(currentClass)) {
2761
2699
  return;
2762
2700
  }
2763
2701
  if (node.static) {
2764
2702
  if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
2765
- const [def] = stateDefs.get(currentClass) ?? [O.none()];
2766
- stateDefs.set(currentClass, [def, true]);
2703
+ const defNode = stateDefs.get(currentClass)?.node;
2704
+ stateDefs.set(currentClass, { node: defNode, isUsed: true });
2767
2705
  }
2768
2706
  return;
2769
2707
  }
2770
- if (O.exists(getName4(node.key), (name2) => name2 === "state")) {
2771
- stateDefs.set(currentClass, [O.some(node.key), false]);
2708
+ if (getName4(node.key) === "state") {
2709
+ stateDefs.set(currentClass, { node: node.key, isUsed: false });
2772
2710
  }
2773
2711
  }
2774
2712
  function methodExit() {
2775
- methodStack.pop();
2713
+ methodEntries.pop();
2776
2714
  }
2777
2715
  function constructorEnter(node) {
2778
- constructorStack.push(node);
2716
+ constructorEntries.push(node);
2779
2717
  }
2780
2718
  function constructorExit() {
2781
- constructorStack.pop();
2719
+ constructorEntries.pop();
2782
2720
  }
2783
2721
  return {
2784
2722
  AssignmentExpression(node) {
2785
2723
  if (!isAssignmentToThisState2(node)) {
2786
2724
  return;
2787
2725
  }
2788
- const currentClass = classStack.at(-1);
2726
+ const currentClass = classEntries.at(-1);
2789
2727
  if (currentClass == null || !isClassComponent(currentClass)) {
2790
2728
  return;
2791
2729
  }
2792
- const currentConstructor = constructorStack.at(-1);
2730
+ const currentConstructor = constructorEntries.at(-1);
2793
2731
  if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
2794
2732
  return;
2795
2733
  }
2796
- const [_, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
2797
- stateDefs.set(currentClass, [O.some(node.left), isUsed]);
2734
+ const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
2735
+ stateDefs.set(currentClass, { node: node.left, isUsed });
2798
2736
  },
2799
2737
  ClassDeclaration: classEnter,
2800
2738
  "ClassDeclaration:exit": classExit,
@@ -2804,25 +2742,25 @@ var no_unused_state_default = createRule({
2804
2742
  if (!AST11.isThisExpression(node.object)) {
2805
2743
  return;
2806
2744
  }
2807
- if (!O.exists(getName4(node.property), (name2) => name2 === "state")) {
2745
+ if (getName4(node.property) !== "state") {
2808
2746
  return;
2809
2747
  }
2810
- const currentClass = classStack.at(-1);
2748
+ const currentClass = classEntries.at(-1);
2811
2749
  if (currentClass == null || !isClassComponent(currentClass)) {
2812
2750
  return;
2813
2751
  }
2814
- const currentMethod = methodStack.at(-1);
2752
+ const currentMethod = methodEntries.at(-1);
2815
2753
  if (currentMethod == null || currentMethod.static) {
2816
2754
  return;
2817
2755
  }
2818
- if (currentMethod === constructorStack.at(-1)) {
2756
+ if (currentMethod === constructorEntries.at(-1)) {
2819
2757
  return;
2820
2758
  }
2821
2759
  if (!currentClass.body.body.includes(currentMethod)) {
2822
2760
  return;
2823
2761
  }
2824
- const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
2825
- stateDefs.set(currentClass, [def, true]);
2762
+ const defNode = stateDefs.get(currentClass)?.node;
2763
+ stateDefs.set(currentClass, { node: defNode, isUsed: true });
2826
2764
  },
2827
2765
  MethodDefinition: methodEnter,
2828
2766
  "MethodDefinition:exit": methodExit,
@@ -2831,15 +2769,15 @@ var no_unused_state_default = createRule({
2831
2769
  PropertyDefinition: methodEnter,
2832
2770
  "PropertyDefinition:exit": methodExit,
2833
2771
  VariableDeclarator(node) {
2834
- const currentClass = classStack.at(-1);
2772
+ const currentClass = classEntries.at(-1);
2835
2773
  if (currentClass == null || !isClassComponent(currentClass)) {
2836
2774
  return;
2837
2775
  }
2838
- const currentMethod = methodStack.at(-1);
2776
+ const currentMethod = methodEntries.at(-1);
2839
2777
  if (currentMethod == null || currentMethod.static) {
2840
2778
  return;
2841
2779
  }
2842
- if (currentMethod === constructorStack.at(-1)) {
2780
+ if (currentMethod === constructorEntries.at(-1)) {
2843
2781
  return;
2844
2782
  }
2845
2783
  if (!currentClass.body.body.includes(currentMethod)) {
@@ -2850,15 +2788,15 @@ var no_unused_state_default = createRule({
2850
2788
  }
2851
2789
  const hasState = node.id.properties.some((prop) => {
2852
2790
  if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
2853
- return O.exists(getName4(prop.key), (name2) => name2 === "state");
2791
+ return getName4(prop.key) === "state";
2854
2792
  }
2855
2793
  return false;
2856
2794
  });
2857
2795
  if (!hasState) {
2858
2796
  return;
2859
2797
  }
2860
- const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
2861
- stateDefs.set(currentClass, [def, true]);
2798
+ const defNode = stateDefs.get(currentClass)?.node;
2799
+ stateDefs.set(currentClass, { node: defNode, isUsed: true });
2862
2800
  }
2863
2801
  };
2864
2802
  },
@@ -2985,10 +2923,8 @@ var prefer_destructuring_assignment_default = createRule({
2985
2923
  if (!AST11.isFunction(block)) {
2986
2924
  return false;
2987
2925
  }
2988
- return O.exists(
2989
- AST11.getFunctionIdentifier(block),
2990
- (id) => isComponentName(id.name) && components.some((component) => component.node === block)
2991
- );
2926
+ const id = AST11.getFunctionIdentifier(block);
2927
+ return id != null && isComponentName(id.name) && components.some((component) => component.node === block);
2992
2928
  }
2993
2929
  for (const [initialScope, memberExpression] of memberExpressionWithNames) {
2994
2930
  let scope = initialScope;
@@ -3117,7 +3053,7 @@ var prefer_read_only_props_default = createRule({
3117
3053
  ...listeners,
3118
3054
  "Program:exit"(node) {
3119
3055
  const components = ctx.getAllComponents(node);
3120
- for (const [_, component] of components) {
3056
+ for (const [, component] of components) {
3121
3057
  const [props] = component.node.params;
3122
3058
  if (props == null) {
3123
3059
  continue;
@@ -3153,24 +3089,23 @@ var prefer_shorthand_boolean_default = createRule({
3153
3089
  },
3154
3090
  name: RULE_NAME48,
3155
3091
  create(context) {
3156
- function getReportDescriptor(node) {
3157
- const { value } = node;
3158
- const propName = JSX7.getPropName(node);
3159
- const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
3160
- if (!hasValueTrue) {
3161
- return O.none();
3162
- }
3163
- return O.some({
3164
- messageId: "preferShorthandBoolean",
3165
- node,
3166
- data: {
3167
- propName
3168
- },
3169
- fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
3170
- });
3171
- }
3172
3092
  return {
3173
- JSXAttribute: F.flow(getReportDescriptor, O.map(context.report))
3093
+ JSXAttribute(node) {
3094
+ const { value } = node;
3095
+ const propName = JSX7.getPropName(node);
3096
+ const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
3097
+ if (!hasValueTrue) {
3098
+ return;
3099
+ }
3100
+ context.report({
3101
+ messageId: "preferShorthandBoolean",
3102
+ node,
3103
+ data: {
3104
+ propName
3105
+ },
3106
+ fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
3107
+ });
3108
+ }
3174
3109
  };
3175
3110
  },
3176
3111
  defaultOptions: []
@@ -3195,31 +3130,32 @@ var prefer_shorthand_fragment_default = createRule({
3195
3130
  },
3196
3131
  name: RULE_NAME49,
3197
3132
  create(context) {
3198
- function getReportDescriptor(node) {
3199
- if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
3200
- return O.none();
3201
- }
3202
- const hasAttributes = node.openingElement.attributes.length > 0;
3203
- if (hasAttributes) {
3204
- return O.none();
3205
- }
3206
- return O.some({
3207
- messageId: "preferShorthandFragment",
3208
- node,
3209
- fix: (fixer) => {
3210
- const { closingElement, openingElement } = node;
3211
- if (closingElement == null) {
3212
- return [];
3213
- }
3214
- return [
3215
- fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
3216
- fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
3217
- ];
3218
- }
3219
- });
3220
- }
3221
3133
  return {
3222
- JSXElement: F.flow(getReportDescriptor, O.map(context.report))
3134
+ JSXElement(node) {
3135
+ if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
3136
+ return;
3137
+ }
3138
+ const hasAttributes = node.openingElement.attributes.length > 0;
3139
+ if (hasAttributes) {
3140
+ return;
3141
+ }
3142
+ context.report({
3143
+ messageId: "preferShorthandFragment",
3144
+ node,
3145
+ fix: (fixer) => {
3146
+ const { closingElement, openingElement } = node;
3147
+ if (closingElement == null) {
3148
+ return [];
3149
+ }
3150
+ return [
3151
+ // eslint-disable-next-line eslint-plugin/prefer-replace-text
3152
+ fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
3153
+ // eslint-disable-next-line eslint-plugin/prefer-replace-text
3154
+ fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
3155
+ ];
3156
+ }
3157
+ });
3158
+ }
3223
3159
  };
3224
3160
  },
3225
3161
  defaultOptions: []
@@ -3241,23 +3177,23 @@ var use_jsx_vars_default = createRule({
3241
3177
  },
3242
3178
  name: RULE_NAME50,
3243
3179
  create(context) {
3244
- function getName5(node) {
3245
- switch (node.type) {
3246
- case AST_NODE_TYPES.JSXIdentifier:
3247
- return O.some(node.name);
3248
- case AST_NODE_TYPES.JSXMemberExpression:
3249
- return getName5(node.object);
3250
- default:
3251
- return O.none();
3252
- }
3253
- }
3254
3180
  return {
3255
3181
  JSXOpeningElement(node) {
3256
- if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) {
3257
- return;
3258
- }
3259
- for (const name2 of O.toArray(getName5(node.name))) {
3260
- context.sourceCode.markVariableAsUsed(name2, node);
3182
+ switch (node.name.type) {
3183
+ case AST_NODE_TYPES.JSXIdentifier: {
3184
+ if (/^[a-z]/u.test(node.name.name)) {
3185
+ return;
3186
+ }
3187
+ context.sourceCode.markVariableAsUsed(node.name.name, node);
3188
+ break;
3189
+ }
3190
+ case AST_NODE_TYPES.JSXMemberExpression: {
3191
+ const { object } = node.name;
3192
+ if (object.type === AST_NODE_TYPES.JSXIdentifier) {
3193
+ context.sourceCode.markVariableAsUsed(object.name, node);
3194
+ }
3195
+ break;
3196
+ }
3261
3197
  }
3262
3198
  }
3263
3199
  };