@pobammer-ts/eslint-cease-nonsense-rules 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/stricty ADDED
@@ -0,0 +1,3303 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+
20
+ // node_modules/@typescript-eslint/types/dist/generated/ast-spec.js
21
+ var require_ast_spec = __commonJS((exports) => {
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.AST_TOKEN_TYPES = exports.AST_NODE_TYPES = undefined;
24
+ var AST_NODE_TYPES;
25
+ (function(AST_NODE_TYPES2) {
26
+ AST_NODE_TYPES2["AccessorProperty"] = "AccessorProperty";
27
+ AST_NODE_TYPES2["ArrayExpression"] = "ArrayExpression";
28
+ AST_NODE_TYPES2["ArrayPattern"] = "ArrayPattern";
29
+ AST_NODE_TYPES2["ArrowFunctionExpression"] = "ArrowFunctionExpression";
30
+ AST_NODE_TYPES2["AssignmentExpression"] = "AssignmentExpression";
31
+ AST_NODE_TYPES2["AssignmentPattern"] = "AssignmentPattern";
32
+ AST_NODE_TYPES2["AwaitExpression"] = "AwaitExpression";
33
+ AST_NODE_TYPES2["BinaryExpression"] = "BinaryExpression";
34
+ AST_NODE_TYPES2["BlockStatement"] = "BlockStatement";
35
+ AST_NODE_TYPES2["BreakStatement"] = "BreakStatement";
36
+ AST_NODE_TYPES2["CallExpression"] = "CallExpression";
37
+ AST_NODE_TYPES2["CatchClause"] = "CatchClause";
38
+ AST_NODE_TYPES2["ChainExpression"] = "ChainExpression";
39
+ AST_NODE_TYPES2["ClassBody"] = "ClassBody";
40
+ AST_NODE_TYPES2["ClassDeclaration"] = "ClassDeclaration";
41
+ AST_NODE_TYPES2["ClassExpression"] = "ClassExpression";
42
+ AST_NODE_TYPES2["ConditionalExpression"] = "ConditionalExpression";
43
+ AST_NODE_TYPES2["ContinueStatement"] = "ContinueStatement";
44
+ AST_NODE_TYPES2["DebuggerStatement"] = "DebuggerStatement";
45
+ AST_NODE_TYPES2["Decorator"] = "Decorator";
46
+ AST_NODE_TYPES2["DoWhileStatement"] = "DoWhileStatement";
47
+ AST_NODE_TYPES2["EmptyStatement"] = "EmptyStatement";
48
+ AST_NODE_TYPES2["ExportAllDeclaration"] = "ExportAllDeclaration";
49
+ AST_NODE_TYPES2["ExportDefaultDeclaration"] = "ExportDefaultDeclaration";
50
+ AST_NODE_TYPES2["ExportNamedDeclaration"] = "ExportNamedDeclaration";
51
+ AST_NODE_TYPES2["ExportSpecifier"] = "ExportSpecifier";
52
+ AST_NODE_TYPES2["ExpressionStatement"] = "ExpressionStatement";
53
+ AST_NODE_TYPES2["ForInStatement"] = "ForInStatement";
54
+ AST_NODE_TYPES2["ForOfStatement"] = "ForOfStatement";
55
+ AST_NODE_TYPES2["ForStatement"] = "ForStatement";
56
+ AST_NODE_TYPES2["FunctionDeclaration"] = "FunctionDeclaration";
57
+ AST_NODE_TYPES2["FunctionExpression"] = "FunctionExpression";
58
+ AST_NODE_TYPES2["Identifier"] = "Identifier";
59
+ AST_NODE_TYPES2["IfStatement"] = "IfStatement";
60
+ AST_NODE_TYPES2["ImportAttribute"] = "ImportAttribute";
61
+ AST_NODE_TYPES2["ImportDeclaration"] = "ImportDeclaration";
62
+ AST_NODE_TYPES2["ImportDefaultSpecifier"] = "ImportDefaultSpecifier";
63
+ AST_NODE_TYPES2["ImportExpression"] = "ImportExpression";
64
+ AST_NODE_TYPES2["ImportNamespaceSpecifier"] = "ImportNamespaceSpecifier";
65
+ AST_NODE_TYPES2["ImportSpecifier"] = "ImportSpecifier";
66
+ AST_NODE_TYPES2["JSXAttribute"] = "JSXAttribute";
67
+ AST_NODE_TYPES2["JSXClosingElement"] = "JSXClosingElement";
68
+ AST_NODE_TYPES2["JSXClosingFragment"] = "JSXClosingFragment";
69
+ AST_NODE_TYPES2["JSXElement"] = "JSXElement";
70
+ AST_NODE_TYPES2["JSXEmptyExpression"] = "JSXEmptyExpression";
71
+ AST_NODE_TYPES2["JSXExpressionContainer"] = "JSXExpressionContainer";
72
+ AST_NODE_TYPES2["JSXFragment"] = "JSXFragment";
73
+ AST_NODE_TYPES2["JSXIdentifier"] = "JSXIdentifier";
74
+ AST_NODE_TYPES2["JSXMemberExpression"] = "JSXMemberExpression";
75
+ AST_NODE_TYPES2["JSXNamespacedName"] = "JSXNamespacedName";
76
+ AST_NODE_TYPES2["JSXOpeningElement"] = "JSXOpeningElement";
77
+ AST_NODE_TYPES2["JSXOpeningFragment"] = "JSXOpeningFragment";
78
+ AST_NODE_TYPES2["JSXSpreadAttribute"] = "JSXSpreadAttribute";
79
+ AST_NODE_TYPES2["JSXSpreadChild"] = "JSXSpreadChild";
80
+ AST_NODE_TYPES2["JSXText"] = "JSXText";
81
+ AST_NODE_TYPES2["LabeledStatement"] = "LabeledStatement";
82
+ AST_NODE_TYPES2["Literal"] = "Literal";
83
+ AST_NODE_TYPES2["LogicalExpression"] = "LogicalExpression";
84
+ AST_NODE_TYPES2["MemberExpression"] = "MemberExpression";
85
+ AST_NODE_TYPES2["MetaProperty"] = "MetaProperty";
86
+ AST_NODE_TYPES2["MethodDefinition"] = "MethodDefinition";
87
+ AST_NODE_TYPES2["NewExpression"] = "NewExpression";
88
+ AST_NODE_TYPES2["ObjectExpression"] = "ObjectExpression";
89
+ AST_NODE_TYPES2["ObjectPattern"] = "ObjectPattern";
90
+ AST_NODE_TYPES2["PrivateIdentifier"] = "PrivateIdentifier";
91
+ AST_NODE_TYPES2["Program"] = "Program";
92
+ AST_NODE_TYPES2["Property"] = "Property";
93
+ AST_NODE_TYPES2["PropertyDefinition"] = "PropertyDefinition";
94
+ AST_NODE_TYPES2["RestElement"] = "RestElement";
95
+ AST_NODE_TYPES2["ReturnStatement"] = "ReturnStatement";
96
+ AST_NODE_TYPES2["SequenceExpression"] = "SequenceExpression";
97
+ AST_NODE_TYPES2["SpreadElement"] = "SpreadElement";
98
+ AST_NODE_TYPES2["StaticBlock"] = "StaticBlock";
99
+ AST_NODE_TYPES2["Super"] = "Super";
100
+ AST_NODE_TYPES2["SwitchCase"] = "SwitchCase";
101
+ AST_NODE_TYPES2["SwitchStatement"] = "SwitchStatement";
102
+ AST_NODE_TYPES2["TaggedTemplateExpression"] = "TaggedTemplateExpression";
103
+ AST_NODE_TYPES2["TemplateElement"] = "TemplateElement";
104
+ AST_NODE_TYPES2["TemplateLiteral"] = "TemplateLiteral";
105
+ AST_NODE_TYPES2["ThisExpression"] = "ThisExpression";
106
+ AST_NODE_TYPES2["ThrowStatement"] = "ThrowStatement";
107
+ AST_NODE_TYPES2["TryStatement"] = "TryStatement";
108
+ AST_NODE_TYPES2["UnaryExpression"] = "UnaryExpression";
109
+ AST_NODE_TYPES2["UpdateExpression"] = "UpdateExpression";
110
+ AST_NODE_TYPES2["VariableDeclaration"] = "VariableDeclaration";
111
+ AST_NODE_TYPES2["VariableDeclarator"] = "VariableDeclarator";
112
+ AST_NODE_TYPES2["WhileStatement"] = "WhileStatement";
113
+ AST_NODE_TYPES2["WithStatement"] = "WithStatement";
114
+ AST_NODE_TYPES2["YieldExpression"] = "YieldExpression";
115
+ AST_NODE_TYPES2["TSAbstractAccessorProperty"] = "TSAbstractAccessorProperty";
116
+ AST_NODE_TYPES2["TSAbstractKeyword"] = "TSAbstractKeyword";
117
+ AST_NODE_TYPES2["TSAbstractMethodDefinition"] = "TSAbstractMethodDefinition";
118
+ AST_NODE_TYPES2["TSAbstractPropertyDefinition"] = "TSAbstractPropertyDefinition";
119
+ AST_NODE_TYPES2["TSAnyKeyword"] = "TSAnyKeyword";
120
+ AST_NODE_TYPES2["TSArrayType"] = "TSArrayType";
121
+ AST_NODE_TYPES2["TSAsExpression"] = "TSAsExpression";
122
+ AST_NODE_TYPES2["TSAsyncKeyword"] = "TSAsyncKeyword";
123
+ AST_NODE_TYPES2["TSBigIntKeyword"] = "TSBigIntKeyword";
124
+ AST_NODE_TYPES2["TSBooleanKeyword"] = "TSBooleanKeyword";
125
+ AST_NODE_TYPES2["TSCallSignatureDeclaration"] = "TSCallSignatureDeclaration";
126
+ AST_NODE_TYPES2["TSClassImplements"] = "TSClassImplements";
127
+ AST_NODE_TYPES2["TSConditionalType"] = "TSConditionalType";
128
+ AST_NODE_TYPES2["TSConstructorType"] = "TSConstructorType";
129
+ AST_NODE_TYPES2["TSConstructSignatureDeclaration"] = "TSConstructSignatureDeclaration";
130
+ AST_NODE_TYPES2["TSDeclareFunction"] = "TSDeclareFunction";
131
+ AST_NODE_TYPES2["TSDeclareKeyword"] = "TSDeclareKeyword";
132
+ AST_NODE_TYPES2["TSEmptyBodyFunctionExpression"] = "TSEmptyBodyFunctionExpression";
133
+ AST_NODE_TYPES2["TSEnumBody"] = "TSEnumBody";
134
+ AST_NODE_TYPES2["TSEnumDeclaration"] = "TSEnumDeclaration";
135
+ AST_NODE_TYPES2["TSEnumMember"] = "TSEnumMember";
136
+ AST_NODE_TYPES2["TSExportAssignment"] = "TSExportAssignment";
137
+ AST_NODE_TYPES2["TSExportKeyword"] = "TSExportKeyword";
138
+ AST_NODE_TYPES2["TSExternalModuleReference"] = "TSExternalModuleReference";
139
+ AST_NODE_TYPES2["TSFunctionType"] = "TSFunctionType";
140
+ AST_NODE_TYPES2["TSImportEqualsDeclaration"] = "TSImportEqualsDeclaration";
141
+ AST_NODE_TYPES2["TSImportType"] = "TSImportType";
142
+ AST_NODE_TYPES2["TSIndexedAccessType"] = "TSIndexedAccessType";
143
+ AST_NODE_TYPES2["TSIndexSignature"] = "TSIndexSignature";
144
+ AST_NODE_TYPES2["TSInferType"] = "TSInferType";
145
+ AST_NODE_TYPES2["TSInstantiationExpression"] = "TSInstantiationExpression";
146
+ AST_NODE_TYPES2["TSInterfaceBody"] = "TSInterfaceBody";
147
+ AST_NODE_TYPES2["TSInterfaceDeclaration"] = "TSInterfaceDeclaration";
148
+ AST_NODE_TYPES2["TSInterfaceHeritage"] = "TSInterfaceHeritage";
149
+ AST_NODE_TYPES2["TSIntersectionType"] = "TSIntersectionType";
150
+ AST_NODE_TYPES2["TSIntrinsicKeyword"] = "TSIntrinsicKeyword";
151
+ AST_NODE_TYPES2["TSLiteralType"] = "TSLiteralType";
152
+ AST_NODE_TYPES2["TSMappedType"] = "TSMappedType";
153
+ AST_NODE_TYPES2["TSMethodSignature"] = "TSMethodSignature";
154
+ AST_NODE_TYPES2["TSModuleBlock"] = "TSModuleBlock";
155
+ AST_NODE_TYPES2["TSModuleDeclaration"] = "TSModuleDeclaration";
156
+ AST_NODE_TYPES2["TSNamedTupleMember"] = "TSNamedTupleMember";
157
+ AST_NODE_TYPES2["TSNamespaceExportDeclaration"] = "TSNamespaceExportDeclaration";
158
+ AST_NODE_TYPES2["TSNeverKeyword"] = "TSNeverKeyword";
159
+ AST_NODE_TYPES2["TSNonNullExpression"] = "TSNonNullExpression";
160
+ AST_NODE_TYPES2["TSNullKeyword"] = "TSNullKeyword";
161
+ AST_NODE_TYPES2["TSNumberKeyword"] = "TSNumberKeyword";
162
+ AST_NODE_TYPES2["TSObjectKeyword"] = "TSObjectKeyword";
163
+ AST_NODE_TYPES2["TSOptionalType"] = "TSOptionalType";
164
+ AST_NODE_TYPES2["TSParameterProperty"] = "TSParameterProperty";
165
+ AST_NODE_TYPES2["TSPrivateKeyword"] = "TSPrivateKeyword";
166
+ AST_NODE_TYPES2["TSPropertySignature"] = "TSPropertySignature";
167
+ AST_NODE_TYPES2["TSProtectedKeyword"] = "TSProtectedKeyword";
168
+ AST_NODE_TYPES2["TSPublicKeyword"] = "TSPublicKeyword";
169
+ AST_NODE_TYPES2["TSQualifiedName"] = "TSQualifiedName";
170
+ AST_NODE_TYPES2["TSReadonlyKeyword"] = "TSReadonlyKeyword";
171
+ AST_NODE_TYPES2["TSRestType"] = "TSRestType";
172
+ AST_NODE_TYPES2["TSSatisfiesExpression"] = "TSSatisfiesExpression";
173
+ AST_NODE_TYPES2["TSStaticKeyword"] = "TSStaticKeyword";
174
+ AST_NODE_TYPES2["TSStringKeyword"] = "TSStringKeyword";
175
+ AST_NODE_TYPES2["TSSymbolKeyword"] = "TSSymbolKeyword";
176
+ AST_NODE_TYPES2["TSTemplateLiteralType"] = "TSTemplateLiteralType";
177
+ AST_NODE_TYPES2["TSThisType"] = "TSThisType";
178
+ AST_NODE_TYPES2["TSTupleType"] = "TSTupleType";
179
+ AST_NODE_TYPES2["TSTypeAliasDeclaration"] = "TSTypeAliasDeclaration";
180
+ AST_NODE_TYPES2["TSTypeAnnotation"] = "TSTypeAnnotation";
181
+ AST_NODE_TYPES2["TSTypeAssertion"] = "TSTypeAssertion";
182
+ AST_NODE_TYPES2["TSTypeLiteral"] = "TSTypeLiteral";
183
+ AST_NODE_TYPES2["TSTypeOperator"] = "TSTypeOperator";
184
+ AST_NODE_TYPES2["TSTypeParameter"] = "TSTypeParameter";
185
+ AST_NODE_TYPES2["TSTypeParameterDeclaration"] = "TSTypeParameterDeclaration";
186
+ AST_NODE_TYPES2["TSTypeParameterInstantiation"] = "TSTypeParameterInstantiation";
187
+ AST_NODE_TYPES2["TSTypePredicate"] = "TSTypePredicate";
188
+ AST_NODE_TYPES2["TSTypeQuery"] = "TSTypeQuery";
189
+ AST_NODE_TYPES2["TSTypeReference"] = "TSTypeReference";
190
+ AST_NODE_TYPES2["TSUndefinedKeyword"] = "TSUndefinedKeyword";
191
+ AST_NODE_TYPES2["TSUnionType"] = "TSUnionType";
192
+ AST_NODE_TYPES2["TSUnknownKeyword"] = "TSUnknownKeyword";
193
+ AST_NODE_TYPES2["TSVoidKeyword"] = "TSVoidKeyword";
194
+ })(AST_NODE_TYPES || (exports.AST_NODE_TYPES = AST_NODE_TYPES = {}));
195
+ var AST_TOKEN_TYPES;
196
+ (function(AST_TOKEN_TYPES2) {
197
+ AST_TOKEN_TYPES2["Boolean"] = "Boolean";
198
+ AST_TOKEN_TYPES2["Identifier"] = "Identifier";
199
+ AST_TOKEN_TYPES2["JSXIdentifier"] = "JSXIdentifier";
200
+ AST_TOKEN_TYPES2["PrivateIdentifier"] = "PrivateIdentifier";
201
+ AST_TOKEN_TYPES2["JSXText"] = "JSXText";
202
+ AST_TOKEN_TYPES2["Keyword"] = "Keyword";
203
+ AST_TOKEN_TYPES2["Null"] = "Null";
204
+ AST_TOKEN_TYPES2["Numeric"] = "Numeric";
205
+ AST_TOKEN_TYPES2["Punctuator"] = "Punctuator";
206
+ AST_TOKEN_TYPES2["RegularExpression"] = "RegularExpression";
207
+ AST_TOKEN_TYPES2["String"] = "String";
208
+ AST_TOKEN_TYPES2["Template"] = "Template";
209
+ AST_TOKEN_TYPES2["Block"] = "Block";
210
+ AST_TOKEN_TYPES2["Line"] = "Line";
211
+ })(AST_TOKEN_TYPES || (exports.AST_TOKEN_TYPES = AST_TOKEN_TYPES = {}));
212
+ });
213
+
214
+ // node_modules/@typescript-eslint/types/dist/lib.js
215
+ var require_lib = __commonJS((exports) => {
216
+ Object.defineProperty(exports, "__esModule", { value: true });
217
+ });
218
+
219
+ // node_modules/@typescript-eslint/types/dist/parser-options.js
220
+ var require_parser_options = __commonJS((exports) => {
221
+ Object.defineProperty(exports, "__esModule", { value: true });
222
+ });
223
+
224
+ // node_modules/@typescript-eslint/types/dist/ts-estree.js
225
+ var require_ts_estree = __commonJS((exports) => {
226
+ var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
227
+ if (k2 === undefined)
228
+ k2 = k;
229
+ var desc = Object.getOwnPropertyDescriptor(m, k);
230
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
231
+ desc = { enumerable: true, get: function() {
232
+ return m[k];
233
+ } };
234
+ }
235
+ Object.defineProperty(o, k2, desc);
236
+ } : function(o, m, k, k2) {
237
+ if (k2 === undefined)
238
+ k2 = k;
239
+ o[k2] = m[k];
240
+ });
241
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
242
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
243
+ } : function(o, v) {
244
+ o["default"] = v;
245
+ });
246
+ var __importStar = exports && exports.__importStar || function() {
247
+ var ownKeys = function(o) {
248
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
249
+ var ar = [];
250
+ for (var k in o2)
251
+ if (Object.prototype.hasOwnProperty.call(o2, k))
252
+ ar[ar.length] = k;
253
+ return ar;
254
+ };
255
+ return ownKeys(o);
256
+ };
257
+ return function(mod) {
258
+ if (mod && mod.__esModule)
259
+ return mod;
260
+ var result = {};
261
+ if (mod != null) {
262
+ for (var k = ownKeys(mod), i = 0;i < k.length; i++)
263
+ if (k[i] !== "default")
264
+ __createBinding(result, mod, k[i]);
265
+ }
266
+ __setModuleDefault(result, mod);
267
+ return result;
268
+ };
269
+ }();
270
+ Object.defineProperty(exports, "__esModule", { value: true });
271
+ exports.TSESTree = undefined;
272
+ exports.TSESTree = __importStar(require_ast_spec());
273
+ });
274
+
275
+ // node_modules/@typescript-eslint/types/dist/index.js
276
+ var require_dist = __commonJS((exports) => {
277
+ var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
278
+ if (k2 === undefined)
279
+ k2 = k;
280
+ var desc = Object.getOwnPropertyDescriptor(m, k);
281
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
282
+ desc = { enumerable: true, get: function() {
283
+ return m[k];
284
+ } };
285
+ }
286
+ Object.defineProperty(o, k2, desc);
287
+ } : function(o, m, k, k2) {
288
+ if (k2 === undefined)
289
+ k2 = k;
290
+ o[k2] = m[k];
291
+ });
292
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
293
+ for (var p in m)
294
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
295
+ __createBinding(exports2, m, p);
296
+ };
297
+ Object.defineProperty(exports, "__esModule", { value: true });
298
+ exports.AST_TOKEN_TYPES = exports.AST_NODE_TYPES = undefined;
299
+ var ast_spec_1 = require_ast_spec();
300
+ Object.defineProperty(exports, "AST_NODE_TYPES", { enumerable: true, get: function() {
301
+ return ast_spec_1.AST_NODE_TYPES;
302
+ } });
303
+ Object.defineProperty(exports, "AST_TOKEN_TYPES", { enumerable: true, get: function() {
304
+ return ast_spec_1.AST_TOKEN_TYPES;
305
+ } });
306
+ __exportStar(require_lib(), exports);
307
+ __exportStar(require_parser_options(), exports);
308
+ __exportStar(require_ts_estree(), exports);
309
+ });
310
+
311
+ // src/rules/enforce-ianitor-check-type.ts
312
+ var DEFAULT_CONFIG = {
313
+ baseThreshold: 10,
314
+ errorThreshold: 25,
315
+ interfacePenalty: 20,
316
+ performanceMode: true,
317
+ warnThreshold: 15
318
+ };
319
+ function hasTypeAnnotation(node) {
320
+ if (node.type === "VariableDeclarator" && node.id && typeof node.id === "object" && "typeAnnotation" in node.id)
321
+ return !!node.id.typeAnnotation;
322
+ if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression")
323
+ return !!node.returnType;
324
+ return false;
325
+ }
326
+ function getTypeName(node) {
327
+ return node.type === "TSInterfaceDeclaration" || node.type === "TSTypeAliasDeclaration" ? node.id.name : undefined;
328
+ }
329
+ function isIanitorValidator(node) {
330
+ return node.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.type === "Identifier" && node.callee.object.name === "Ianitor";
331
+ }
332
+ function hasIanitorStaticType(typeAnnotation) {
333
+ let currentType = typeAnnotation;
334
+ if (currentType.type === "TSTypeReference" && currentType.typeName.type === "Identifier" && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0])
335
+ currentType = currentType.typeArguments.params[0];
336
+ if (currentType.type !== "TSTypeReference")
337
+ return false;
338
+ const { typeName, typeArguments } = currentType;
339
+ const firstParam = typeArguments?.params[0];
340
+ return typeName.type === "TSQualifiedName" && typeName.left.type === "Identifier" && typeName.left.name === "Ianitor" && typeName.right.type === "Identifier" && typeName.right.name === "Static" && firstParam?.type === "TSTypeQuery";
341
+ }
342
+ function calculateIanitorComplexity(node) {
343
+ const callee = node.callee;
344
+ if (callee?.type !== "MemberExpression" || callee.property?.type !== "Identifier")
345
+ return 0;
346
+ const method = callee.property.name;
347
+ switch (method) {
348
+ case "interface":
349
+ case "strictInterface": {
350
+ const properties = node.arguments?.[0];
351
+ return properties?.type === "ObjectExpression" ? 10 + (properties.properties?.length || 0) * 3 : 0;
352
+ }
353
+ case "optional":
354
+ case "array":
355
+ case "instanceIsA":
356
+ case "instanceOf":
357
+ return 2;
358
+ case "record":
359
+ case "map":
360
+ return 3;
361
+ case "union":
362
+ case "intersection":
363
+ return (node.arguments?.length || 0) * 2;
364
+ case "string":
365
+ case "number":
366
+ case "boolean":
367
+ return 1;
368
+ default:
369
+ return 1;
370
+ }
371
+ }
372
+ var enforceIanitorCheckType = {
373
+ create(context) {
374
+ const config = { ...DEFAULT_CONFIG, ...context.options[0] };
375
+ const cache = {
376
+ nodeCache: new WeakMap,
377
+ visitedNodes: new WeakSet
378
+ };
379
+ const ianitorStaticVariables = new Set;
380
+ const depthMultiplierCache = new Map;
381
+ const complexityCeiling = config.errorThreshold * 2;
382
+ function getDepthMultiplier(depth) {
383
+ const cached = depthMultiplierCache.get(depth);
384
+ if (cached !== undefined)
385
+ return cached;
386
+ const computed = Math.log2(depth + 1);
387
+ depthMultiplierCache.set(depth, computed);
388
+ return computed;
389
+ }
390
+ function addScore(current, addition) {
391
+ const nextScore = current + addition;
392
+ if (!config.performanceMode)
393
+ return nextScore;
394
+ return nextScore > complexityCeiling ? complexityCeiling : nextScore;
395
+ }
396
+ function extractIanitorStaticVariable(typeAnnotation) {
397
+ let currentType = typeAnnotation;
398
+ if (currentType.type === "TSTypeReference" && currentType.typeName.type === "Identifier" && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0])
399
+ currentType = currentType.typeArguments.params[0];
400
+ if (currentType.type !== "TSTypeReference")
401
+ return null;
402
+ const { typeName, typeArguments } = currentType;
403
+ const firstParam = typeArguments?.params[0];
404
+ if (typeName.type === "TSQualifiedName" && typeName.left.type === "Identifier" && typeName.left.name === "Ianitor" && typeName.right.type === "Identifier" && typeName.right.name === "Static" && firstParam?.type === "TSTypeQuery" && firstParam.exprName.type === "Identifier")
405
+ return firstParam.exprName.name;
406
+ return null;
407
+ }
408
+ function calculateStructuralComplexity(node, depth = 0) {
409
+ const cached = cache.nodeCache.get(node);
410
+ if (cached !== undefined)
411
+ return cached;
412
+ if (cache.visitedNodes.has(node))
413
+ return 50;
414
+ cache.visitedNodes.add(node);
415
+ let score = 0;
416
+ const nextDepth = depth + 1;
417
+ switch (node.type) {
418
+ case "TSStringKeyword":
419
+ case "TSNumberKeyword":
420
+ case "TSBooleanKeyword":
421
+ case "TSNullKeyword":
422
+ case "TSUndefinedKeyword":
423
+ case "TSVoidKeyword":
424
+ case "TSSymbolKeyword":
425
+ case "TSBigIntKeyword":
426
+ score = 1;
427
+ break;
428
+ case "TSNeverKeyword":
429
+ case "TSUnknownKeyword":
430
+ case "TSAnyKeyword":
431
+ score = 0;
432
+ break;
433
+ case "TSInterfaceDeclaration": {
434
+ const iface = node;
435
+ score = config.interfacePenalty;
436
+ const extendsLength = iface.extends?.length;
437
+ if (extendsLength)
438
+ score = addScore(score, extendsLength * 5);
439
+ const { body } = iface.body;
440
+ score = addScore(score, body.length * 2);
441
+ for (const member of body) {
442
+ const typeAnnotation = "typeAnnotation" in member ? member.typeAnnotation : undefined;
443
+ if (typeAnnotation)
444
+ score = addScore(score, calculateStructuralComplexity(typeAnnotation.typeAnnotation, nextDepth));
445
+ }
446
+ break;
447
+ }
448
+ case "TSTypeLiteral": {
449
+ const { members } = node;
450
+ score = 2 + members.length * 0.5;
451
+ for (const member of members) {
452
+ const typeAnnotation = "typeAnnotation" in member ? member.typeAnnotation : undefined;
453
+ if (typeAnnotation)
454
+ score = addScore(score, calculateStructuralComplexity(typeAnnotation.typeAnnotation, nextDepth));
455
+ }
456
+ break;
457
+ }
458
+ case "TSUnionType": {
459
+ const { types } = node;
460
+ for (const type of types)
461
+ score = addScore(score, calculateStructuralComplexity(type, nextDepth));
462
+ score = addScore(score, 2 * (types.length - 1));
463
+ break;
464
+ }
465
+ case "TSIntersectionType": {
466
+ const { types } = node;
467
+ for (const type of types)
468
+ score = addScore(score, calculateStructuralComplexity(type, nextDepth));
469
+ score = addScore(score, 3 * types.length);
470
+ break;
471
+ }
472
+ case "TSArrayType":
473
+ score = addScore(calculateStructuralComplexity(node.elementType, nextDepth), 1);
474
+ break;
475
+ case "TSTupleType": {
476
+ const { elementTypes } = node;
477
+ score = 1;
478
+ for (const element of elementTypes) {
479
+ const elementType = element.type;
480
+ if (elementType !== "TSRestType" && elementType !== "TSOptionalType")
481
+ score = addScore(score, calculateStructuralComplexity(element, nextDepth));
482
+ }
483
+ score = addScore(score, 1.5 * elementTypes.length);
484
+ break;
485
+ }
486
+ case "TSTypeReference": {
487
+ score = 2;
488
+ const { typeArguments } = node;
489
+ if (typeArguments) {
490
+ for (const param of typeArguments.params)
491
+ score = addScore(score, calculateStructuralComplexity(param, nextDepth) + 2);
492
+ }
493
+ break;
494
+ }
495
+ case "TSConditionalType": {
496
+ score = 3;
497
+ score = addScore(score, calculateStructuralComplexity(node.checkType, nextDepth));
498
+ score = addScore(score, calculateStructuralComplexity(node.extendsType, nextDepth));
499
+ score = addScore(score, calculateStructuralComplexity(node.trueType, nextDepth));
500
+ score = addScore(score, calculateStructuralComplexity(node.falseType, nextDepth));
501
+ break;
502
+ }
503
+ case "TSMappedType": {
504
+ score = 5;
505
+ if (node.constraint)
506
+ score = addScore(score, calculateStructuralComplexity(node.constraint, nextDepth));
507
+ if (node.typeAnnotation)
508
+ score = addScore(score, calculateStructuralComplexity(node.typeAnnotation, nextDepth));
509
+ break;
510
+ }
511
+ case "TSFunctionType":
512
+ case "TSMethodSignature": {
513
+ const func = node;
514
+ score = 2;
515
+ for (const param of func.params) {
516
+ const typeAnnotation = "typeAnnotation" in param ? param.typeAnnotation : undefined;
517
+ if (typeAnnotation)
518
+ score = addScore(score, calculateStructuralComplexity(typeAnnotation.typeAnnotation, nextDepth));
519
+ }
520
+ if (func.returnType)
521
+ score = addScore(score, calculateStructuralComplexity(func.returnType.typeAnnotation, nextDepth));
522
+ break;
523
+ }
524
+ default:
525
+ score = 1;
526
+ }
527
+ score *= getDepthMultiplier(depth);
528
+ cache.nodeCache.set(node, score);
529
+ cache.visitedNodes.delete(node);
530
+ return score;
531
+ }
532
+ const variableDeclaratorsToCheck = new Map;
533
+ return {
534
+ "Program:exit"() {
535
+ for (const [nodeKey, data] of variableDeclaratorsToCheck.entries()) {
536
+ const node = nodeKey;
537
+ if (node.id.type === "Identifier" && ianitorStaticVariables.has(node.id.name))
538
+ continue;
539
+ context.report({
540
+ data: { score: data.complexity.toFixed(1) },
541
+ messageId: "missingIanitorCheckType",
542
+ node: node.id
543
+ });
544
+ }
545
+ },
546
+ TSInterfaceDeclaration(node) {
547
+ const complexity = calculateStructuralComplexity(node);
548
+ const name = getTypeName(node);
549
+ if (complexity >= config.interfacePenalty) {
550
+ context.report({
551
+ data: { name: name || "unknown" },
552
+ messageId: "complexInterfaceNeedsCheck",
553
+ node
554
+ });
555
+ }
556
+ },
557
+ TSTypeAliasDeclaration(node) {
558
+ const varName = extractIanitorStaticVariable(node.typeAnnotation);
559
+ if (varName)
560
+ ianitorStaticVariables.add(varName);
561
+ if (hasIanitorStaticType(node.typeAnnotation))
562
+ return;
563
+ const complexity = calculateStructuralComplexity(node.typeAnnotation);
564
+ if (complexity < config.baseThreshold)
565
+ return;
566
+ context.report({
567
+ data: { score: complexity.toFixed(1) },
568
+ messageId: "missingIanitorCheckType",
569
+ node
570
+ });
571
+ },
572
+ VariableDeclarator(node) {
573
+ if (!node.init || node.init.type !== "CallExpression")
574
+ return;
575
+ if (!isIanitorValidator(node.init))
576
+ return;
577
+ if (hasTypeAnnotation(node))
578
+ return;
579
+ const complexity = calculateIanitorComplexity(node.init);
580
+ if (complexity < config.baseThreshold)
581
+ return;
582
+ variableDeclaratorsToCheck.set(node, { complexity });
583
+ }
584
+ };
585
+ },
586
+ meta: {
587
+ docs: {
588
+ description: "Enforce Ianitor.Check<T> type annotations on complex TypeScript types",
589
+ recommended: false
590
+ },
591
+ fixable: undefined,
592
+ messages: {
593
+ complexInterfaceNeedsCheck: "Interface '{{name}}' requires Ianitor.Check<T> annotation (interfaces always need explicit checking)",
594
+ missingIanitorCheckType: "Complex type (score: {{score}}) requires Ianitor.Check<T> annotation for type safety"
595
+ },
596
+ schema: [
597
+ {
598
+ additionalProperties: false,
599
+ properties: {
600
+ baseThreshold: { minimum: 1, type: "number" },
601
+ errorThreshold: { minimum: 1, type: "number" },
602
+ interfacePenalty: { minimum: 1, type: "number" },
603
+ performanceMode: { type: "boolean" },
604
+ warnThreshold: { minimum: 1, type: "number" }
605
+ },
606
+ type: "object"
607
+ }
608
+ ],
609
+ type: "problem"
610
+ }
611
+ };
612
+ var enforce_ianitor_check_type_default = enforceIanitorCheckType;
613
+
614
+ // src/rules/no-color3-constructor.ts
615
+ function isUnknownRecord(value) {
616
+ return typeof value === "object" && value !== null;
617
+ }
618
+ function isNumericLiteralNode(value) {
619
+ return isUnknownRecord(value) && value.type === "Literal" && "value" in value && typeof value.value === "number";
620
+ }
621
+ function mapComponentToRgbRange(value) {
622
+ return Math.round(value > 1 ? value : value * 255);
623
+ }
624
+ function collectNumericComponents(parameters) {
625
+ const components = new Array;
626
+ let allZero = true;
627
+ for (const parameter of parameters) {
628
+ if (!isNumericLiteralNode(parameter))
629
+ return;
630
+ const mapped = mapComponentToRgbRange(parameter.value);
631
+ components.push(mapped);
632
+ if (mapped !== 0)
633
+ allZero = false;
634
+ }
635
+ return { allZero, components };
636
+ }
637
+ var noColor3Constructor = {
638
+ create(context) {
639
+ return {
640
+ NewExpression(node) {
641
+ if (node.callee.type !== "Identifier" || node.callee.name !== "Color3")
642
+ return;
643
+ const parameters = node.arguments;
644
+ if (parameters.length === 0)
645
+ return;
646
+ const collected = collectNumericComponents(parameters);
647
+ if (!collected) {
648
+ context.report({
649
+ messageId: parameters.length < 3 ? "useFromRGB" : "onlyZeroArgs",
650
+ node
651
+ });
652
+ return;
653
+ }
654
+ if (parameters.length < 3) {
655
+ const [red, green = 0] = collected.components;
656
+ context.report({
657
+ fix: (fixer) => fixer.replaceText(node, `Color3.fromRGB(${red}, ${green}, 0)`),
658
+ messageId: "useFromRGB",
659
+ node
660
+ });
661
+ return;
662
+ }
663
+ if (!collected.allZero) {
664
+ context.report({
665
+ fix: (fixer) => fixer.replaceText(node, `Color3.fromRGB(${collected.components.join(", ")})`),
666
+ messageId: "onlyZeroArgs",
667
+ node
668
+ });
669
+ }
670
+ }
671
+ };
672
+ },
673
+ meta: {
674
+ docs: {
675
+ description: "Ban new Color3(...) except new Color3() or new Color3(0, 0, 0). Use Color3.fromRGB() instead.",
676
+ recommended: true
677
+ },
678
+ fixable: "code",
679
+ messages: {
680
+ onlyZeroArgs: "Use Color3.fromRGB() instead of new Color3(). new Color3() uses floats [0-1] and performs worse than Color3.fromRGB() which uses [0-255]. Only 'new Color3()' or 'new Color3(0, 0, 0)' are allowed.",
681
+ useFromRGB: "Use Color3.fromRGB() instead of new Color3(). new Color3() uses floats [0-1] and performs worse than Color3.fromRGB() which uses [0-255]."
682
+ },
683
+ schema: [],
684
+ type: "problem"
685
+ }
686
+ };
687
+ var no_color3_constructor_default = noColor3Constructor;
688
+
689
+ // src/rules/no-print.ts
690
+ var noPrint = {
691
+ create(context) {
692
+ return {
693
+ 'CallExpression[callee.type="Identifier"][callee.name="print"]'(node) {
694
+ context.report({
695
+ messageId: "useLog",
696
+ node
697
+ });
698
+ }
699
+ };
700
+ },
701
+ meta: {
702
+ docs: {
703
+ description: "Ban print() function calls. Use Log instead.",
704
+ recommended: false
705
+ },
706
+ messages: {
707
+ useLog: "Use Log instead of print()"
708
+ },
709
+ schema: [],
710
+ type: "problem"
711
+ }
712
+ };
713
+ var no_print_default = noPrint;
714
+
715
+ // src/rules/no-shorthand-names.ts
716
+ var DEFAULT_OPTIONS = {
717
+ allowPropertyAccess: ["char"],
718
+ shorthands: {
719
+ args: "parameters",
720
+ char: "character",
721
+ dt: "deltaTime",
722
+ plr: "player"
723
+ }
724
+ };
725
+ function isUnknownRecord2(value) {
726
+ return typeof value === "object" && value !== null;
727
+ }
728
+ function isStringRecord(value) {
729
+ return isUnknownRecord2(value) && Object.values(value).every((v) => typeof v === "string");
730
+ }
731
+ function isStringArray(value) {
732
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string");
733
+ }
734
+ function escapeRegex(str) {
735
+ return str.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&");
736
+ }
737
+ function isRuleOptions(value) {
738
+ if (!isUnknownRecord2(value))
739
+ return false;
740
+ return (!("shorthands" in value) || isStringRecord(value.shorthands)) && (!("allowPropertyAccess" in value) || isStringArray(value.allowPropertyAccess));
741
+ }
742
+ function normalizeOptions(rawOptions) {
743
+ const mergedShorthands = { ...DEFAULT_OPTIONS.shorthands };
744
+ if (rawOptions?.shorthands)
745
+ for (const [key, value] of Object.entries(rawOptions.shorthands))
746
+ mergedShorthands[key] = value;
747
+ const shorthandsMap = new Map(Object.entries(mergedShorthands));
748
+ const allowPropertyAccessSource = rawOptions?.allowPropertyAccess ?? DEFAULT_OPTIONS.allowPropertyAccess;
749
+ const escapedKeys = Array.from(shorthandsMap.keys()).map((key) => escapeRegex(key));
750
+ const selector = `Identifier[name=/^(${escapedKeys.join("|")})$/]`;
751
+ return {
752
+ allowPropertyAccess: new Set(allowPropertyAccessSource),
753
+ selector,
754
+ shorthands: shorthandsMap
755
+ };
756
+ }
757
+ var noShorthandNames = {
758
+ create(context) {
759
+ const validatedOptions = isRuleOptions(context.options[0]) ? context.options[0] : undefined;
760
+ const normalized = normalizeOptions(validatedOptions);
761
+ const { shorthands, allowPropertyAccess, selector } = normalized;
762
+ return {
763
+ [selector](node) {
764
+ const shorthandName = node.name;
765
+ const replacement = shorthands.get(shorthandName);
766
+ if (!replacement)
767
+ return;
768
+ const parent = node.parent;
769
+ if (allowPropertyAccess.has(shorthandName) && parent && isUnknownRecord2(parent) && parent.type === "MemberExpression" && parent.property === node)
770
+ return;
771
+ if (shorthandName === "plr" && parent?.type === "VariableDeclarator" && parent.id === node) {
772
+ const init = parent.init;
773
+ if (init && isUnknownRecord2(init) && init.type === "MemberExpression" && init.object && isUnknownRecord2(init.object) && init.object.type === "Identifier" && init.object.name === "Players" && init.property && isUnknownRecord2(init.property) && init.property.type === "Identifier" && init.property.name === "LocalPlayer") {
774
+ context.report({
775
+ data: { replacement: "localPlayer", shorthand: shorthandName },
776
+ messageId: "useReplacement",
777
+ node
778
+ });
779
+ return;
780
+ }
781
+ }
782
+ context.report({
783
+ data: { replacement, shorthand: shorthandName },
784
+ messageId: "useReplacement",
785
+ node
786
+ });
787
+ }
788
+ };
789
+ },
790
+ meta: {
791
+ docs: {
792
+ description: "Ban shorthand variable names. Use descriptive full names instead.",
793
+ recommended: true
794
+ },
795
+ messages: {
796
+ useReplacement: "Use '{{replacement}}' instead of '{{shorthand}}' shorthand"
797
+ },
798
+ schema: [
799
+ {
800
+ additionalProperties: false,
801
+ properties: {
802
+ allowPropertyAccess: {
803
+ description: "Shorthand names that are allowed as property access",
804
+ items: { type: "string" },
805
+ type: "array"
806
+ },
807
+ shorthands: {
808
+ additionalProperties: { type: "string" },
809
+ description: "Map of shorthand names to their full replacements",
810
+ type: "object"
811
+ }
812
+ },
813
+ type: "object"
814
+ }
815
+ ],
816
+ type: "suggestion"
817
+ }
818
+ };
819
+ var no_shorthand_names_default = noShorthandNames;
820
+
821
+ // src/rules/no-warn.ts
822
+ var noWarn = {
823
+ create(context) {
824
+ return {
825
+ 'CallExpression[callee.type="Identifier"][callee.name="warn"]'(node) {
826
+ context.report({
827
+ messageId: "useLog",
828
+ node
829
+ });
830
+ }
831
+ };
832
+ },
833
+ meta: {
834
+ docs: {
835
+ description: "Ban warn() function calls. Use Log instead.",
836
+ recommended: false
837
+ },
838
+ messages: {
839
+ useLog: "Use Log instead of warn()"
840
+ },
841
+ schema: [],
842
+ type: "problem"
843
+ }
844
+ };
845
+ var no_warn_default = noWarn;
846
+
847
+ // src/rules/require-react-component-keys.ts
848
+ var DEFAULT_OPTIONS2 = {
849
+ allowRootKeys: false,
850
+ ignoreCallExpressions: ["ReactTree.mount", "CreateReactStory"]
851
+ };
852
+ var WRAPPER_PARENT_TYPES = new Set([
853
+ "ParenthesizedExpression",
854
+ "TSAsExpression",
855
+ "TSSatisfiesExpression",
856
+ "TSTypeAssertion",
857
+ "TSNonNullExpression",
858
+ "TSInstantiationExpression",
859
+ "ChainExpression"
860
+ ]);
861
+ var ARGUMENT_WRAPPER_TYPES = new Set([
862
+ ...WRAPPER_PARENT_TYPES,
863
+ "AwaitExpression",
864
+ "ConditionalExpression",
865
+ "LogicalExpression",
866
+ "SequenceExpression",
867
+ "SpreadElement"
868
+ ]);
869
+ function ascendPastWrappers(node) {
870
+ let current = node;
871
+ while (current && WRAPPER_PARENT_TYPES.has(current.type))
872
+ current = current.parent;
873
+ return current;
874
+ }
875
+ function hasKeyAttribute(node) {
876
+ for (const attr of node.openingElement.attributes) {
877
+ if (attr.type === "JSXAttribute" && attr.name.name === "key")
878
+ return true;
879
+ }
880
+ return false;
881
+ }
882
+ function isReactComponentHOC(callExpr) {
883
+ const { callee } = callExpr;
884
+ if (callee.type === "Identifier") {
885
+ return callee.name === "forwardRef" || callee.name === "memo";
886
+ }
887
+ if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "React" && callee.property.type === "Identifier") {
888
+ return callee.property.name === "forwardRef" || callee.property.name === "memo";
889
+ }
890
+ return false;
891
+ }
892
+ function isInConditionalJSXChild(node) {
893
+ let parent = node.parent;
894
+ if (!parent)
895
+ return false;
896
+ const hasConditional = parent.type === "ConditionalExpression" || parent.type === "LogicalExpression";
897
+ if (!hasConditional)
898
+ return false;
899
+ while (parent && (parent.type === "ConditionalExpression" || parent.type === "LogicalExpression")) {
900
+ parent = parent.parent;
901
+ }
902
+ if (!parent)
903
+ return false;
904
+ if (parent.type === "JSXExpressionContainer") {
905
+ const jsxExprContainer = parent;
906
+ const containerParent = jsxExprContainer.parent;
907
+ if (!containerParent)
908
+ return false;
909
+ if (containerParent.type === "JSXElement" || containerParent.type === "JSXFragment") {
910
+ const children = containerParent.children;
911
+ const significantChildren = children.filter((child) => {
912
+ if (child.type === "JSXText") {
913
+ return child.value.trim().length > 0;
914
+ }
915
+ return true;
916
+ });
917
+ if (significantChildren.length > 1) {
918
+ return false;
919
+ }
920
+ return true;
921
+ }
922
+ return false;
923
+ }
924
+ return false;
925
+ }
926
+ function getEnclosingFunctionLike(node) {
927
+ let current = node.parent;
928
+ while (current) {
929
+ if (current.type === "ArrowFunctionExpression" || current.type === "FunctionExpression" || current.type === "FunctionDeclaration") {
930
+ return current;
931
+ }
932
+ current = current.parent;
933
+ }
934
+ return;
935
+ }
936
+ function findEnclosingCallExpression(node) {
937
+ let current = node;
938
+ let parent = node.parent;
939
+ while (parent) {
940
+ if (parent.type === "CallExpression") {
941
+ for (const argument of parent.arguments) {
942
+ if (argument === current)
943
+ return parent;
944
+ if (argument.type === "SpreadElement" && argument.argument === current)
945
+ return parent;
946
+ }
947
+ return;
948
+ }
949
+ if (ARGUMENT_WRAPPER_TYPES.has(parent.type)) {
950
+ current = parent;
951
+ parent = parent.parent;
952
+ continue;
953
+ }
954
+ break;
955
+ }
956
+ return;
957
+ }
958
+ function getVariableForFunction(context, fn) {
959
+ if (fn.type === "FunctionDeclaration") {
960
+ const declared = context.sourceCode.getDeclaredVariables(fn);
961
+ if (declared.length > 0)
962
+ return declared[0];
963
+ return;
964
+ }
965
+ const parent = fn.parent;
966
+ if (!parent)
967
+ return;
968
+ if (parent.type === "VariableDeclarator" || parent.type === "AssignmentExpression") {
969
+ const declared = context.sourceCode.getDeclaredVariables(parent);
970
+ if (declared.length > 0)
971
+ return declared[0];
972
+ }
973
+ return;
974
+ }
975
+ function referenceActsAsCallback(reference) {
976
+ if (!reference.isRead())
977
+ return false;
978
+ const callExpression = findEnclosingCallExpression(reference.identifier);
979
+ if (!callExpression)
980
+ return false;
981
+ return !isReactComponentHOC(callExpression);
982
+ }
983
+ function isFunctionUsedAsCallback(context, fn) {
984
+ const inlineCall = findEnclosingCallExpression(fn);
985
+ if (inlineCall && !isReactComponentHOC(inlineCall)) {
986
+ return true;
987
+ }
988
+ const variable = getVariableForFunction(context, fn);
989
+ if (!variable)
990
+ return false;
991
+ for (const reference of variable.references) {
992
+ if (referenceActsAsCallback(reference))
993
+ return true;
994
+ }
995
+ return false;
996
+ }
997
+ function isTopLevelReturn(node) {
998
+ let parent = ascendPastWrappers(node.parent);
999
+ if (!parent)
1000
+ return false;
1001
+ if (parent.type === "JSXExpressionContainer")
1002
+ parent = ascendPastWrappers(parent.parent);
1003
+ if (!parent)
1004
+ return false;
1005
+ while (parent && (parent.type === "ConditionalExpression" || parent.type === "LogicalExpression")) {
1006
+ parent = ascendPastWrappers(parent.parent);
1007
+ }
1008
+ if (!parent)
1009
+ return false;
1010
+ if (parent.type === "ReturnStatement") {
1011
+ let currentNode = ascendPastWrappers(parent.parent);
1012
+ if (currentNode?.type === "BlockStatement") {
1013
+ currentNode = ascendPastWrappers(currentNode.parent);
1014
+ }
1015
+ if (!currentNode)
1016
+ return false;
1017
+ if (currentNode.type === "ArrowFunctionExpression" || currentNode.type === "FunctionExpression") {
1018
+ const functionParent = ascendPastWrappers(currentNode.parent);
1019
+ if (functionParent?.type === "CallExpression") {
1020
+ return isReactComponentHOC(functionParent);
1021
+ }
1022
+ return true;
1023
+ }
1024
+ return currentNode.type === "FunctionDeclaration";
1025
+ }
1026
+ if (parent.type === "ArrowFunctionExpression") {
1027
+ const functionParent = ascendPastWrappers(parent.parent);
1028
+ if (functionParent?.type === "CallExpression") {
1029
+ return isReactComponentHOC(functionParent);
1030
+ }
1031
+ return true;
1032
+ }
1033
+ return false;
1034
+ }
1035
+ function isIgnoredCallExpression(node, ignoreList) {
1036
+ let parent = node.parent;
1037
+ if (!parent)
1038
+ return false;
1039
+ if (parent.type === "JSXExpressionContainer") {
1040
+ parent = parent.parent;
1041
+ if (!parent)
1042
+ return false;
1043
+ }
1044
+ const maxDepth = 20;
1045
+ for (let depth = 0;depth < maxDepth && parent; depth++) {
1046
+ const { type } = parent;
1047
+ if (type === "CallExpression") {
1048
+ const { callee } = parent;
1049
+ if (callee.type === "Identifier")
1050
+ return ignoreList.includes(callee.name);
1051
+ if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.property.type === "Identifier")
1052
+ return ignoreList.includes(`${callee.object.name}.${callee.property.name}`);
1053
+ return false;
1054
+ }
1055
+ parent = parent.parent;
1056
+ }
1057
+ return false;
1058
+ }
1059
+ function isJSXPropValue(node) {
1060
+ let parent = node.parent;
1061
+ if (!parent)
1062
+ return false;
1063
+ while (parent && (parent.type === "ConditionalExpression" || parent.type === "LogicalExpression"))
1064
+ parent = parent.parent;
1065
+ if (!parent)
1066
+ return false;
1067
+ if (parent.type === "JSXExpressionContainer") {
1068
+ parent = parent.parent;
1069
+ if (!parent)
1070
+ return false;
1071
+ }
1072
+ return parent.type === "JSXAttribute";
1073
+ }
1074
+ var docs = {
1075
+ description: "Enforce key props on all React elements except top-level returns",
1076
+ recommended: true
1077
+ };
1078
+ var requireReactComponentKeys = {
1079
+ create(context) {
1080
+ const options = {
1081
+ ...DEFAULT_OPTIONS2,
1082
+ ...context.options[0]
1083
+ };
1084
+ function checkElement(node) {
1085
+ const functionLike = getEnclosingFunctionLike(node);
1086
+ const isCallback = functionLike ? isFunctionUsedAsCallback(context, functionLike) : false;
1087
+ const isRoot = isTopLevelReturn(node);
1088
+ if (isRoot && !isCallback) {
1089
+ if (!options.allowRootKeys && node.type === "JSXElement" && hasKeyAttribute(node)) {
1090
+ context.report({
1091
+ messageId: "rootComponentWithKey",
1092
+ node
1093
+ });
1094
+ }
1095
+ return;
1096
+ }
1097
+ if (isIgnoredCallExpression(node, options.ignoreCallExpressions))
1098
+ return;
1099
+ if (isJSXPropValue(node))
1100
+ return;
1101
+ if (isInConditionalJSXChild(node))
1102
+ return;
1103
+ if (node.type === "JSXFragment") {
1104
+ context.report({
1105
+ messageId: "missingKey",
1106
+ node
1107
+ });
1108
+ return;
1109
+ }
1110
+ if (!hasKeyAttribute(node)) {
1111
+ context.report({
1112
+ messageId: "missingKey",
1113
+ node
1114
+ });
1115
+ }
1116
+ }
1117
+ return {
1118
+ JSXElement(node) {
1119
+ checkElement(node);
1120
+ },
1121
+ JSXFragment(node) {
1122
+ checkElement(node);
1123
+ }
1124
+ };
1125
+ },
1126
+ defaultOptions: [DEFAULT_OPTIONS2],
1127
+ meta: {
1128
+ docs,
1129
+ messages: {
1130
+ missingKey: "All React elements except top-level returns require a key prop",
1131
+ rootComponentWithKey: "Root component returns should not have key props"
1132
+ },
1133
+ schema: [
1134
+ {
1135
+ additionalProperties: false,
1136
+ properties: {
1137
+ allowRootKeys: {
1138
+ default: false,
1139
+ description: "Allow key props on root component returns",
1140
+ type: "boolean"
1141
+ },
1142
+ ignoreCallExpressions: {
1143
+ default: ["ReactTree.mount"],
1144
+ description: "Function calls where JSX arguments don't need keys",
1145
+ items: { type: "string" },
1146
+ type: "array"
1147
+ }
1148
+ },
1149
+ type: "object"
1150
+ }
1151
+ ],
1152
+ type: "problem"
1153
+ }
1154
+ };
1155
+ var require_react_component_keys_default = requireReactComponentKeys;
1156
+
1157
+ // src/rules/use-exhaustive-dependencies.ts
1158
+ var import_types = __toESM(require_dist(), 1);
1159
+
1160
+ // node_modules/sury/src/Sury.res.mjs
1161
+ function valFromOption(x) {
1162
+ if (x === null || x.BS_PRIVATE_NESTED_SOME_NONE === undefined) {
1163
+ return x;
1164
+ }
1165
+ let depth = x.BS_PRIVATE_NESTED_SOME_NONE;
1166
+ if (depth === 0) {
1167
+ return;
1168
+ } else {
1169
+ return {
1170
+ BS_PRIVATE_NESTED_SOME_NONE: depth - 1 | 0
1171
+ };
1172
+ }
1173
+ }
1174
+ var idMap = {};
1175
+ function create(str) {
1176
+ let v = idMap[str];
1177
+ if (v !== undefined) {
1178
+ let id = v + 1 | 0;
1179
+ idMap[str] = id;
1180
+ return str + ("/" + id);
1181
+ }
1182
+ idMap[str] = 1;
1183
+ return str;
1184
+ }
1185
+ var immutableEmpty$1 = [];
1186
+ function capitalize(string) {
1187
+ return string.slice(0, 1).toUpperCase() + string.slice(1);
1188
+ }
1189
+ var copy = (d) => ({ ...d });
1190
+ function fromString(string) {
1191
+ let _idx = 0;
1192
+ while (true) {
1193
+ let idx = _idx;
1194
+ let match = string[idx];
1195
+ if (match === undefined) {
1196
+ return '"' + string + '"';
1197
+ }
1198
+ switch (match) {
1199
+ case '"':
1200
+ case `
1201
+ `:
1202
+ return JSON.stringify(string);
1203
+ default:
1204
+ _idx = idx + 1 | 0;
1205
+ continue;
1206
+ }
1207
+ }
1208
+ }
1209
+ function toArray(path) {
1210
+ if (path === "") {
1211
+ return [];
1212
+ } else {
1213
+ return JSON.parse(path.split('"]["').join('","'));
1214
+ }
1215
+ }
1216
+ var vendor = "sury";
1217
+ var s = Symbol(vendor);
1218
+ var itemSymbol = Symbol(vendor + ":item");
1219
+ var $$Error = /* @__PURE__ */ create("Sury.Error");
1220
+ var constField = "const";
1221
+ function has(acc, flag) {
1222
+ return (acc & flag) !== 0;
1223
+ }
1224
+ var flags = {
1225
+ unknown: 1,
1226
+ string: 2,
1227
+ number: 4,
1228
+ boolean: 8,
1229
+ undefined: 16,
1230
+ null: 32,
1231
+ object: 64,
1232
+ array: 128,
1233
+ union: 256,
1234
+ ref: 512,
1235
+ bigint: 1024,
1236
+ nan: 2048,
1237
+ function: 4096,
1238
+ instance: 8192,
1239
+ never: 16384,
1240
+ symbol: 32768
1241
+ };
1242
+ function stringify(unknown) {
1243
+ let tagFlag = flags[typeof unknown];
1244
+ if (tagFlag & 16) {
1245
+ return "undefined";
1246
+ }
1247
+ if (!(tagFlag & 64)) {
1248
+ if (tagFlag & 2) {
1249
+ return '"' + unknown + '"';
1250
+ } else if (tagFlag & 1024) {
1251
+ return unknown + "n";
1252
+ } else {
1253
+ return unknown.toString();
1254
+ }
1255
+ }
1256
+ if (unknown === null) {
1257
+ return "null";
1258
+ }
1259
+ if (Array.isArray(unknown)) {
1260
+ let string = "[";
1261
+ for (let i = 0, i_finish = unknown.length;i < i_finish; ++i) {
1262
+ if (i !== 0) {
1263
+ string = string + ", ";
1264
+ }
1265
+ string = string + stringify(unknown[i]);
1266
+ }
1267
+ return string + "]";
1268
+ }
1269
+ if (unknown.constructor !== Object) {
1270
+ return Object.prototype.toString.call(unknown);
1271
+ }
1272
+ let keys = Object.keys(unknown);
1273
+ let string$1 = "{ ";
1274
+ for (let i$1 = 0, i_finish$1 = keys.length;i$1 < i_finish$1; ++i$1) {
1275
+ let key = keys[i$1];
1276
+ let value = unknown[key];
1277
+ string$1 = string$1 + key + ": " + stringify(value) + "; ";
1278
+ }
1279
+ return string$1 + "}";
1280
+ }
1281
+ function toExpression(schema) {
1282
+ let tag = schema.type;
1283
+ let $$const = schema.const;
1284
+ let name = schema.name;
1285
+ if (name !== undefined) {
1286
+ return name;
1287
+ }
1288
+ if ($$const !== undefined) {
1289
+ return stringify($$const);
1290
+ }
1291
+ let format = schema.format;
1292
+ let anyOf = schema.anyOf;
1293
+ if (anyOf !== undefined) {
1294
+ return anyOf.map(toExpression).join(" | ");
1295
+ }
1296
+ if (format !== undefined) {
1297
+ return format;
1298
+ }
1299
+ switch (tag) {
1300
+ case "nan":
1301
+ return "NaN";
1302
+ case "object":
1303
+ let additionalItems = schema.additionalItems;
1304
+ let properties = schema.properties;
1305
+ let locations = Object.keys(properties);
1306
+ if (locations.length === 0) {
1307
+ if (typeof additionalItems === "object") {
1308
+ return "{ [key: string]: " + toExpression(additionalItems) + "; }";
1309
+ } else {
1310
+ return "{}";
1311
+ }
1312
+ } else {
1313
+ return "{ " + locations.map((location) => location + ": " + toExpression(properties[location]) + ";").join(" ") + " }";
1314
+ }
1315
+ default:
1316
+ if (schema.b) {
1317
+ return tag;
1318
+ }
1319
+ switch (tag) {
1320
+ case "instance":
1321
+ return schema.class.name;
1322
+ case "array":
1323
+ let additionalItems$1 = schema.additionalItems;
1324
+ let items = schema.items;
1325
+ if (typeof additionalItems$1 !== "object") {
1326
+ return "[" + items.map((item) => toExpression(item.schema)).join(", ") + "]";
1327
+ }
1328
+ let itemName = toExpression(additionalItems$1);
1329
+ return (additionalItems$1.type === "union" ? "(" + itemName + ")" : itemName) + "[]";
1330
+ default:
1331
+ return tag;
1332
+ }
1333
+ }
1334
+ }
1335
+
1336
+ class SuryError extends Error {
1337
+ constructor(code, flag, path) {
1338
+ super();
1339
+ this.flag = flag;
1340
+ this.code = code;
1341
+ this.path = path;
1342
+ }
1343
+ }
1344
+ var d = Object.defineProperty;
1345
+ var p = SuryError.prototype;
1346
+ d(p, "message", {
1347
+ get() {
1348
+ return message(this);
1349
+ }
1350
+ });
1351
+ d(p, "reason", {
1352
+ get() {
1353
+ return reason(this);
1354
+ }
1355
+ });
1356
+ d(p, "name", { value: "SuryError" });
1357
+ d(p, "s", { value: s });
1358
+ d(p, "_1", {
1359
+ get() {
1360
+ return this;
1361
+ }
1362
+ });
1363
+ d(p, "RE_EXN_ID", {
1364
+ value: $$Error
1365
+ });
1366
+ var Schema = function(type) {
1367
+ this.type = type;
1368
+ };
1369
+ var sp = Object.create(null);
1370
+ d(sp, "with", {
1371
+ get() {
1372
+ return (fn, ...args) => fn(this, ...args);
1373
+ }
1374
+ });
1375
+ Schema.prototype = sp;
1376
+ function getOrRethrow(exn) {
1377
+ if (exn && exn.s === s) {
1378
+ return exn;
1379
+ }
1380
+ throw exn;
1381
+ }
1382
+ function reason(error, nestedLevelOpt) {
1383
+ let nestedLevel = nestedLevelOpt !== undefined ? nestedLevelOpt : 0;
1384
+ let reason$1 = error.code;
1385
+ if (typeof reason$1 !== "object") {
1386
+ return "Encountered unexpected async transform or refine. Use parseAsyncOrThrow operation instead";
1387
+ }
1388
+ switch (reason$1.TAG) {
1389
+ case "OperationFailed":
1390
+ return reason$1._0;
1391
+ case "InvalidOperation":
1392
+ return reason$1.description;
1393
+ case "InvalidType":
1394
+ let unionErrors = reason$1.unionErrors;
1395
+ let m = "Expected " + toExpression(reason$1.expected) + ", received " + stringify(reason$1.received);
1396
+ if (unionErrors !== undefined) {
1397
+ let lineBreak = `
1398
+ ` + " ".repeat(nestedLevel << 1);
1399
+ let reasonsDict = {};
1400
+ for (let idx = 0, idx_finish = unionErrors.length;idx < idx_finish; ++idx) {
1401
+ let error$1 = unionErrors[idx];
1402
+ let reason$2 = reason(error$1, nestedLevel + 1);
1403
+ let nonEmptyPath = error$1.path;
1404
+ let location = nonEmptyPath === "" ? "" : "At " + nonEmptyPath + ": ";
1405
+ let line = "- " + location + reason$2;
1406
+ if (!reasonsDict[line]) {
1407
+ reasonsDict[line] = 1;
1408
+ m = m + lineBreak + line;
1409
+ }
1410
+ }
1411
+ }
1412
+ return m;
1413
+ case "UnsupportedTransformation":
1414
+ return "Unsupported transformation from " + toExpression(reason$1.from) + " to " + toExpression(reason$1.to);
1415
+ case "ExcessField":
1416
+ return 'Unrecognized key "' + reason$1._0 + '"';
1417
+ case "InvalidJsonSchema":
1418
+ return toExpression(reason$1._0) + " is not valid JSON";
1419
+ }
1420
+ }
1421
+ function message(error) {
1422
+ let op = error.flag;
1423
+ let text = "Failed ";
1424
+ if (op & 2) {
1425
+ text = text + "async ";
1426
+ }
1427
+ text = text + (op & 1 ? op & 4 ? "asserting" : "parsing" : "converting");
1428
+ if (op & 8) {
1429
+ text = text + " to JSON" + (op & 16 ? " string" : "");
1430
+ }
1431
+ let nonEmptyPath = error.path;
1432
+ let tmp = nonEmptyPath === "" ? "" : " at " + nonEmptyPath;
1433
+ return text + tmp + ": " + reason(error, undefined);
1434
+ }
1435
+ var globalConfig = {
1436
+ m: message,
1437
+ d: undefined,
1438
+ a: "strip",
1439
+ n: false
1440
+ };
1441
+ var shakenRef = "as";
1442
+ var shakenTraps = {
1443
+ get: (target, prop) => {
1444
+ let l = target[shakenRef];
1445
+ if (l === undefined) {
1446
+ return target[prop];
1447
+ }
1448
+ if (prop === shakenRef) {
1449
+ return target[prop];
1450
+ }
1451
+ let l$1 = valFromOption(l);
1452
+ let message2 = "Schema S." + l$1 + " is not enabled. To start using it, add S.enable" + capitalize(l$1) + "() at the project root.";
1453
+ throw new Error("[Sury] " + message2);
1454
+ }
1455
+ };
1456
+ function shaken(apiName) {
1457
+ let mut = new Schema("never");
1458
+ mut[shakenRef] = apiName;
1459
+ return new Proxy(mut, shakenTraps);
1460
+ }
1461
+ var unknown = new Schema("unknown");
1462
+ var bool = new Schema("boolean");
1463
+ var symbol = new Schema("symbol");
1464
+ var string = new Schema("string");
1465
+ var int = new Schema("number");
1466
+ int.format = "int32";
1467
+ var float = new Schema("number");
1468
+ var bigint = new Schema("bigint");
1469
+ var unit = new Schema("undefined");
1470
+ unit.const = undefined;
1471
+ var copyWithoutCache = (schema) => {
1472
+ let c = new Schema(schema.type);
1473
+ for (let k in schema) {
1474
+ if (k > "a" || k === "$ref" || k === "$defs") {
1475
+ c[k] = schema[k];
1476
+ }
1477
+ }
1478
+ return c;
1479
+ };
1480
+ function updateOutput(schema, fn) {
1481
+ let root = copyWithoutCache(schema);
1482
+ let mut = root;
1483
+ while (mut.to) {
1484
+ let next = copyWithoutCache(mut.to);
1485
+ mut.to = next;
1486
+ mut = next;
1487
+ }
1488
+ fn(mut);
1489
+ return root;
1490
+ }
1491
+ var value = SuryError;
1492
+ function constructor(prim0, prim1, prim2) {
1493
+ return new SuryError(prim0, prim1, prim2);
1494
+ }
1495
+ var ErrorClass = {
1496
+ value,
1497
+ constructor
1498
+ };
1499
+ function embed(b, value2) {
1500
+ let e = b.g.e;
1501
+ let l = e.length;
1502
+ e[l] = value2;
1503
+ return "e[" + l + "]";
1504
+ }
1505
+ function inlineConst(b, schema) {
1506
+ let tagFlag = flags[schema.type];
1507
+ let $$const = schema.const;
1508
+ if (tagFlag & 16) {
1509
+ return "void 0";
1510
+ } else if (tagFlag & 2) {
1511
+ return fromString($$const);
1512
+ } else if (tagFlag & 1024) {
1513
+ return $$const + "n";
1514
+ } else if (tagFlag & 45056) {
1515
+ return embed(b, schema.const);
1516
+ } else {
1517
+ return $$const;
1518
+ }
1519
+ }
1520
+ function inlineLocation(b, location) {
1521
+ let key = '"' + location + '"';
1522
+ let i = b.g[key];
1523
+ if (i !== undefined) {
1524
+ return i;
1525
+ }
1526
+ let inlinedLocation = fromString(location);
1527
+ b.g[key] = inlinedLocation;
1528
+ return inlinedLocation;
1529
+ }
1530
+ function secondAllocate(v) {
1531
+ let b = this;
1532
+ b.l = b.l + "," + v;
1533
+ }
1534
+ function initialAllocate(v) {
1535
+ let b = this;
1536
+ b.l = v;
1537
+ b.a = secondAllocate;
1538
+ }
1539
+ function rootScope(flag, defs) {
1540
+ let global = {
1541
+ c: "",
1542
+ l: "",
1543
+ a: initialAllocate,
1544
+ v: -1,
1545
+ o: flag,
1546
+ f: "",
1547
+ e: [],
1548
+ d: defs
1549
+ };
1550
+ global.g = global;
1551
+ return global;
1552
+ }
1553
+ function allocateScope(b) {
1554
+ delete b.a;
1555
+ let varsAllocation = b.l;
1556
+ if (varsAllocation === "") {
1557
+ return b.f + b.c;
1558
+ } else {
1559
+ return b.f + "let " + varsAllocation + ";" + b.c;
1560
+ }
1561
+ }
1562
+ function varWithoutAllocation(global) {
1563
+ let newCounter = global.v + 1;
1564
+ global.v = newCounter;
1565
+ return "v" + newCounter;
1566
+ }
1567
+ function _var(_b) {
1568
+ return this.i;
1569
+ }
1570
+ function _notVar(b) {
1571
+ let val = this;
1572
+ let v = varWithoutAllocation(b.g);
1573
+ let i = val.i;
1574
+ if (i === "") {
1575
+ val.b.a(v);
1576
+ } else if (b.a !== undefined) {
1577
+ b.a(v + "=" + i);
1578
+ } else {
1579
+ b.c = b.c + (v + "=" + i + ";");
1580
+ b.g.a(v);
1581
+ }
1582
+ val.v = _var;
1583
+ val.i = v;
1584
+ return v;
1585
+ }
1586
+ function allocateVal(b, schema) {
1587
+ let v = varWithoutAllocation(b.g);
1588
+ b.a(v);
1589
+ return {
1590
+ b,
1591
+ v: _var,
1592
+ i: v,
1593
+ f: 0,
1594
+ type: schema.type
1595
+ };
1596
+ }
1597
+ function val(b, initial, schema) {
1598
+ return {
1599
+ b,
1600
+ v: _notVar,
1601
+ i: initial,
1602
+ f: 0,
1603
+ type: schema.type
1604
+ };
1605
+ }
1606
+ function constVal(b, schema) {
1607
+ return {
1608
+ b,
1609
+ v: _notVar,
1610
+ i: inlineConst(b, schema),
1611
+ f: 0,
1612
+ type: schema.type,
1613
+ const: schema.const
1614
+ };
1615
+ }
1616
+ function asyncVal(b, initial) {
1617
+ return {
1618
+ b,
1619
+ v: _notVar,
1620
+ i: initial,
1621
+ f: 2,
1622
+ type: "unknown"
1623
+ };
1624
+ }
1625
+ function addKey(b, input, key, val2) {
1626
+ return input.v(b) + "[" + key + "]=" + val2.i;
1627
+ }
1628
+ function set(b, input, val2) {
1629
+ if (input === val2) {
1630
+ return "";
1631
+ }
1632
+ let inputVar = input.v(b);
1633
+ let match = input.f & 2;
1634
+ let match$1 = val2.f & 2;
1635
+ if (match) {
1636
+ if (!match$1) {
1637
+ return inputVar + "=Promise.resolve(" + val2.i + ")";
1638
+ }
1639
+ } else if (match$1) {
1640
+ input.f = input.f | 2;
1641
+ return inputVar + "=" + val2.i;
1642
+ }
1643
+ return inputVar + "=" + val2.i;
1644
+ }
1645
+ function setInlined(b, input, inlined) {
1646
+ return input.v(b) + "=" + inlined;
1647
+ }
1648
+ function map(inlinedFn, input) {
1649
+ return {
1650
+ b: input.b,
1651
+ v: _notVar,
1652
+ i: inlinedFn + "(" + input.i + ")",
1653
+ f: 0,
1654
+ type: "unknown"
1655
+ };
1656
+ }
1657
+ function $$throw(b, code, path) {
1658
+ throw new SuryError(code, b.g.o, path);
1659
+ }
1660
+ function failWithArg(b, path, fn, arg) {
1661
+ return embed(b, (arg2) => $$throw(b, fn(arg2), path)) + "(" + arg + ")";
1662
+ }
1663
+ function withPathPrepend(b, input, path, maybeDynamicLocationVar, appendSafe, fn) {
1664
+ if (path === "" && maybeDynamicLocationVar === undefined) {
1665
+ return fn(b, input, path);
1666
+ }
1667
+ try {
1668
+ let $$catch = (b2, errorVar2) => {
1669
+ b2.c = errorVar2 + ".path=" + fromString(path) + "+" + (maybeDynamicLocationVar !== undefined ? `'["'+` + maybeDynamicLocationVar + `+'"]'+` : "") + errorVar2 + ".path";
1670
+ };
1671
+ let fn$1 = (b2) => fn(b2, input, "");
1672
+ let prevCode = b.c;
1673
+ b.c = "";
1674
+ let errorVar = varWithoutAllocation(b.g);
1675
+ let maybeResolveVal = $$catch(b, errorVar);
1676
+ let catchCode = "if(" + (errorVar + "&&" + errorVar + ".s===s") + "){" + b.c;
1677
+ b.c = "";
1678
+ let bb = {
1679
+ c: "",
1680
+ l: "",
1681
+ a: initialAllocate,
1682
+ f: "",
1683
+ g: b.g
1684
+ };
1685
+ let fnOutput = fn$1(bb);
1686
+ b.c = b.c + allocateScope(bb);
1687
+ let isNoop = fnOutput.i === input.i && b.c === "";
1688
+ if (appendSafe !== undefined) {
1689
+ appendSafe(b, fnOutput);
1690
+ }
1691
+ if (isNoop) {
1692
+ return fnOutput;
1693
+ }
1694
+ let isAsync = fnOutput.f & 2;
1695
+ let output = input === fnOutput ? input : appendSafe !== undefined ? fnOutput : {
1696
+ b,
1697
+ v: _notVar,
1698
+ i: "",
1699
+ f: isAsync ? 2 : 0,
1700
+ type: "unknown"
1701
+ };
1702
+ let catchCode$1 = maybeResolveVal !== undefined ? (catchLocation) => catchCode + (catchLocation === 1 ? "return " + maybeResolveVal.i : set(b, output, maybeResolveVal)) + ("}else{throw " + errorVar + "}") : (param) => catchCode + "}throw " + errorVar;
1703
+ b.c = prevCode + ("try{" + b.c + (isAsync ? setInlined(b, output, fnOutput.i + ".catch(" + errorVar + "=>{" + catchCode$1(1) + "})") : set(b, output, fnOutput)) + "}catch(" + errorVar + "){" + catchCode$1(0) + "}");
1704
+ return output;
1705
+ } catch (exn) {
1706
+ let error = getOrRethrow(exn);
1707
+ throw new SuryError(error.code, error.flag, path + "[]" + error.path);
1708
+ }
1709
+ }
1710
+ function validation(b, inputVar, schema, negative) {
1711
+ let eq = negative ? "!==" : "===";
1712
+ let and_ = negative ? "||" : "&&";
1713
+ let exp = negative ? "!" : "";
1714
+ let tag = schema.type;
1715
+ let tagFlag = flags[tag];
1716
+ if (tagFlag & 2048) {
1717
+ return exp + ("Number.isNaN(" + inputVar + ")");
1718
+ }
1719
+ if (constField in schema) {
1720
+ return inputVar + eq + inlineConst(b, schema);
1721
+ }
1722
+ if (tagFlag & 4) {
1723
+ return "typeof " + inputVar + eq + '"' + tag + '"';
1724
+ }
1725
+ if (tagFlag & 64) {
1726
+ return "typeof " + inputVar + eq + '"' + tag + '"' + and_ + exp + inputVar;
1727
+ }
1728
+ if (tagFlag & 128) {
1729
+ return exp + "Array.isArray(" + inputVar + ")";
1730
+ }
1731
+ if (!(tagFlag & 8192)) {
1732
+ return "typeof " + inputVar + eq + '"' + tag + '"';
1733
+ }
1734
+ let c = inputVar + " instanceof " + embed(b, schema.class);
1735
+ if (negative) {
1736
+ return "!(" + c + ")";
1737
+ } else {
1738
+ return c;
1739
+ }
1740
+ }
1741
+ function refinement(b, inputVar, schema, negative) {
1742
+ let eq = negative ? "!==" : "===";
1743
+ let and_ = negative ? "||" : "&&";
1744
+ let not_ = negative ? "" : "!";
1745
+ let lt = negative ? ">" : "<";
1746
+ let gt = negative ? "<" : ">";
1747
+ let match = schema.type;
1748
+ let tag;
1749
+ let exit = 0;
1750
+ let match$1 = schema.const;
1751
+ if (match$1 !== undefined) {
1752
+ return "";
1753
+ }
1754
+ let match$2 = schema.format;
1755
+ if (match$2 !== undefined) {
1756
+ switch (match$2) {
1757
+ case "int32":
1758
+ return and_ + inputVar + lt + "2147483647" + and_ + inputVar + gt + "-2147483648" + and_ + inputVar + "%1" + eq + "0";
1759
+ case "port":
1760
+ case "json":
1761
+ exit = 2;
1762
+ break;
1763
+ }
1764
+ } else {
1765
+ exit = 2;
1766
+ }
1767
+ if (exit === 2) {
1768
+ switch (match) {
1769
+ case "number":
1770
+ if (globalConfig.n) {
1771
+ return "";
1772
+ } else {
1773
+ return and_ + not_ + "Number.isNaN(" + inputVar + ")";
1774
+ }
1775
+ case "array":
1776
+ case "object":
1777
+ tag = match;
1778
+ break;
1779
+ default:
1780
+ return "";
1781
+ }
1782
+ }
1783
+ let additionalItems = schema.additionalItems;
1784
+ let items = schema.items;
1785
+ let length = items.length;
1786
+ let code = tag === "array" ? additionalItems === "strip" || additionalItems === "strict" ? additionalItems === "strip" ? and_ + inputVar + ".length" + gt + length : and_ + inputVar + ".length" + eq + length : "" : additionalItems === "strip" ? "" : and_ + not_ + "Array.isArray(" + inputVar + ")";
1787
+ for (let idx = 0, idx_finish = items.length;idx < idx_finish; ++idx) {
1788
+ let match$3 = items[idx];
1789
+ let location = match$3.location;
1790
+ let item = match$3.schema;
1791
+ let itemCode;
1792
+ if (constField in item || schema.unnest) {
1793
+ let inlinedLocation = inlineLocation(b, location);
1794
+ itemCode = validation(b, inputVar + ("[" + inlinedLocation + "]"), item, negative);
1795
+ } else if (item.items) {
1796
+ let inlinedLocation$1 = inlineLocation(b, location);
1797
+ let inputVar$1 = inputVar + ("[" + inlinedLocation$1 + "]");
1798
+ itemCode = validation(b, inputVar$1, item, negative) + refinement(b, inputVar$1, item, negative);
1799
+ } else {
1800
+ itemCode = "";
1801
+ }
1802
+ if (itemCode !== "") {
1803
+ code = code + and_ + itemCode;
1804
+ }
1805
+ }
1806
+ return code;
1807
+ }
1808
+ function makeRefinedOf(b, input, schema) {
1809
+ let mut = {
1810
+ b,
1811
+ v: input.v,
1812
+ i: input.i,
1813
+ f: input.f,
1814
+ type: schema.type
1815
+ };
1816
+ let loop = (mut2, schema2) => {
1817
+ if (constField in schema2) {
1818
+ mut2.const = schema2.const;
1819
+ }
1820
+ let items = schema2.items;
1821
+ if (items === undefined) {
1822
+ return;
1823
+ }
1824
+ let properties = {};
1825
+ items.forEach((item) => {
1826
+ let schema3 = item.schema;
1827
+ let isConst = constField in schema3;
1828
+ if (!(isConst || schema3.items)) {
1829
+ return;
1830
+ }
1831
+ let tmp;
1832
+ if (isConst) {
1833
+ tmp = inlineConst(b, schema3);
1834
+ } else {
1835
+ let inlinedLocation = inlineLocation(b, item.location);
1836
+ tmp = mut2.v(b) + ("[" + inlinedLocation + "]");
1837
+ }
1838
+ let mut$1 = {
1839
+ b: mut2.b,
1840
+ v: _notVar,
1841
+ i: tmp,
1842
+ f: 0,
1843
+ type: schema3.type
1844
+ };
1845
+ loop(mut$1, schema3);
1846
+ properties[item.location] = mut$1;
1847
+ });
1848
+ mut2.properties = properties;
1849
+ mut2.additionalItems = unknown;
1850
+ };
1851
+ loop(mut, schema);
1852
+ return mut;
1853
+ }
1854
+ function typeFilterCode(b, schema, input, path) {
1855
+ if (schema.noValidation || flags[schema.type] & 17153) {
1856
+ return "";
1857
+ }
1858
+ let inputVar = input.v(b);
1859
+ return "if(" + validation(b, inputVar, schema, true) + refinement(b, inputVar, schema, true) + "){" + failWithArg(b, path, (input2) => ({
1860
+ TAG: "InvalidType",
1861
+ expected: schema,
1862
+ received: input2
1863
+ }), inputVar) + "}";
1864
+ }
1865
+ function unsupportedTransform(b, from, target, path) {
1866
+ return $$throw(b, {
1867
+ TAG: "UnsupportedTransformation",
1868
+ from,
1869
+ to: target
1870
+ }, path);
1871
+ }
1872
+ function noopOperation(i) {
1873
+ return i;
1874
+ }
1875
+ function setHas(has2, tag) {
1876
+ has2[tag === "union" || tag === "ref" ? "unknown" : tag] = true;
1877
+ }
1878
+ var jsonName = "JSON";
1879
+ var jsonString = shaken("jsonString");
1880
+ function inputToString(b, input) {
1881
+ return val(b, '""+' + input.i, string);
1882
+ }
1883
+ function parse(prevB, schema, inputArg, path) {
1884
+ let b = {
1885
+ c: "",
1886
+ l: "",
1887
+ a: initialAllocate,
1888
+ f: "",
1889
+ g: prevB.g
1890
+ };
1891
+ if (schema.$defs) {
1892
+ b.g.d = schema.$defs;
1893
+ }
1894
+ let input = inputArg;
1895
+ let isFromLiteral = constField in input;
1896
+ let isSchemaLiteral = constField in schema;
1897
+ let isSameTag = input.type === schema.type;
1898
+ let schemaTagFlag = flags[schema.type];
1899
+ let inputTagFlag = flags[input.type];
1900
+ let isUnsupported = false;
1901
+ if (!(schemaTagFlag & 257 || schema.format === "json")) {
1902
+ if (schema.name === jsonName && !(inputTagFlag & 1)) {
1903
+ if (!(inputTagFlag & 14)) {
1904
+ if (inputTagFlag & 1024) {
1905
+ input = inputToString(b, input);
1906
+ } else {
1907
+ isUnsupported = true;
1908
+ }
1909
+ }
1910
+ } else if (isSchemaLiteral) {
1911
+ if (isFromLiteral) {
1912
+ if (input.const !== schema.const) {
1913
+ input = constVal(b, schema);
1914
+ }
1915
+ } else if (inputTagFlag & 2 && schemaTagFlag & 3132) {
1916
+ let inputVar = input.v(b);
1917
+ b.f = schema.noValidation ? "" : input.i + '==="' + schema.const + '"||' + failWithArg(b, path, (input2) => ({
1918
+ TAG: "InvalidType",
1919
+ expected: schema,
1920
+ received: input2
1921
+ }), inputVar) + ";";
1922
+ input = constVal(b, schema);
1923
+ } else if (schema.noValidation) {
1924
+ input = constVal(b, schema);
1925
+ } else {
1926
+ b.f = typeFilterCode(prevB, schema, input, path);
1927
+ input.type = schema.type;
1928
+ input.const = schema.const;
1929
+ }
1930
+ } else if (isFromLiteral && !isSchemaLiteral) {
1931
+ if (!isSameTag) {
1932
+ if (schemaTagFlag & 2 && inputTagFlag & 3132) {
1933
+ let $$const = "" + input.const;
1934
+ input = {
1935
+ b,
1936
+ v: _notVar,
1937
+ i: '"' + $$const + '"',
1938
+ f: 0,
1939
+ type: "string",
1940
+ const: $$const
1941
+ };
1942
+ } else {
1943
+ isUnsupported = true;
1944
+ }
1945
+ }
1946
+ } else if (inputTagFlag & 1) {
1947
+ let ref = schema.$ref;
1948
+ if (ref !== undefined) {
1949
+ let defs = b.g.d;
1950
+ let identifier = ref.slice(8);
1951
+ let def = defs[identifier];
1952
+ let flag = schema.noValidation ? (b.g.o | 1) ^ 1 : b.g.o;
1953
+ let fn = def[flag];
1954
+ let recOperation;
1955
+ if (fn !== undefined) {
1956
+ let fn$1 = valFromOption(fn);
1957
+ recOperation = fn$1 === 0 ? embed(b, def) + ("[" + flag + "]") : embed(b, fn$1);
1958
+ } else {
1959
+ def[flag] = 0;
1960
+ let fn$2 = internalCompile(def, flag, b.g.d);
1961
+ def[flag] = fn$2;
1962
+ recOperation = embed(b, fn$2);
1963
+ }
1964
+ input = withPathPrepend(b, input, path, undefined, undefined, (param, input2, param$1) => {
1965
+ let output = map(recOperation, input2);
1966
+ if (def.isAsync === undefined) {
1967
+ let defsMut = copy(defs);
1968
+ defsMut[identifier] = unknown;
1969
+ isAsyncInternal(def, defsMut);
1970
+ }
1971
+ if (def.isAsync) {
1972
+ output.f = output.f | 2;
1973
+ }
1974
+ return output;
1975
+ });
1976
+ input.v(b);
1977
+ } else {
1978
+ if (b.g.o & 1) {
1979
+ b.f = typeFilterCode(prevB, schema, input, path);
1980
+ }
1981
+ let refined = makeRefinedOf(b, input, schema);
1982
+ input.type = refined.type;
1983
+ input.i = refined.i;
1984
+ input.v = refined.v;
1985
+ input.additionalItems = refined.additionalItems;
1986
+ input.properties = refined.properties;
1987
+ if (constField in refined) {
1988
+ input.const = refined.const;
1989
+ }
1990
+ }
1991
+ } else if (schemaTagFlag & 2 && inputTagFlag & 1036) {
1992
+ input = inputToString(b, input);
1993
+ } else if (!isSameTag) {
1994
+ if (inputTagFlag & 2) {
1995
+ let inputVar$1 = input.v(b);
1996
+ if (schemaTagFlag & 8) {
1997
+ let output = allocateVal(b, schema);
1998
+ b.c = b.c + ("(" + output.i + "=" + inputVar$1 + '==="true")||' + inputVar$1 + '==="false"||' + failWithArg(b, path, (input2) => ({
1999
+ TAG: "InvalidType",
2000
+ expected: schema,
2001
+ received: input2
2002
+ }), inputVar$1) + ";");
2003
+ input = output;
2004
+ } else if (schemaTagFlag & 4) {
2005
+ let output$1 = val(b, "+" + inputVar$1, schema);
2006
+ let outputVar = output$1.v(b);
2007
+ let match = schema.format;
2008
+ b.c = b.c + (match !== undefined ? "(" + refinement(b, outputVar, schema, true).slice(2) + ")" : "Number.isNaN(" + outputVar + ")") + ("&&" + failWithArg(b, path, (input2) => ({
2009
+ TAG: "InvalidType",
2010
+ expected: schema,
2011
+ received: input2
2012
+ }), inputVar$1) + ";");
2013
+ input = output$1;
2014
+ } else if (schemaTagFlag & 1024) {
2015
+ let output$2 = allocateVal(b, schema);
2016
+ b.c = b.c + ("try{" + output$2.i + "=BigInt(" + inputVar$1 + ")}catch(_){" + failWithArg(b, path, (input2) => ({
2017
+ TAG: "InvalidType",
2018
+ expected: schema,
2019
+ received: input2
2020
+ }), inputVar$1) + "}");
2021
+ input = output$2;
2022
+ } else {
2023
+ isUnsupported = true;
2024
+ }
2025
+ } else if (inputTagFlag & 4 && schemaTagFlag & 1024) {
2026
+ input = val(b, "BigInt(" + input.i + ")", schema);
2027
+ } else {
2028
+ isUnsupported = true;
2029
+ }
2030
+ }
2031
+ }
2032
+ if (isUnsupported) {
2033
+ unsupportedTransform(b, input, schema, path);
2034
+ }
2035
+ let compiler = schema.compiler;
2036
+ if (compiler !== undefined) {
2037
+ input = compiler(b, input, schema, path);
2038
+ }
2039
+ if (input.t !== true) {
2040
+ let refiner = schema.refiner;
2041
+ if (refiner !== undefined) {
2042
+ b.c = b.c + refiner(b, input.v(b), schema, path);
2043
+ }
2044
+ }
2045
+ let to = schema.to;
2046
+ if (to !== undefined) {
2047
+ let parser = schema.parser;
2048
+ if (parser !== undefined) {
2049
+ input = parser(b, input, schema, path);
2050
+ }
2051
+ if (input.t !== true) {
2052
+ input = parse(b, to, input, path);
2053
+ }
2054
+ }
2055
+ prevB.c = prevB.c + allocateScope(b);
2056
+ return input;
2057
+ }
2058
+ function jsonableValidation(output, parent, path, flag) {
2059
+ let tagFlag = flags[output.type];
2060
+ if (tagFlag & 48129 || tagFlag & 16 && parent.type !== "object") {
2061
+ throw new SuryError({
2062
+ TAG: "InvalidJsonSchema",
2063
+ _0: parent
2064
+ }, flag, path);
2065
+ }
2066
+ if (tagFlag & 256) {
2067
+ output.anyOf.forEach((s2) => jsonableValidation(s2, parent, path, flag));
2068
+ return;
2069
+ }
2070
+ if (!(tagFlag & 192)) {
2071
+ return;
2072
+ }
2073
+ let additionalItems = output.additionalItems;
2074
+ if (additionalItems === "strip" || additionalItems === "strict")
2075
+ ;
2076
+ else {
2077
+ jsonableValidation(additionalItems, parent, path, flag);
2078
+ }
2079
+ let p2 = output.properties;
2080
+ if (p2 !== undefined) {
2081
+ let keys = Object.keys(p2);
2082
+ for (let idx = 0, idx_finish = keys.length;idx < idx_finish; ++idx) {
2083
+ let key = keys[idx];
2084
+ jsonableValidation(p2[key], parent, path, flag);
2085
+ }
2086
+ return;
2087
+ }
2088
+ output.items.forEach((item) => jsonableValidation(item.schema, output, path + ("[" + fromString(item.location) + "]"), flag));
2089
+ }
2090
+ function reverse(schema) {
2091
+ let reversedHead;
2092
+ let current = schema;
2093
+ while (current) {
2094
+ let mut = copyWithoutCache(current);
2095
+ let next = mut.to;
2096
+ let to = reversedHead;
2097
+ if (to !== undefined) {
2098
+ mut.to = to;
2099
+ } else {
2100
+ delete mut.to;
2101
+ }
2102
+ let parser = mut.parser;
2103
+ let serializer = mut.serializer;
2104
+ if (serializer !== undefined) {
2105
+ mut.parser = serializer;
2106
+ } else {
2107
+ delete mut.parser;
2108
+ }
2109
+ if (parser !== undefined) {
2110
+ mut.serializer = parser;
2111
+ } else {
2112
+ delete mut.serializer;
2113
+ }
2114
+ let fromDefault = mut.fromDefault;
2115
+ let $$default = mut.default;
2116
+ if ($$default !== undefined) {
2117
+ mut.fromDefault = $$default;
2118
+ } else {
2119
+ delete mut.fromDefault;
2120
+ }
2121
+ if (fromDefault !== undefined) {
2122
+ mut.default = fromDefault;
2123
+ } else {
2124
+ delete mut.default;
2125
+ }
2126
+ let items = mut.items;
2127
+ if (items !== undefined) {
2128
+ let properties = {};
2129
+ let newItems = new Array(items.length);
2130
+ for (let idx = 0, idx_finish = items.length;idx < idx_finish; ++idx) {
2131
+ let item = items[idx];
2132
+ let reversed_schema = reverse(item.schema);
2133
+ let reversed_location = item.location;
2134
+ let reversed = {
2135
+ schema: reversed_schema,
2136
+ location: reversed_location
2137
+ };
2138
+ if (item.r) {
2139
+ reversed.r = item.r;
2140
+ }
2141
+ properties[item.location] = reversed_schema;
2142
+ newItems[idx] = reversed;
2143
+ }
2144
+ mut.items = newItems;
2145
+ let match = mut.properties;
2146
+ if (match !== undefined) {
2147
+ mut.properties = properties;
2148
+ }
2149
+ }
2150
+ if (typeof mut.additionalItems === "object") {
2151
+ mut.additionalItems = reverse(mut.additionalItems);
2152
+ }
2153
+ let anyOf = mut.anyOf;
2154
+ if (anyOf !== undefined) {
2155
+ let has2 = {};
2156
+ let newAnyOf = [];
2157
+ for (let idx$1 = 0, idx_finish$1 = anyOf.length;idx$1 < idx_finish$1; ++idx$1) {
2158
+ let s2 = anyOf[idx$1];
2159
+ let reversed$1 = reverse(s2);
2160
+ newAnyOf.push(reversed$1);
2161
+ setHas(has2, reversed$1.type);
2162
+ }
2163
+ mut.has = has2;
2164
+ mut.anyOf = newAnyOf;
2165
+ }
2166
+ let defs = mut.$defs;
2167
+ if (defs !== undefined) {
2168
+ let reversedDefs = {};
2169
+ for (let idx$2 = 0, idx_finish$2 = Object.keys(defs).length;idx$2 < idx_finish$2; ++idx$2) {
2170
+ let key = Object.keys(defs)[idx$2];
2171
+ reversedDefs[key] = reverse(defs[key]);
2172
+ }
2173
+ mut.$defs = reversedDefs;
2174
+ }
2175
+ reversedHead = mut;
2176
+ current = next;
2177
+ }
2178
+ return reversedHead;
2179
+ }
2180
+ function internalCompile(schema, flag, defs) {
2181
+ let b = rootScope(flag, defs);
2182
+ if (flag & 8) {
2183
+ let output = reverse(schema);
2184
+ jsonableValidation(output, output, "", flag);
2185
+ }
2186
+ let input = {
2187
+ b,
2188
+ v: _var,
2189
+ i: "i",
2190
+ f: 0,
2191
+ type: "unknown"
2192
+ };
2193
+ let schema$1 = flag & 4 ? updateOutput(schema, (mut) => {
2194
+ let t = new Schema(unit.type);
2195
+ t.const = unit.const;
2196
+ t.noValidation = true;
2197
+ mut.to = t;
2198
+ }) : flag & 16 ? updateOutput(schema, (mut) => {
2199
+ mut.to = jsonString;
2200
+ }) : schema;
2201
+ let output$1 = parse(b, schema$1, input, "");
2202
+ let code = allocateScope(b);
2203
+ let isAsync = has(output$1.f, 2);
2204
+ schema$1.isAsync = isAsync;
2205
+ if (code === "" && output$1 === input && !(flag & 2)) {
2206
+ return noopOperation;
2207
+ }
2208
+ let inlinedOutput = output$1.i;
2209
+ if (flag & 2 && !isAsync && !defs) {
2210
+ inlinedOutput = "Promise.resolve(" + inlinedOutput + ")";
2211
+ }
2212
+ let inlinedFunction = "i=>{" + code + "return " + inlinedOutput + "}";
2213
+ let ctxVarValue1 = b.g.e;
2214
+ return new Function("e", "s", "return " + inlinedFunction)(ctxVarValue1, s);
2215
+ }
2216
+ function isAsyncInternal(schema, defs) {
2217
+ try {
2218
+ let b = rootScope(2, defs);
2219
+ let input = {
2220
+ b,
2221
+ v: _var,
2222
+ i: "i",
2223
+ f: 0,
2224
+ type: "unknown"
2225
+ };
2226
+ let output = parse(b, schema, input, "");
2227
+ let isAsync = has(output.f, 2);
2228
+ schema.isAsync = isAsync;
2229
+ return isAsync;
2230
+ } catch (exn) {
2231
+ getOrRethrow(exn);
2232
+ return false;
2233
+ }
2234
+ }
2235
+ function operationFn(s2, o) {
2236
+ if (o in s2) {
2237
+ return s2[o];
2238
+ }
2239
+ let f = internalCompile(o & 32 ? reverse(s2) : s2, o, 0);
2240
+ s2[o] = f;
2241
+ return f;
2242
+ }
2243
+ d(sp, "~standard", {
2244
+ get: function() {
2245
+ let schema = this;
2246
+ return {
2247
+ version: 1,
2248
+ vendor,
2249
+ validate: (input) => {
2250
+ try {
2251
+ return {
2252
+ value: operationFn(schema, 1)(input)
2253
+ };
2254
+ } catch (exn) {
2255
+ let error = getOrRethrow(exn);
2256
+ return {
2257
+ issues: [{
2258
+ message: reason(error, undefined),
2259
+ path: error.path === "" ? undefined : toArray(error.path)
2260
+ }]
2261
+ };
2262
+ }
2263
+ }
2264
+ };
2265
+ }
2266
+ });
2267
+ function parseOrThrow(any, schema) {
2268
+ return operationFn(schema, 1)(any);
2269
+ }
2270
+ var $$null = new Schema("null");
2271
+ $$null.const = null;
2272
+ function wrapExnToFailure(exn) {
2273
+ if (exn && exn.s === s) {
2274
+ return {
2275
+ success: false,
2276
+ error: exn
2277
+ };
2278
+ }
2279
+ throw exn;
2280
+ }
2281
+ function js_safe(fn) {
2282
+ try {
2283
+ return {
2284
+ success: true,
2285
+ value: fn()
2286
+ };
2287
+ } catch (exn) {
2288
+ return wrapExnToFailure(exn);
2289
+ }
2290
+ }
2291
+ var nullAsUnit = new Schema("null");
2292
+ nullAsUnit.const = null;
2293
+ nullAsUnit.to = unit;
2294
+ function neverBuilder(b, input, selfSchema, path) {
2295
+ b.c = b.c + failWithArg(b, path, (input2) => ({
2296
+ TAG: "InvalidType",
2297
+ expected: selfSchema,
2298
+ received: input2
2299
+ }), input.i) + ";";
2300
+ return input;
2301
+ }
2302
+ var never = new Schema("never");
2303
+ never.compiler = neverBuilder;
2304
+ function arrayCompiler(b, input, selfSchema, path) {
2305
+ let item = selfSchema.additionalItems;
2306
+ let inputVar = input.v(b);
2307
+ let iteratorVar = varWithoutAllocation(b.g);
2308
+ let bb = {
2309
+ c: "",
2310
+ l: "",
2311
+ a: initialAllocate,
2312
+ f: "",
2313
+ g: b.g
2314
+ };
2315
+ let itemInput = val(bb, inputVar + "[" + iteratorVar + "]", unknown);
2316
+ let itemOutput = withPathPrepend(bb, itemInput, path, iteratorVar, undefined, (b2, input2, path2) => parse(b2, item, input2, path2));
2317
+ let itemCode = allocateScope(bb);
2318
+ let isTransformed = itemInput !== itemOutput;
2319
+ let output = isTransformed ? val(b, "new Array(" + inputVar + ".length)", selfSchema) : input;
2320
+ output.type = selfSchema.type;
2321
+ output.additionalItems = selfSchema.additionalItems;
2322
+ if (isTransformed || itemCode !== "") {
2323
+ b.c = b.c + ("for(let " + iteratorVar + "=0;" + iteratorVar + "<" + inputVar + ".length;++" + iteratorVar + "){" + itemCode + (isTransformed ? addKey(b, output, iteratorVar, itemOutput) : "") + "}");
2324
+ }
2325
+ if (itemOutput.f & 2) {
2326
+ return asyncVal(output.b, "Promise.all(" + output.i + ")");
2327
+ } else {
2328
+ return output;
2329
+ }
2330
+ }
2331
+ function factory$2(item) {
2332
+ let mut = new Schema("array");
2333
+ mut.additionalItems = item;
2334
+ mut.items = immutableEmpty$1;
2335
+ mut.compiler = arrayCompiler;
2336
+ return mut;
2337
+ }
2338
+ var json = shaken("json");
2339
+ var array = factory$2;
2340
+
2341
+ // node_modules/sury/src/S.mjs
2342
+ var Error2 = ErrorClass.value;
2343
+ var string2 = string;
2344
+ var number = float;
2345
+ var array2 = array;
2346
+ var safe = js_safe;
2347
+ var parseOrThrow2 = parseOrThrow;
2348
+
2349
+ // src/rules/use-exhaustive-dependencies.ts
2350
+ var FUNCTION_DECLARATIONS = new Set([
2351
+ import_types.TSESTree.AST_NODE_TYPES.FunctionExpression,
2352
+ import_types.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression,
2353
+ import_types.TSESTree.AST_NODE_TYPES.FunctionDeclaration
2354
+ ]);
2355
+ var UNSTABLE_VALUES = new Set([
2356
+ ...FUNCTION_DECLARATIONS,
2357
+ import_types.TSESTree.AST_NODE_TYPES.ObjectExpression,
2358
+ import_types.TSESTree.AST_NODE_TYPES.ArrayExpression
2359
+ ]);
2360
+ var testingMetrics = {
2361
+ moduleLevelStableConst: 0,
2362
+ outerScopeSkip: 0
2363
+ };
2364
+ var DEFAULT_HOOKS = new Map([
2365
+ ["useEffect", { closureIndex: 0, dependenciesIndex: 1 }],
2366
+ ["useLayoutEffect", { closureIndex: 0, dependenciesIndex: 1 }],
2367
+ ["useInsertionEffect", { closureIndex: 0, dependenciesIndex: 1 }],
2368
+ ["useCallback", { closureIndex: 0, dependenciesIndex: 1 }],
2369
+ ["useMemo", { closureIndex: 0, dependenciesIndex: 1 }],
2370
+ ["useImperativeHandle", { closureIndex: 1, dependenciesIndex: 2 }],
2371
+ ["useSpring", { closureIndex: 0, dependenciesIndex: 1 }],
2372
+ ["useSprings", { closureIndex: 1, dependenciesIndex: 2 }],
2373
+ ["useTrail", { closureIndex: 1, dependenciesIndex: 2 }]
2374
+ ]);
2375
+ var STABLE_HOOKS = new Map([
2376
+ ["useState", new Set([1])],
2377
+ ["useReducer", new Set([1])],
2378
+ ["useTransition", new Set([1])],
2379
+ ["useRef", true],
2380
+ ["useBinding", true]
2381
+ ]);
2382
+ var STABLE_VALUE_TYPES = new Set(["ImportBinding", "FunctionDeclaration", "ClassDeclaration", "FunctionName"]);
2383
+ var GLOBAL_BUILTINS = new Set([
2384
+ "undefined",
2385
+ "null",
2386
+ "Infinity",
2387
+ "NaN",
2388
+ "Array",
2389
+ "Object",
2390
+ "String",
2391
+ "Number",
2392
+ "Boolean",
2393
+ "Symbol",
2394
+ "BigInt",
2395
+ "Function",
2396
+ "Map",
2397
+ "Set",
2398
+ "WeakMap",
2399
+ "WeakSet",
2400
+ "Promise",
2401
+ "Date",
2402
+ "RegExp",
2403
+ "Error",
2404
+ "Math",
2405
+ "JSON",
2406
+ "parseInt",
2407
+ "parseFloat",
2408
+ "isNaN",
2409
+ "isFinite",
2410
+ "encodeURI",
2411
+ "encodeURIComponent",
2412
+ "decodeURI",
2413
+ "decodeURIComponent",
2414
+ "ReadonlyArray",
2415
+ "ReadonlyMap",
2416
+ "ReadonlySet",
2417
+ "Partial",
2418
+ "Required",
2419
+ "Readonly",
2420
+ "Pick",
2421
+ "Omit",
2422
+ "Exclude",
2423
+ "Extract",
2424
+ "Record",
2425
+ "NonNullable",
2426
+ "ReturnType",
2427
+ "InstanceType",
2428
+ "Parameters",
2429
+ "console",
2430
+ "setTimeout",
2431
+ "setInterval",
2432
+ "clearTimeout",
2433
+ "clearInterval",
2434
+ "Element",
2435
+ "Node",
2436
+ "Document",
2437
+ "Window",
2438
+ "Event"
2439
+ ]);
2440
+ function getHookName(node) {
2441
+ const { callee } = node;
2442
+ if (callee.type === "Identifier") {
2443
+ return callee.name;
2444
+ }
2445
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
2446
+ return callee.property.name;
2447
+ }
2448
+ return;
2449
+ }
2450
+ function getMemberExpressionDepth(node) {
2451
+ let depth = 0;
2452
+ let current = node;
2453
+ while (current.type === "MemberExpression") {
2454
+ depth += 1;
2455
+ current = current.object;
2456
+ }
2457
+ return depth;
2458
+ }
2459
+ function getRootIdentifier(node) {
2460
+ let current = node;
2461
+ while (current.type === "MemberExpression")
2462
+ current = current.object;
2463
+ return current.type === "Identifier" ? current : undefined;
2464
+ }
2465
+ function nodeToDependencyString(node, sourceCode) {
2466
+ return sourceCode.getText(node);
2467
+ }
2468
+ function isStableArrayIndex(stableResult, node, identifierName) {
2469
+ if (!stableResult)
2470
+ return false;
2471
+ if (!(stableResult instanceof Set) || node.type !== "VariableDeclarator" || node.id.type !== "ArrayPattern")
2472
+ return false;
2473
+ const elements = node.id.elements;
2474
+ for (let index = 0;index < elements.length; index += 1) {
2475
+ const element = elements[index];
2476
+ if (element?.type === "Identifier" && element.name === identifierName)
2477
+ return stableResult.has(index);
2478
+ }
2479
+ return false;
2480
+ }
2481
+ function isStableHookValue(init, node, identifierName, stableHooks) {
2482
+ const initNode = init;
2483
+ if (initNode.type !== "CallExpression")
2484
+ return false;
2485
+ const hookName = getHookName(initNode);
2486
+ if (!hookName)
2487
+ return false;
2488
+ const stableResult = stableHooks.get(hookName);
2489
+ if (stableResult === true)
2490
+ return true;
2491
+ return isStableArrayIndex(stableResult, node, identifierName);
2492
+ }
2493
+ function isStableValue(variable, identifierName, stableHooks) {
2494
+ if (!variable)
2495
+ return false;
2496
+ const { defs } = variable;
2497
+ if (defs.length === 0)
2498
+ return false;
2499
+ for (const def of defs) {
2500
+ const { node, type } = def;
2501
+ if (STABLE_VALUE_TYPES.has(type))
2502
+ return true;
2503
+ if (type === "Variable" && node.type === "VariableDeclarator") {
2504
+ const parent = node.parent;
2505
+ if (!parent || parent.type !== "VariableDeclaration" || parent.kind !== "const")
2506
+ continue;
2507
+ const { init } = node;
2508
+ if (init && isStableHookValue(init, node, identifierName, stableHooks))
2509
+ return true;
2510
+ if (init?.type === "CallExpression") {
2511
+ const { callee } = init;
2512
+ if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "React" && callee.property.type === "Identifier" && callee.property.name === "joinBindings")
2513
+ return true;
2514
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && callee.property.name === "map")
2515
+ return true;
2516
+ }
2517
+ if (init) {
2518
+ if (init.type === "Literal" || init.type === "TemplateLiteral")
2519
+ return true;
2520
+ if (init.type === "UnaryExpression" && init.argument.type === "Literal")
2521
+ return true;
2522
+ }
2523
+ const varDef = variable.defs.find((d2) => d2.node === node);
2524
+ if (varDef && varDef.node.type === "VariableDeclarator") {
2525
+ const declParent = varDef.node.parent?.parent;
2526
+ if (declParent && (declParent.type === "Program" || declParent.type === "ExportNamedDeclaration")) {
2527
+ testingMetrics.moduleLevelStableConst += 1;
2528
+ return true;
2529
+ }
2530
+ }
2531
+ }
2532
+ }
2533
+ return false;
2534
+ }
2535
+ function findTopmostMemberExpression(node) {
2536
+ let current = node;
2537
+ let parent = node.parent;
2538
+ while (parent?.type === "MemberExpression" && parent.object === current) {
2539
+ current = parent;
2540
+ parent = parent.parent;
2541
+ }
2542
+ return current;
2543
+ }
2544
+ var IS_CEASE_BOUNDARY = new Set([
2545
+ import_types.TSESTree.AST_NODE_TYPES.FunctionDeclaration,
2546
+ import_types.TSESTree.AST_NODE_TYPES.FunctionExpression,
2547
+ import_types.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression,
2548
+ import_types.TSESTree.AST_NODE_TYPES.VariableDeclarator
2549
+ ]);
2550
+ function isInTypePosition(identifier) {
2551
+ let parent = identifier.parent;
2552
+ while (parent) {
2553
+ if (parent.type.startsWith("TS"))
2554
+ return true;
2555
+ if (IS_CEASE_BOUNDARY.has(parent.type))
2556
+ return false;
2557
+ parent = parent.parent;
2558
+ }
2559
+ return false;
2560
+ }
2561
+ function isDeclaredInComponentBody(variable, closureNode) {
2562
+ let parent = closureNode.parent;
2563
+ while (parent) {
2564
+ const isFunction = FUNCTION_DECLARATIONS.has(parent.type);
2565
+ if (isFunction) {
2566
+ const functionParent = parent;
2567
+ const isParameter = variable.defs.some((def) => {
2568
+ if (def.type !== "Parameter")
2569
+ return false;
2570
+ return def.node === functionParent;
2571
+ });
2572
+ if (isParameter)
2573
+ return true;
2574
+ return variable.defs.some((def) => {
2575
+ let node = def.node.parent;
2576
+ while (node && node !== functionParent)
2577
+ node = node.parent;
2578
+ return node === functionParent;
2579
+ });
2580
+ }
2581
+ parent = parent.parent;
2582
+ }
2583
+ return false;
2584
+ }
2585
+ function resolveFunctionReference(identifier, scope) {
2586
+ let variable;
2587
+ let currentScope = scope;
2588
+ while (currentScope) {
2589
+ variable = currentScope.set.get(identifier.name);
2590
+ if (variable)
2591
+ break;
2592
+ currentScope = currentScope.upper;
2593
+ }
2594
+ if (!variable || variable.defs.length === 0)
2595
+ return;
2596
+ for (const def of variable.defs) {
2597
+ const { node } = def;
2598
+ if (node.type === "FunctionDeclaration")
2599
+ return node;
2600
+ if (node.type === "VariableDeclarator" && node.init && (node.init.type === "ArrowFunctionExpression" || node.init.type === "FunctionExpression"))
2601
+ return node.init;
2602
+ }
2603
+ return;
2604
+ }
2605
+ function collectCaptures(node, scope, sourceCode) {
2606
+ const captures = new Array;
2607
+ const captureSet = new Set;
2608
+ function visit(current) {
2609
+ if (current.type === "Identifier") {
2610
+ const { name } = current;
2611
+ if (captureSet.has(name))
2612
+ return;
2613
+ if (GLOBAL_BUILTINS.has(name))
2614
+ return;
2615
+ if (isInTypePosition(current))
2616
+ return;
2617
+ let variable;
2618
+ let currentScope = scope;
2619
+ while (currentScope) {
2620
+ variable = currentScope.set.get(name);
2621
+ if (variable)
2622
+ break;
2623
+ currentScope = currentScope.upper;
2624
+ }
2625
+ if (variable) {
2626
+ const isDefinedInClosure = variable.defs.some((def) => {
2627
+ let defNode = def.node;
2628
+ while (defNode) {
2629
+ if (defNode === node)
2630
+ return true;
2631
+ defNode = defNode.parent;
2632
+ }
2633
+ return false;
2634
+ });
2635
+ if (!isDefinedInClosure) {
2636
+ if (!isDeclaredInComponentBody(variable, node)) {
2637
+ testingMetrics.outerScopeSkip += 1;
2638
+ return;
2639
+ }
2640
+ captureSet.add(name);
2641
+ const depthNode = findTopmostMemberExpression(current);
2642
+ const usagePath = sourceCode.getText(depthNode);
2643
+ captures.push({
2644
+ depth: getMemberExpressionDepth(depthNode),
2645
+ name,
2646
+ node: depthNode,
2647
+ usagePath,
2648
+ variable
2649
+ });
2650
+ }
2651
+ }
2652
+ }
2653
+ if (current.type === "TSSatisfiesExpression" || current.type === "TSAsExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") {
2654
+ visit(current.expression);
2655
+ return;
2656
+ }
2657
+ if (current.type === "MemberExpression") {
2658
+ visit(current.object);
2659
+ if (current.computed)
2660
+ visit(current.property);
2661
+ return;
2662
+ }
2663
+ const keys = sourceCode.visitorKeys?.[current.type] || [];
2664
+ for (const key of keys) {
2665
+ const value2 = current[key];
2666
+ if (Array.isArray(value2)) {
2667
+ for (const item of value2)
2668
+ if (item && typeof item === "object" && "type" in item)
2669
+ visit(item);
2670
+ } else if (value2 && typeof value2 === "object" && "type" in value2)
2671
+ visit(value2);
2672
+ }
2673
+ }
2674
+ visit(node);
2675
+ return captures;
2676
+ }
2677
+ function parseDependencies(node, sourceCode) {
2678
+ const dependencies = new Array;
2679
+ for (const element of node.elements) {
2680
+ if (!element || element.type === "SpreadElement")
2681
+ continue;
2682
+ const name = nodeToDependencyString(element, sourceCode);
2683
+ const depth = getMemberExpressionDepth(element);
2684
+ dependencies.push({
2685
+ depth,
2686
+ name,
2687
+ node: element
2688
+ });
2689
+ }
2690
+ return dependencies;
2691
+ }
2692
+ function isUnstableValue(node) {
2693
+ return node ? UNSTABLE_VALUES.has(node.type) : false;
2694
+ }
2695
+ var isNumberArray = array2(number);
2696
+ var isStringArray2 = array2(string2);
2697
+ function validate(validator, value2) {
2698
+ return safe(() => parseOrThrow2(value2, validator)).success;
2699
+ }
2700
+ function convertStableResult(stableResult) {
2701
+ if (typeof stableResult === "boolean")
2702
+ return stableResult;
2703
+ if (typeof stableResult === "number")
2704
+ return new Set([stableResult]);
2705
+ if (validate(isNumberArray, stableResult) && stableResult.length > 0)
2706
+ return new Set(stableResult);
2707
+ if (validate(isStringArray2, stableResult) && stableResult.length > 0)
2708
+ return new Set(stableResult);
2709
+ return false;
2710
+ }
2711
+ var useExhaustiveDependencies = {
2712
+ create(context) {
2713
+ const options = {
2714
+ hooks: [],
2715
+ reportMissingDependenciesArray: true,
2716
+ reportUnnecessaryDependencies: true,
2717
+ ...context.options[0]
2718
+ };
2719
+ const hookConfigs = new Map(DEFAULT_HOOKS);
2720
+ for (const customHook of options.hooks) {
2721
+ if (customHook.closureIndex !== undefined && customHook.dependenciesIndex !== undefined) {
2722
+ hookConfigs.set(customHook.name, {
2723
+ closureIndex: customHook.closureIndex,
2724
+ dependenciesIndex: customHook.dependenciesIndex
2725
+ });
2726
+ }
2727
+ }
2728
+ const stableHooks = new Map(STABLE_HOOKS);
2729
+ for (const customHook of options.hooks) {
2730
+ if (customHook.stableResult !== undefined) {
2731
+ stableHooks.set(customHook.name, convertStableResult(customHook.stableResult));
2732
+ }
2733
+ }
2734
+ const scopeCache = new WeakMap;
2735
+ function getScope(node) {
2736
+ const cached = scopeCache.get(node);
2737
+ if (cached)
2738
+ return cached;
2739
+ const scope = context.sourceCode.getScope(node);
2740
+ scopeCache.set(node, scope);
2741
+ return scope;
2742
+ }
2743
+ return {
2744
+ CallExpression(node) {
2745
+ const callNode = node;
2746
+ const hookName = getHookName(callNode);
2747
+ if (!hookName)
2748
+ return;
2749
+ const hookConfig = hookConfigs.get(hookName);
2750
+ if (!hookConfig)
2751
+ return;
2752
+ const { closureIndex, dependenciesIndex } = hookConfig;
2753
+ const { arguments: args } = callNode;
2754
+ const closureArg = args[closureIndex];
2755
+ if (!closureArg)
2756
+ return;
2757
+ let closureFunction;
2758
+ if (closureArg.type === "ArrowFunctionExpression" || closureArg.type === "FunctionExpression") {
2759
+ closureFunction = closureArg;
2760
+ } else if (closureArg.type === "Identifier") {
2761
+ const scope2 = getScope(callNode);
2762
+ closureFunction = resolveFunctionReference(closureArg, scope2);
2763
+ }
2764
+ if (!closureFunction)
2765
+ return;
2766
+ const dependenciesArgument = args[dependenciesIndex];
2767
+ if (!dependenciesArgument && options.reportMissingDependenciesArray) {
2768
+ const scope2 = getScope(closureFunction);
2769
+ const captures2 = collectCaptures(closureFunction, scope2, context.sourceCode);
2770
+ const requiredCaptures = captures2.filter((capture) => !isStableValue(capture.variable, capture.name, stableHooks));
2771
+ if (requiredCaptures.length > 0) {
2772
+ const missingNames = Array.from(new Set(requiredCaptures.map(({ name }) => name))).join(", ");
2773
+ const usagePaths = requiredCaptures.map(({ usagePath }) => usagePath);
2774
+ const uniqueDeps = Array.from(new Set(usagePaths)).toSorted();
2775
+ const depsArrayString = `[${uniqueDeps.join(", ")}]`;
2776
+ context.report({
2777
+ data: { deps: missingNames },
2778
+ messageId: "missingDependenciesArray",
2779
+ node: callNode,
2780
+ suggest: [
2781
+ {
2782
+ desc: `Add dependencies array: ${depsArrayString}`,
2783
+ fix(fixer) {
2784
+ const closureArgNode = args[closureIndex];
2785
+ return fixer.insertTextAfter(closureArgNode, `, ${depsArrayString}`);
2786
+ }
2787
+ }
2788
+ ]
2789
+ });
2790
+ }
2791
+ return;
2792
+ }
2793
+ if (!dependenciesArgument)
2794
+ return;
2795
+ if (dependenciesArgument.type !== "ArrayExpression")
2796
+ return;
2797
+ const depsArray = dependenciesArgument;
2798
+ const scope = getScope(closureFunction);
2799
+ const captures = collectCaptures(closureFunction, scope, context.sourceCode);
2800
+ const dependencies = parseDependencies(depsArray, context.sourceCode);
2801
+ for (const dependency of dependencies) {
2802
+ const dependencyRootIdentifier = getRootIdentifier(dependency.node);
2803
+ if (!dependencyRootIdentifier)
2804
+ continue;
2805
+ const dependencyName = dependencyRootIdentifier.name;
2806
+ const matchingCaptures = captures.filter(({ node: node2 }) => getRootIdentifier(node2)?.name === dependencyName);
2807
+ if (matchingCaptures.length === 0) {
2808
+ if (options.reportUnnecessaryDependencies) {
2809
+ const newDeps = dependencies.filter((d2) => d2.name !== dependency.name).map((d2) => d2.name);
2810
+ const newDepsString = `[${newDeps.join(", ")}]`;
2811
+ context.report({
2812
+ data: { name: dependency.name },
2813
+ messageId: "unnecessaryDependency",
2814
+ node: dependency.node,
2815
+ suggest: [
2816
+ {
2817
+ desc: `Remove '${dependency.name}' from dependencies array`,
2818
+ fix(fixer) {
2819
+ return fixer.replaceText(depsArray, newDepsString);
2820
+ }
2821
+ }
2822
+ ]
2823
+ });
2824
+ }
2825
+ continue;
2826
+ }
2827
+ const maxCaptureDepth = Math.max(...matchingCaptures.map((c) => c.depth));
2828
+ if (dependency.depth > maxCaptureDepth && options.reportUnnecessaryDependencies) {
2829
+ const newDeps = dependencies.filter((d2) => d2.name !== dependency.name).map((d2) => d2.name);
2830
+ const newDepsString = `[${newDeps.join(", ")}]`;
2831
+ context.report({
2832
+ data: { name: dependency.name },
2833
+ messageId: "unnecessaryDependency",
2834
+ node: dependency.node,
2835
+ suggest: [
2836
+ {
2837
+ desc: `Remove '${dependency.name}' from dependencies array`,
2838
+ fix(fixer) {
2839
+ return fixer.replaceText(depsArray, newDepsString);
2840
+ }
2841
+ }
2842
+ ]
2843
+ });
2844
+ }
2845
+ }
2846
+ for (const capture of captures) {
2847
+ if (isStableValue(capture.variable, capture.name, stableHooks))
2848
+ continue;
2849
+ const rootIdentifier = getRootIdentifier(capture.node);
2850
+ if (!rootIdentifier)
2851
+ continue;
2852
+ const captureName = rootIdentifier.name;
2853
+ let isInDependencies = false;
2854
+ for (const dependency of dependencies) {
2855
+ const dependencyRootIdentifier = getRootIdentifier(dependency.node);
2856
+ if (dependencyRootIdentifier?.name === captureName && dependency.depth <= capture.depth) {
2857
+ isInDependencies = true;
2858
+ break;
2859
+ }
2860
+ }
2861
+ if (!isInDependencies) {
2862
+ const lastDependency = dependencies.at(-1);
2863
+ const dependencyNames = dependencies.map(({ name }) => name);
2864
+ const newDependencies = [...dependencyNames, capture.usagePath].toSorted();
2865
+ const newDependenciesString = `[${newDependencies.join(", ")}]`;
2866
+ context.report({
2867
+ data: { name: capture.usagePath },
2868
+ messageId: "missingDependency",
2869
+ node: lastDependency?.node || depsArray,
2870
+ suggest: [
2871
+ {
2872
+ desc: `Add '${capture.usagePath}' to dependencies array`,
2873
+ fix(fixer) {
2874
+ return fixer.replaceText(depsArray, newDependenciesString);
2875
+ }
2876
+ }
2877
+ ]
2878
+ });
2879
+ }
2880
+ }
2881
+ for (const capture of captures) {
2882
+ if (isStableValue(capture.variable, capture.name, stableHooks))
2883
+ continue;
2884
+ const rootIdentifier = getRootIdentifier(capture.node);
2885
+ if (!rootIdentifier)
2886
+ continue;
2887
+ const captureName = rootIdentifier.name;
2888
+ for (const dependency of dependencies) {
2889
+ const dependencyRootIdentifier = getRootIdentifier(dependency.node);
2890
+ const isMatch = dependencyRootIdentifier?.name === captureName && dependency.depth === capture.depth;
2891
+ const isDirectIdentifier = dependency.depth === 0;
2892
+ if (isMatch && isDirectIdentifier) {
2893
+ const variableDefinition = capture.variable?.defs[0];
2894
+ const initialNode = variableDefinition?.node.type === "VariableDeclarator" ? variableDefinition.node.init ?? undefined : undefined;
2895
+ if (isUnstableValue(initialNode)) {
2896
+ context.report({
2897
+ data: { name: capture.usagePath },
2898
+ messageId: "unstableDependency",
2899
+ node: dependency.node
2900
+ });
2901
+ }
2902
+ break;
2903
+ }
2904
+ if (isMatch)
2905
+ break;
2906
+ }
2907
+ }
2908
+ }
2909
+ };
2910
+ },
2911
+ meta: {
2912
+ docs: {
2913
+ description: "Enforce exhaustive and correct dependency specification in React hooks to prevent stale closures and unnecessary re-renders",
2914
+ recommended: true,
2915
+ url: "https://biomejs.dev/linter/rules/use-exhaustive-dependencies/"
2916
+ },
2917
+ fixable: "code",
2918
+ hasSuggestions: true,
2919
+ messages: {
2920
+ missingDependenciesArray: "This hook does not specify its dependencies array. Missing: {{deps}}",
2921
+ missingDependency: "This hook does not specify its dependency on {{name}}.",
2922
+ unnecessaryDependency: "This dependency {{name}} can be removed from the list.",
2923
+ unstableDependency: "{{name}} changes on every re-render. Wrap the definition in useCallback() or useMemo() to stabilize it."
2924
+ },
2925
+ schema: [
2926
+ {
2927
+ additionalProperties: false,
2928
+ properties: {
2929
+ hooks: {
2930
+ description: "Array of custom hook entries to check for exhaustive dependencies",
2931
+ items: {
2932
+ additionalProperties: false,
2933
+ properties: {
2934
+ closureIndex: {
2935
+ description: "Index of the closure argument for dependency validation",
2936
+ type: "number"
2937
+ },
2938
+ dependenciesIndex: {
2939
+ description: "Index of the dependencies array for validation",
2940
+ type: "number"
2941
+ },
2942
+ name: {
2943
+ description: "The name of the hook",
2944
+ type: "string"
2945
+ },
2946
+ stableResult: {
2947
+ description: "Specify stable results: true (whole result), number (array index), number[] (multiple indices), or string[] (object properties)",
2948
+ oneOf: [
2949
+ { type: "boolean" },
2950
+ { type: "number" },
2951
+ { items: { type: "number" }, type: "array" },
2952
+ { items: { type: "string" }, type: "array" }
2953
+ ]
2954
+ }
2955
+ },
2956
+ required: ["name"],
2957
+ type: "object"
2958
+ },
2959
+ type: "array"
2960
+ },
2961
+ reportMissingDependenciesArray: {
2962
+ default: true,
2963
+ description: "Report when the dependencies array is completely missing",
2964
+ type: "boolean"
2965
+ },
2966
+ reportUnnecessaryDependencies: {
2967
+ default: true,
2968
+ description: "Report when unnecessary dependencies are specified",
2969
+ type: "boolean"
2970
+ }
2971
+ },
2972
+ type: "object"
2973
+ }
2974
+ ],
2975
+ type: "problem"
2976
+ }
2977
+ };
2978
+ var use_exhaustive_dependencies_default = useExhaustiveDependencies;
2979
+
2980
+ // src/rules/use-hook-at-top-level.ts
2981
+ var import_types2 = __toESM(require_dist(), 1);
2982
+ var HOOK_NAME_PATTERN = /^use[A-Z]/;
2983
+ var COMPONENT_NAME_PATTERN = /^[A-Z]/;
2984
+ function isReactHook(name) {
2985
+ return HOOK_NAME_PATTERN.test(name);
2986
+ }
2987
+ function isComponent(name) {
2988
+ return COMPONENT_NAME_PATTERN.test(name);
2989
+ }
2990
+ function isComponentOrHook(node) {
2991
+ if (node.type === "FunctionDeclaration" && node.id) {
2992
+ const { name } = node.id;
2993
+ return isComponent(name) || isReactHook(name);
2994
+ }
2995
+ if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
2996
+ const { parent } = node;
2997
+ if (!parent)
2998
+ return false;
2999
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") {
3000
+ const { name } = parent.id;
3001
+ return isComponent(name) || isReactHook(name);
3002
+ }
3003
+ if (parent.type === "Property" && parent.key.type === "Identifier") {
3004
+ const { name } = parent.key;
3005
+ return isComponent(name) || isReactHook(name);
3006
+ }
3007
+ if (parent.type === "MethodDefinition" && parent.key.type === "Identifier") {
3008
+ const { name } = parent.key;
3009
+ return isComponent(name) || isReactHook(name);
3010
+ }
3011
+ }
3012
+ return false;
3013
+ }
3014
+ function isHookCall(node) {
3015
+ const { callee } = node;
3016
+ if (callee.type === "Identifier")
3017
+ return isReactHook(callee.name);
3018
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier")
3019
+ return isReactHook(callee.property.name);
3020
+ return false;
3021
+ }
3022
+ var FUNCTION_BOUNDARIES = new Set([
3023
+ import_types2.TSESTree.AST_NODE_TYPES.FunctionDeclaration,
3024
+ import_types2.TSESTree.AST_NODE_TYPES.FunctionExpression,
3025
+ import_types2.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression
3026
+ ]);
3027
+ function isInFinallyBlock(node) {
3028
+ let current = node.parent;
3029
+ const maxDepth = 20;
3030
+ for (let depth = 0;depth < maxDepth && current; depth++) {
3031
+ if (FUNCTION_BOUNDARIES.has(current.type))
3032
+ return false;
3033
+ if (current.type === "TryStatement") {
3034
+ let checkNode = node;
3035
+ while (checkNode && checkNode !== current) {
3036
+ if (checkNode === current.finalizer)
3037
+ return true;
3038
+ checkNode = checkNode.parent;
3039
+ }
3040
+ return false;
3041
+ }
3042
+ current = current.parent;
3043
+ }
3044
+ return false;
3045
+ }
3046
+ function isRecursiveCall(node, functionName) {
3047
+ if (!functionName)
3048
+ return false;
3049
+ const { callee } = node;
3050
+ if (callee.type === "Identifier")
3051
+ return callee.name === functionName;
3052
+ return false;
3053
+ }
3054
+ var useHookAtTopLevel = {
3055
+ create(context) {
3056
+ const contextStack = new Array;
3057
+ let currentFunctionName;
3058
+ function getCurrentContext() {
3059
+ return contextStack.length > 0 ? contextStack.at(-1) : undefined;
3060
+ }
3061
+ function pushContext(newContext) {
3062
+ contextStack.push(newContext);
3063
+ }
3064
+ function popContext() {
3065
+ contextStack.pop();
3066
+ }
3067
+ function updateContext(updates) {
3068
+ const current = getCurrentContext();
3069
+ if (!current)
3070
+ return;
3071
+ contextStack[contextStack.length - 1] = {
3072
+ ...current,
3073
+ ...updates
3074
+ };
3075
+ }
3076
+ function handleFunctionEnter(node) {
3077
+ const funcNode = node;
3078
+ const current = getCurrentContext();
3079
+ const depth = current ? current.functionDepth + 1 : 0;
3080
+ const isComp = isComponentOrHook(funcNode);
3081
+ if (funcNode.type === "FunctionDeclaration" && funcNode.id)
3082
+ currentFunctionName = funcNode.id.name;
3083
+ if (current?.isComponentOrHook) {
3084
+ pushContext({
3085
+ afterEarlyReturn: false,
3086
+ functionDepth: depth,
3087
+ inConditional: false,
3088
+ inLoop: false,
3089
+ inNestedFunction: true,
3090
+ inTryBlock: false,
3091
+ isComponentOrHook: false
3092
+ });
3093
+ } else if (isComp) {
3094
+ pushContext({
3095
+ afterEarlyReturn: false,
3096
+ functionDepth: depth,
3097
+ inConditional: false,
3098
+ inLoop: false,
3099
+ inNestedFunction: false,
3100
+ inTryBlock: false,
3101
+ isComponentOrHook: true
3102
+ });
3103
+ }
3104
+ }
3105
+ function handleFunctionExit() {
3106
+ const current = getCurrentContext();
3107
+ if (current)
3108
+ popContext();
3109
+ currentFunctionName = undefined;
3110
+ }
3111
+ return {
3112
+ ArrowFunctionExpression: handleFunctionEnter,
3113
+ "ArrowFunctionExpression:exit": handleFunctionExit,
3114
+ CallExpression(node) {
3115
+ const callNode = node;
3116
+ if (!isHookCall(callNode))
3117
+ return;
3118
+ const current = getCurrentContext();
3119
+ if (!current)
3120
+ return;
3121
+ if (!current.isComponentOrHook && !current.inNestedFunction)
3122
+ return;
3123
+ if (isInFinallyBlock(callNode))
3124
+ return;
3125
+ if (isRecursiveCall(callNode, currentFunctionName)) {
3126
+ context.report({
3127
+ messageId: "recursiveHookCall",
3128
+ node: callNode
3129
+ });
3130
+ return;
3131
+ }
3132
+ if (current.inNestedFunction) {
3133
+ context.report({
3134
+ messageId: "nestedFunction",
3135
+ node: callNode
3136
+ });
3137
+ return;
3138
+ }
3139
+ if (current.inConditional) {
3140
+ context.report({
3141
+ messageId: "conditionalHook",
3142
+ node: callNode
3143
+ });
3144
+ return;
3145
+ }
3146
+ if (current.inLoop) {
3147
+ context.report({
3148
+ messageId: "loopHook",
3149
+ node: callNode
3150
+ });
3151
+ return;
3152
+ }
3153
+ if (current.inTryBlock) {
3154
+ context.report({
3155
+ messageId: "tryBlockHook",
3156
+ node: callNode
3157
+ });
3158
+ return;
3159
+ }
3160
+ if (current.afterEarlyReturn) {
3161
+ context.report({
3162
+ messageId: "afterEarlyReturn",
3163
+ node: callNode
3164
+ });
3165
+ }
3166
+ },
3167
+ ConditionalExpression() {
3168
+ updateContext({ inConditional: true });
3169
+ },
3170
+ "ConditionalExpression:exit"() {
3171
+ updateContext({ inConditional: false });
3172
+ },
3173
+ DoWhileStatement() {
3174
+ updateContext({ inLoop: true });
3175
+ },
3176
+ "DoWhileStatement:exit"() {
3177
+ updateContext({ inLoop: false });
3178
+ },
3179
+ ForInStatement() {
3180
+ updateContext({ inLoop: true });
3181
+ },
3182
+ "ForInStatement:exit"() {
3183
+ updateContext({ inLoop: false });
3184
+ },
3185
+ ForOfStatement() {
3186
+ updateContext({ inLoop: true });
3187
+ },
3188
+ "ForOfStatement:exit"() {
3189
+ updateContext({ inLoop: false });
3190
+ },
3191
+ ForStatement() {
3192
+ updateContext({ inLoop: true });
3193
+ },
3194
+ "ForStatement:exit"() {
3195
+ updateContext({ inLoop: false });
3196
+ },
3197
+ FunctionDeclaration: handleFunctionEnter,
3198
+ "FunctionDeclaration:exit": handleFunctionExit,
3199
+ FunctionExpression: handleFunctionEnter,
3200
+ "FunctionExpression:exit": handleFunctionExit,
3201
+ IfStatement() {
3202
+ updateContext({ inConditional: true });
3203
+ },
3204
+ "IfStatement:exit"() {
3205
+ updateContext({ inConditional: false });
3206
+ },
3207
+ LogicalExpression() {
3208
+ updateContext({ inConditional: true });
3209
+ },
3210
+ "LogicalExpression:exit"() {
3211
+ updateContext({ inConditional: false });
3212
+ },
3213
+ "ReturnStatement:exit"() {
3214
+ updateContext({ afterEarlyReturn: true });
3215
+ },
3216
+ SwitchStatement() {
3217
+ updateContext({ inConditional: true });
3218
+ },
3219
+ "SwitchStatement:exit"() {
3220
+ updateContext({ inConditional: false });
3221
+ },
3222
+ TryStatement() {
3223
+ updateContext({ inTryBlock: true });
3224
+ },
3225
+ "TryStatement:exit"() {
3226
+ updateContext({ inTryBlock: false });
3227
+ },
3228
+ WhileStatement() {
3229
+ updateContext({ inLoop: true });
3230
+ },
3231
+ "WhileStatement:exit"() {
3232
+ updateContext({ inLoop: false });
3233
+ }
3234
+ };
3235
+ },
3236
+ meta: {
3237
+ docs: {
3238
+ description: "Enforce that React hooks are only called at the top level of components or custom hooks, never conditionally or in nested functions",
3239
+ recommended: true,
3240
+ url: "https://react.dev/reference/rules/rules-of-hooks"
3241
+ },
3242
+ messages: {
3243
+ afterEarlyReturn: "This hook is being called after an early return. Hooks must be called unconditionally and in the same order every render.",
3244
+ conditionalHook: "This hook is being called conditionally. All hooks must be called in the exact same order in every component render.",
3245
+ loopHook: "This hook is being called inside a loop. All hooks must be called in the exact same order in every component render.",
3246
+ nestedFunction: "This hook is being called from a nested function. All hooks must be called unconditionally from the top-level component.",
3247
+ recursiveHookCall: "This hook is being called recursively. Recursive calls require a condition to terminate, which violates hook rules.",
3248
+ tryBlockHook: "This hook is being called inside a try block. Hooks must be called unconditionally at the top level."
3249
+ },
3250
+ schema: [
3251
+ {
3252
+ additionalProperties: false,
3253
+ properties: {
3254
+ hooks: {
3255
+ description: "Additional custom hook names to check",
3256
+ items: { type: "string" },
3257
+ type: "array"
3258
+ }
3259
+ },
3260
+ type: "object"
3261
+ }
3262
+ ],
3263
+ type: "problem"
3264
+ }
3265
+ };
3266
+ var use_hook_at_top_level_default = useHookAtTopLevel;
3267
+
3268
+ // src/index.ts
3269
+ var rules = {
3270
+ "enforce-ianitor-check-type": enforce_ianitor_check_type_default,
3271
+ "no-color3-constructor": no_color3_constructor_default,
3272
+ "no-print": no_print_default,
3273
+ "no-shorthand-names": no_shorthand_names_default,
3274
+ "no-warn": no_warn_default,
3275
+ "require-react-component-keys": require_react_component_keys_default,
3276
+ "use-exhaustive-dependencies": use_exhaustive_dependencies_default,
3277
+ "use-hook-at-top-level": use_hook_at_top_level_default
3278
+ };
3279
+ var recommended = {
3280
+ plugins: {
3281
+ "cease-nonsense": {
3282
+ rules
3283
+ }
3284
+ },
3285
+ rules: {
3286
+ "cease-nonsense/enforce-ianitor-check-type": "error",
3287
+ "cease-nonsense/no-color3-constructor": "error",
3288
+ "cease-nonsense/no-print": "error",
3289
+ "cease-nonsense/no-shorthand-names": "error",
3290
+ "cease-nonsense/no-warn": "error",
3291
+ "cease-nonsense/require-react-component-keys": "error",
3292
+ "cease-nonsense/use-exhaustive-dependencies": "error",
3293
+ "cease-nonsense/use-hook-at-top-level": "error"
3294
+ }
3295
+ };
3296
+ var plugin = {
3297
+ configs: { recommended },
3298
+ rules
3299
+ };
3300
+ var src_default = plugin;
3301
+ export {
3302
+ src_default as default
3303
+ };