@pobammer-ts/eslint-cease-nonsense-rules 1.0.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +268 -1
  2. package/dist/configure-utilities.d.ts +68 -0
  3. package/dist/configure-utilities.js +115 -0
  4. package/dist/configure-utilities.js.map +1 -0
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.js +4 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/rules/ban-react-fc.js.map +1 -1
  9. package/dist/rules/enforce-ianitor-check-type.js +5 -5
  10. package/dist/rules/enforce-ianitor-check-type.js.map +1 -1
  11. package/dist/rules/no-color3-constructor.js.map +1 -1
  12. package/dist/rules/no-instance-methods-without-this.d.ts +2 -2
  13. package/dist/rules/no-instance-methods-without-this.js.map +1 -1
  14. package/dist/rules/no-print.js.map +1 -1
  15. package/dist/rules/no-shorthand-names.d.ts +4 -0
  16. package/dist/rules/no-shorthand-names.js.map +1 -1
  17. package/dist/rules/no-warn.js.map +1 -1
  18. package/dist/rules/prefer-sequence-overloads.js.map +1 -1
  19. package/dist/rules/prefer-udim2-shorthand.js +44 -70
  20. package/dist/rules/prefer-udim2-shorthand.js.map +1 -1
  21. package/dist/rules/require-named-effect-functions.d.ts +11 -0
  22. package/dist/rules/require-named-effect-functions.js +2 -1
  23. package/dist/rules/require-named-effect-functions.js.map +1 -1
  24. package/dist/rules/require-paired-calls.d.ts +34 -0
  25. package/dist/rules/require-paired-calls.js +690 -0
  26. package/dist/rules/require-paired-calls.js.map +1 -0
  27. package/dist/rules/require-react-component-keys.d.ts +2 -2
  28. package/dist/rules/require-react-component-keys.js +1 -1
  29. package/dist/rules/require-react-component-keys.js.map +1 -1
  30. package/dist/rules/use-exhaustive-dependencies.d.ts +16 -1
  31. package/dist/rules/use-exhaustive-dependencies.js.map +1 -1
  32. package/dist/rules/use-hook-at-top-level.js.map +1 -1
  33. package/package.json +27 -18
@@ -0,0 +1,690 @@
1
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
2
+ import Type from "typebox";
3
+ import { Compile } from "typebox/compile";
4
+ const isStringArray = Compile(Type.Readonly(Type.Array(Type.String())));
5
+ const isPairConfiguration = Compile(Type.Readonly(Type.Object({
6
+ alternatives: Type.Optional(isStringArray),
7
+ closer: Type.Union([Type.String(), isStringArray]),
8
+ opener: Type.String(),
9
+ platform: Type.Optional(Type.Literal("roblox")),
10
+ requireSync: Type.Optional(Type.Boolean()),
11
+ yieldingFunctions: Type.Optional(isStringArray),
12
+ })));
13
+ const isRuleOptions = Compile(Type.Partial(Type.Readonly(Type.Object({
14
+ allowConditionalClosers: Type.Optional(Type.Boolean()),
15
+ allowMultipleOpeners: Type.Optional(Type.Boolean()),
16
+ maxNestingDepth: Type.Optional(Type.Number()),
17
+ pairs: Type.Readonly(Type.Array(isPairConfiguration)),
18
+ }))));
19
+ export const DEFAULT_ROBLOX_YIELDING_FUNCTIONS = ["task.wait", "wait", "*.WaitForChild"];
20
+ function getCallName(node) {
21
+ const { callee } = node;
22
+ if (callee.type === AST_NODE_TYPES.Identifier)
23
+ return callee.name;
24
+ if (callee.type === AST_NODE_TYPES.MemberExpression) {
25
+ const object = callee.object.type === AST_NODE_TYPES.Identifier ? callee.object.name : undefined;
26
+ const property = callee.property.type === AST_NODE_TYPES.Identifier ? callee.property.name : undefined;
27
+ if (object !== undefined && property !== undefined)
28
+ return `${object}.${property}`;
29
+ }
30
+ return undefined;
31
+ }
32
+ function getValidClosers(configuration) {
33
+ const result = new Array();
34
+ if (isStringArray.Check(configuration.closer))
35
+ result.push(...configuration.closer);
36
+ else if (typeof configuration.closer === "string")
37
+ result.push(configuration.closer);
38
+ if (configuration.alternatives)
39
+ for (const alternative of configuration.alternatives)
40
+ result.push(alternative);
41
+ return result;
42
+ }
43
+ function cloneEntry(value) {
44
+ return { ...value };
45
+ }
46
+ const rule = {
47
+ create(context) {
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- ESLint context.options is typed as any[]
49
+ const rawOptions = context.options[0];
50
+ const baseOptions = isRuleOptions.Check(rawOptions) ? rawOptions : {};
51
+ const options = {
52
+ allowConditionalClosers: baseOptions.allowConditionalClosers ?? false,
53
+ allowMultipleOpeners: baseOptions.allowMultipleOpeners ?? true,
54
+ maxNestingDepth: baseOptions.maxNestingDepth ?? 0,
55
+ pairs: baseOptions.pairs ?? [],
56
+ };
57
+ if (options.pairs.length === 0) {
58
+ options.pairs = [
59
+ {
60
+ closer: "debug.profileend",
61
+ opener: "debug.profilebegin",
62
+ platform: "roblox",
63
+ requireSync: true,
64
+ yieldingFunctions: [...DEFAULT_ROBLOX_YIELDING_FUNCTIONS],
65
+ },
66
+ ];
67
+ }
68
+ const openerStack = new Array();
69
+ let stackIndexCounter = 0;
70
+ const functionStacks = new Array();
71
+ let yieldingAutoClosed = false;
72
+ let yieldingReportedFirst = false;
73
+ const contextStack = new Array();
74
+ const stackSnapshots = new Map();
75
+ const branchStacks = new Map();
76
+ function getCurrentContext() {
77
+ return contextStack.length > 0
78
+ ? contextStack.at(-1)
79
+ : {
80
+ asyncContext: false,
81
+ currentFunction: undefined,
82
+ hasEarlyExit: false,
83
+ inCatch: false,
84
+ inConditional: false,
85
+ inFinally: false,
86
+ inLoop: false,
87
+ inTry: false,
88
+ };
89
+ }
90
+ function pushContext(newContext) {
91
+ const currentContext = getCurrentContext();
92
+ contextStack.push({ ...currentContext, ...newContext });
93
+ }
94
+ function popContext() {
95
+ contextStack.pop();
96
+ }
97
+ function updateContext(updates) {
98
+ const last = contextStack.at(-1);
99
+ if (!last)
100
+ return;
101
+ contextStack[contextStack.length - 1] = { ...last, ...updates };
102
+ }
103
+ function cloneStack() {
104
+ // oxlint-disable-next-line no-array-callback-reference -- this is fine. leave it alone.
105
+ return openerStack.map(cloneEntry);
106
+ }
107
+ function saveSnapshot(node) {
108
+ stackSnapshots.set(node, cloneStack());
109
+ }
110
+ function findPairConfig(functionName, isOpener) {
111
+ return options.pairs.find((pair) => {
112
+ if (isOpener)
113
+ return pair.opener === functionName;
114
+ // Check if it matches closer or alternatives
115
+ const validClosers = getValidClosers(pair);
116
+ return validClosers.includes(functionName);
117
+ });
118
+ }
119
+ function isRobloxYieldingFunction(functionName, configuration) {
120
+ if (configuration.platform !== "roblox")
121
+ return false;
122
+ const yieldingFunctions = configuration.yieldingFunctions ?? DEFAULT_ROBLOX_YIELDING_FUNCTIONS;
123
+ return yieldingFunctions.some((pattern) => {
124
+ if (pattern.startsWith("*.")) {
125
+ // Match any method call with this name
126
+ const methodName = pattern.slice(2);
127
+ return functionName.endsWith(`.${methodName}`);
128
+ }
129
+ return functionName === pattern;
130
+ });
131
+ }
132
+ function onFunctionEnter(node) {
133
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor functions receive unknown, we know the type from selector
134
+ const functionNode = node;
135
+ functionStacks.push([...openerStack]);
136
+ openerStack.length = 0;
137
+ yieldingAutoClosed = false;
138
+ yieldingReportedFirst = false;
139
+ pushContext({
140
+ asyncContext: functionNode.async ?? false,
141
+ currentFunction: functionNode,
142
+ hasEarlyExit: false,
143
+ inCatch: false,
144
+ inConditional: false,
145
+ inFinally: false,
146
+ inLoop: false,
147
+ inTry: false,
148
+ });
149
+ }
150
+ function onFunctionExit() {
151
+ if (openerStack.length > 0) {
152
+ for (const entry of openerStack) {
153
+ const validClosers = getValidClosers(entry.config);
154
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
155
+ context.report({
156
+ data: {
157
+ closer,
158
+ opener: entry.opener,
159
+ paths: "function exit",
160
+ },
161
+ messageId: "unpairedOpener",
162
+ node: entry.node,
163
+ });
164
+ }
165
+ }
166
+ const parentStack = functionStacks.pop();
167
+ if (parentStack) {
168
+ openerStack.length = 0;
169
+ openerStack.push(...parentStack);
170
+ }
171
+ else
172
+ openerStack.length = 0;
173
+ popContext();
174
+ }
175
+ function onIfStatementEnter(node) {
176
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
177
+ const ifNode = node;
178
+ pushContext({ inConditional: true });
179
+ saveSnapshot(ifNode);
180
+ }
181
+ function onIfStatementExit(node) {
182
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
183
+ const ifNode = node;
184
+ popContext();
185
+ const originalStack = stackSnapshots.get(ifNode);
186
+ const branches = branchStacks.get(ifNode);
187
+ if (originalStack && branches && branches.length > 0) {
188
+ const hasCompleteElse = ifNode.alternate !== undefined && ifNode.alternate !== null;
189
+ if (hasCompleteElse) {
190
+ for (const { index, config, opener, node } of originalStack) {
191
+ const branchesWithOpener = branches.filter((branchStack) => branchStack.some((branch) => branch.index === index));
192
+ if (branchesWithOpener.length <= 0 || branchesWithOpener.length >= branches.length)
193
+ continue;
194
+ if (options.allowConditionalClosers !== false)
195
+ continue;
196
+ const validClosers = getValidClosers(config);
197
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
198
+ context.report({
199
+ data: {
200
+ closer,
201
+ opener,
202
+ paths: "not all execution paths",
203
+ },
204
+ messageId: "unpairedOpener",
205
+ node,
206
+ });
207
+ }
208
+ const commonOpeners = originalStack.filter((opener) => branches.every((branchStack) => branchStack.some(({ index }) => index === opener.index)));
209
+ openerStack.length = 0;
210
+ openerStack.push(...commonOpeners);
211
+ }
212
+ else {
213
+ openerStack.length = 0;
214
+ for (const entry of originalStack)
215
+ openerStack.push({ ...entry });
216
+ }
217
+ }
218
+ stackSnapshots.delete(ifNode);
219
+ branchStacks.delete(ifNode);
220
+ }
221
+ function onIfConsequentExit(node) {
222
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
223
+ const consequentNode = node;
224
+ const parent = consequentNode.parent;
225
+ if (parent?.type === AST_NODE_TYPES.IfStatement) {
226
+ const branches = branchStacks.get(parent) ?? [];
227
+ branches.push(cloneStack());
228
+ branchStacks.set(parent, branches);
229
+ const originalStack = stackSnapshots.get(parent);
230
+ if (!originalStack)
231
+ return;
232
+ openerStack.length = 0;
233
+ for (const entry of originalStack)
234
+ openerStack.push({ ...entry });
235
+ }
236
+ }
237
+ function onIfAlternateExit(node) {
238
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
239
+ const alternateNode = node;
240
+ const parent = alternateNode.parent;
241
+ if (parent?.type === AST_NODE_TYPES.IfStatement) {
242
+ const branches = branchStacks.get(parent) ?? [];
243
+ branches.push(cloneStack());
244
+ branchStacks.set(parent, branches);
245
+ }
246
+ }
247
+ function onTryStatementEnter(node) {
248
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
249
+ const tryNode = node;
250
+ saveSnapshot(tryNode);
251
+ }
252
+ function onTryStatementExit(node) {
253
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
254
+ const tryNode = node;
255
+ const originalStack = stackSnapshots.get(tryNode);
256
+ const branches = branchStacks.get(tryNode);
257
+ if (tryNode.finalizer) {
258
+ stackSnapshots.delete(tryNode);
259
+ branchStacks.delete(tryNode);
260
+ return;
261
+ }
262
+ if (originalStack && branches && branches.length > 0) {
263
+ for (const opener of originalStack) {
264
+ const branchesWithOpener = branches.filter((branchStack) => branchStack.some((entry) => entry.index === opener.index));
265
+ if (branchesWithOpener.length > 0 &&
266
+ branchesWithOpener.length < branches.length &&
267
+ options.allowConditionalClosers === false) {
268
+ const validClosers = getValidClosers(opener.config);
269
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
270
+ context.report({
271
+ data: {
272
+ closer,
273
+ opener: opener.opener,
274
+ paths: "not all execution paths",
275
+ },
276
+ messageId: "unpairedOpener",
277
+ node: opener.node,
278
+ });
279
+ }
280
+ }
281
+ const commonOpeners = originalStack.filter((opener) => branches.every((branchStack) => branchStack.some((entry) => entry.index === opener.index)));
282
+ openerStack.length = 0;
283
+ openerStack.push(...commonOpeners);
284
+ }
285
+ stackSnapshots.delete(tryNode);
286
+ branchStacks.delete(tryNode);
287
+ }
288
+ function onTryBlockEnter() {
289
+ pushContext({ inTry: true });
290
+ }
291
+ function onTryBlockExit(node) {
292
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
293
+ const blockNode = node;
294
+ const { parent } = blockNode;
295
+ if (parent?.type === AST_NODE_TYPES.TryStatement) {
296
+ const branches = branchStacks.get(parent) ?? [];
297
+ branches.push(cloneStack());
298
+ branchStacks.set(parent, branches);
299
+ const originalStack = stackSnapshots.get(parent);
300
+ if (originalStack) {
301
+ openerStack.length = 0;
302
+ for (const entry of originalStack)
303
+ openerStack.push({ ...entry });
304
+ }
305
+ }
306
+ popContext();
307
+ }
308
+ function onCatchClauseEnter() {
309
+ pushContext({ inCatch: true });
310
+ }
311
+ function onCatchClauseExit(node) {
312
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
313
+ const catchNode = node;
314
+ const { parent } = catchNode;
315
+ if (parent?.type === AST_NODE_TYPES.TryStatement) {
316
+ const branches = branchStacks.get(parent) ?? [];
317
+ branches.push(cloneStack());
318
+ branchStacks.set(parent, branches);
319
+ const originalStack = stackSnapshots.get(parent);
320
+ if (originalStack) {
321
+ openerStack.length = 0;
322
+ for (const entry of originalStack)
323
+ openerStack.push({ ...entry });
324
+ }
325
+ }
326
+ popContext();
327
+ }
328
+ function onFinallyBlockEnter() {
329
+ pushContext({ inFinally: true });
330
+ }
331
+ function onFinallyBlockExit() {
332
+ popContext();
333
+ }
334
+ function onSwitchStatementEnter(node) {
335
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
336
+ const switchNode = node;
337
+ pushContext({ inConditional: true });
338
+ saveSnapshot(switchNode);
339
+ }
340
+ function onSwitchStatementExit(node) {
341
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
342
+ const switchNode = node;
343
+ popContext();
344
+ const originalStack = stackSnapshots.get(switchNode);
345
+ const branches = branchStacks.get(switchNode);
346
+ if (originalStack && branches && branches.length > 0) {
347
+ const hasDefault = switchNode.cases.some((caseNode) => caseNode.test === null);
348
+ if (hasDefault && branches.length === switchNode.cases.length) {
349
+ for (const opener of originalStack) {
350
+ const branchesWithOpener = branches.filter((branchStack) => branchStack.some((entry) => entry.index === opener.index));
351
+ if (branchesWithOpener.length > 0 &&
352
+ branchesWithOpener.length < branches.length &&
353
+ options.allowConditionalClosers === false) {
354
+ const validClosers = getValidClosers(opener.config);
355
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
356
+ context.report({
357
+ data: {
358
+ closer,
359
+ opener: opener.opener,
360
+ paths: "not all execution paths",
361
+ },
362
+ messageId: "unpairedOpener",
363
+ node: opener.node,
364
+ });
365
+ }
366
+ }
367
+ const commonOpeners = originalStack.filter((opener) => branches.every((branchStack) => branchStack.some((entry) => entry.index === opener.index)));
368
+ openerStack.length = 0;
369
+ openerStack.push(...commonOpeners);
370
+ }
371
+ else {
372
+ openerStack.length = 0;
373
+ for (const entry of originalStack)
374
+ openerStack.push({ ...entry });
375
+ }
376
+ }
377
+ stackSnapshots.delete(switchNode);
378
+ branchStacks.delete(switchNode);
379
+ }
380
+ function onSwitchCaseExit(node) {
381
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
382
+ const caseNode = node;
383
+ const { parent } = caseNode;
384
+ if (parent?.type === AST_NODE_TYPES.SwitchStatement) {
385
+ const branches = branchStacks.get(parent) ?? [];
386
+ branches.push(cloneStack());
387
+ branchStacks.set(parent, branches);
388
+ const originalStack = stackSnapshots.get(parent);
389
+ if (!originalStack)
390
+ return;
391
+ openerStack.length = 0;
392
+ for (const entry of originalStack)
393
+ openerStack.push({ ...entry });
394
+ }
395
+ }
396
+ function onLoopEnter() {
397
+ pushContext({ inLoop: true });
398
+ }
399
+ function onLoopExit() {
400
+ popContext();
401
+ }
402
+ function onEarlyExit(node) {
403
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
404
+ const statementNode = node;
405
+ updateContext({ hasEarlyExit: true });
406
+ const currentContext = getCurrentContext();
407
+ if (currentContext.inFinally || openerStack.length === 0)
408
+ return;
409
+ for (const { opener, config, node } of openerStack) {
410
+ const validClosers = getValidClosers(config);
411
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
412
+ const statementType = statementNode.type === AST_NODE_TYPES.ReturnStatement ? "return" : "throw";
413
+ const lineNumber = statementNode.loc?.start.line ?? 0;
414
+ context.report({
415
+ data: {
416
+ closer,
417
+ opener,
418
+ paths: `${statementType} at line ${lineNumber}`,
419
+ },
420
+ messageId: "unpairedOpener",
421
+ node: node,
422
+ });
423
+ }
424
+ }
425
+ function onBreakContinue(node) {
426
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
427
+ const statementNode = node;
428
+ const currentContext = getCurrentContext();
429
+ if (!currentContext.inLoop || openerStack.length <= 0)
430
+ return;
431
+ for (const { node, config, opener } of openerStack) {
432
+ const validClosers = getValidClosers(config);
433
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
434
+ const statementType = statementNode.type === AST_NODE_TYPES.BreakStatement ? "break" : "continue";
435
+ const lineNumber = statementNode.loc?.start.line ?? 0;
436
+ context.report({
437
+ data: {
438
+ closer,
439
+ opener,
440
+ paths: `${statementType} at line ${lineNumber}`,
441
+ },
442
+ messageId: "unpairedOpener",
443
+ node,
444
+ });
445
+ }
446
+ }
447
+ function onCallExpression(node) {
448
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
449
+ const callNode = node;
450
+ const callName = getCallName(callNode);
451
+ if (callName === undefined || callName === "")
452
+ return;
453
+ const openerConfig = findPairConfig(callName, true);
454
+ if (openerConfig) {
455
+ handleOpener(callNode, callName, openerConfig);
456
+ return;
457
+ }
458
+ const closerConfiguration = findPairConfig(callName, false);
459
+ if (closerConfiguration) {
460
+ handleCloser(callNode, callName, closerConfiguration);
461
+ return;
462
+ }
463
+ for (const entry of openerStack) {
464
+ if (!isRobloxYieldingFunction(callName, entry.config))
465
+ continue;
466
+ handleRobloxYield(callNode, callName, entry);
467
+ // Roblox auto-closes ALL profiles
468
+ openerStack.length = 0;
469
+ yieldingAutoClosed = true;
470
+ return;
471
+ }
472
+ }
473
+ function handleOpener(node, opener, config) {
474
+ const maxDepth = options.maxNestingDepth ?? 0;
475
+ if (maxDepth > 0 && openerStack.length >= maxDepth) {
476
+ context.report({
477
+ data: { max: String(maxDepth) },
478
+ messageId: "maxNestingExceeded",
479
+ node,
480
+ });
481
+ }
482
+ if (options.allowMultipleOpeners === false &&
483
+ openerStack.length > 0 &&
484
+ openerStack.at(-1)?.opener === opener) {
485
+ context.report({
486
+ data: { opener },
487
+ messageId: "multipleOpeners",
488
+ node,
489
+ });
490
+ }
491
+ const entry = {
492
+ config,
493
+ index: stackIndexCounter++,
494
+ location: node.loc,
495
+ node,
496
+ opener,
497
+ };
498
+ openerStack.push(entry);
499
+ }
500
+ function handleCloser(node, closer, configuration) {
501
+ const matchingIndex = openerStack.findLastIndex((entry) => getValidClosers(entry.config).includes(closer) && entry.config === configuration);
502
+ if (matchingIndex === -1) {
503
+ if (yieldingAutoClosed && !yieldingReportedFirst) {
504
+ yieldingReportedFirst = true;
505
+ return;
506
+ }
507
+ context.report({
508
+ data: {
509
+ closer,
510
+ opener: configuration.opener,
511
+ },
512
+ messageId: "unpairedCloser",
513
+ node,
514
+ });
515
+ return;
516
+ }
517
+ const matchingEntry = openerStack[matchingIndex];
518
+ if (!matchingEntry)
519
+ return;
520
+ if (matchingIndex !== openerStack.length - 1) {
521
+ const topEntry = openerStack.at(-1);
522
+ if (topEntry) {
523
+ context.report({
524
+ data: {
525
+ actual: topEntry.opener,
526
+ closer,
527
+ expected: matchingEntry.opener,
528
+ },
529
+ messageId: "wrongOrder",
530
+ node,
531
+ });
532
+ }
533
+ }
534
+ openerStack.splice(matchingIndex, 1);
535
+ }
536
+ function handleRobloxYield(node, yieldingFunction, openerEntry) {
537
+ const validClosers = getValidClosers(openerEntry.config);
538
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
539
+ context.report({
540
+ data: { closer, yieldingFunction },
541
+ messageId: "robloxYieldViolation",
542
+ node,
543
+ });
544
+ }
545
+ function onAsyncYield(node) {
546
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- ESLint visitor type from selector
547
+ const asyncNode = node;
548
+ for (const { opener, config } of openerStack) {
549
+ if (config.requireSync !== true)
550
+ continue;
551
+ const validClosers = getValidClosers(config);
552
+ const closer = validClosers.length === 1 ? (validClosers[0] ?? "closer") : validClosers.join("' or '");
553
+ const asyncType = asyncNode.type === AST_NODE_TYPES.AwaitExpression ? "await" : "yield";
554
+ context.report({
555
+ data: { asyncType, closer, opener },
556
+ messageId: "asyncViolation",
557
+ node: asyncNode,
558
+ });
559
+ }
560
+ }
561
+ return {
562
+ ArrowFunctionExpression: onFunctionEnter,
563
+ "ArrowFunctionExpression:exit": onFunctionExit,
564
+ AwaitExpression: onAsyncYield,
565
+ BreakStatement: onBreakContinue,
566
+ CallExpression: onCallExpression,
567
+ CatchClause: onCatchClauseEnter,
568
+ "CatchClause:exit": onCatchClauseExit,
569
+ ContinueStatement: onBreakContinue,
570
+ DoWhileStatement: onLoopEnter,
571
+ "DoWhileStatement:exit": onLoopExit,
572
+ ForInStatement: onLoopEnter,
573
+ "ForInStatement:exit": onLoopExit,
574
+ ForOfStatement: (node) => {
575
+ if (node.await)
576
+ onAsyncYield(node);
577
+ onLoopEnter();
578
+ },
579
+ "ForOfStatement:exit": onLoopExit,
580
+ ForStatement: onLoopEnter,
581
+ "ForStatement:exit": onLoopExit,
582
+ FunctionDeclaration: onFunctionEnter,
583
+ "FunctionDeclaration:exit": onFunctionExit,
584
+ FunctionExpression: onFunctionEnter,
585
+ "FunctionExpression:exit": onFunctionExit,
586
+ IfStatement: onIfStatementEnter,
587
+ "IfStatement > .alternate:exit": onIfAlternateExit,
588
+ "IfStatement > .consequent:exit": onIfConsequentExit,
589
+ "IfStatement:exit": onIfStatementExit,
590
+ ReturnStatement: onEarlyExit,
591
+ "SwitchCase:exit": onSwitchCaseExit,
592
+ SwitchStatement: onSwitchStatementEnter,
593
+ "SwitchStatement:exit": onSwitchStatementExit,
594
+ ThrowStatement: onEarlyExit,
595
+ TryStatement: onTryStatementEnter,
596
+ "TryStatement > .block": onTryBlockEnter,
597
+ "TryStatement > .block:exit": onTryBlockExit,
598
+ "TryStatement > .finalizer": onFinallyBlockEnter,
599
+ "TryStatement > .finalizer:exit": onFinallyBlockExit,
600
+ "TryStatement:exit": onTryStatementExit,
601
+ WhileStatement: onLoopEnter,
602
+ "WhileStatement:exit": onLoopExit,
603
+ YieldExpression: onAsyncYield,
604
+ };
605
+ },
606
+ meta: {
607
+ docs: {
608
+ description: "Enforces balanced opener/closer function calls across all execution paths",
609
+ recommended: false,
610
+ url: "https://github.com/howmanysmall/eslint-idiot-lint/tree/main/docs/rules/require-paired-calls.md",
611
+ },
612
+ fixable: "code",
613
+ messages: {
614
+ asyncViolation: "Cannot use {{asyncType}} between '{{opener}}' and '{{closer}}' (requireSync: true)",
615
+ conditionalOpener: "Conditional opener '{{opener}}' at {{location}} may not have matching closer on all paths",
616
+ maxNestingExceeded: "Maximum nesting depth of {{max}} exceeded for paired calls",
617
+ multipleOpeners: "Multiple consecutive calls to '{{opener}}' without matching closers (allowMultipleOpeners: false)",
618
+ robloxYieldViolation: "Yielding function '{{yieldingFunction}}' auto-closes all profiles - subsequent '{{closer}}' will error",
619
+ unpairedCloser: "Unexpected call to '{{closer}}' - no matching '{{opener}}'",
620
+ unpairedOpener: "Unpaired call to '{{opener}}' - missing '{{closer}}' on {{paths}}",
621
+ wrongOrder: "Closer '{{closer}}' called out of order - expected to close '{{expected}}' but '{{actual}}' is still open",
622
+ },
623
+ schema: [
624
+ {
625
+ additionalProperties: false,
626
+ properties: {
627
+ allowConditionalClosers: {
628
+ default: false,
629
+ type: "boolean",
630
+ },
631
+ allowMultipleOpeners: {
632
+ default: true,
633
+ type: "boolean",
634
+ },
635
+ maxNestingDepth: {
636
+ default: 0,
637
+ minimum: 0,
638
+ type: "number",
639
+ },
640
+ pairs: {
641
+ items: {
642
+ additionalProperties: false,
643
+ properties: {
644
+ alternatives: {
645
+ items: { minLength: 1, type: "string" },
646
+ type: "array",
647
+ },
648
+ closer: {
649
+ oneOf: [
650
+ { minLength: 1, type: "string" },
651
+ {
652
+ items: { minLength: 1, type: "string" },
653
+ minItems: 1,
654
+ type: "array",
655
+ },
656
+ ],
657
+ },
658
+ opener: {
659
+ minLength: 1,
660
+ type: "string",
661
+ },
662
+ platform: {
663
+ enum: ["roblox"],
664
+ type: "string",
665
+ },
666
+ requireSync: {
667
+ default: false,
668
+ type: "boolean",
669
+ },
670
+ yieldingFunctions: {
671
+ items: { minLength: 1, type: "string" },
672
+ type: "array",
673
+ },
674
+ },
675
+ required: ["opener", "closer"],
676
+ type: "object",
677
+ },
678
+ minItems: 1,
679
+ type: "array",
680
+ },
681
+ },
682
+ required: ["pairs"],
683
+ type: "object",
684
+ },
685
+ ],
686
+ type: "problem",
687
+ },
688
+ };
689
+ export default rule;
690
+ //# sourceMappingURL=require-paired-calls.js.map