pasika 0.10.84 → 0.10.85

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.
@@ -6221,14 +6221,16 @@ var preferEnumRule = {
6221
6221
  };
6222
6222
 
6223
6223
  // eslint/rules/prefer-object-destructuring.ts
6224
+ import ts8 from "typescript";
6224
6225
  var DOC5 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
6225
6226
  function hasTypeAnnotation(identifier) {
6226
6227
  return "typeAnnotation" in identifier && identifier.typeAnnotation !== void 0;
6227
6228
  }
6228
- function directPropertyBinding(context, declarator) {
6229
+ function directPropertyBinding(context, declarator, isEnumValue) {
6229
6230
  if (declarator.id.type !== "Identifier" || hasTypeAnnotation(declarator.id)) return void 0;
6230
6231
  if (declarator.init?.type !== "MemberExpression") return void 0;
6231
6232
  const member = declarator.init;
6233
+ if (isEnumValue(member.object)) return void 0;
6232
6234
  if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
6233
6235
  if (!memberCanBecomeLocal(member)) return void 0;
6234
6236
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
@@ -6289,6 +6291,37 @@ function memberCanBecomeLocal(member) {
6289
6291
  if (rootIdentifierName(member) === "locales") return false;
6290
6292
  return member.property.type === "Identifier" && isCompliantLocalName(member.property.name);
6291
6293
  }
6294
+ function isEnumDefinition(definition) {
6295
+ return typeof definition === "object" && definition !== null && "type" in definition && definition.type === "TSEnumName";
6296
+ }
6297
+ function localEnumBinding(context, node) {
6298
+ if (node.type !== "Identifier") return false;
6299
+ let scope = context.sourceCode.getScope(node);
6300
+ for (; ; ) {
6301
+ const variable = scope.variables.find(({ name }) => name === node.name);
6302
+ if (variable) return variable.defs.some(isEnumDefinition);
6303
+ if (scope.upper === null) return false;
6304
+ scope = scope.upper;
6305
+ }
6306
+ }
6307
+ function enumValueResolver(context) {
6308
+ const services = typedParserServices(context.sourceCode.parserServices);
6309
+ if (!services) return (node) => localEnumBinding(context, node);
6310
+ const checker = services.program.getTypeChecker();
6311
+ const { esTreeNodeToTSNodeMap: nodeMap } = services;
6312
+ const isEnumSymbol = (symbol) => {
6313
+ const resolved = symbol.flags === ts8.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
6314
+ return (resolved.declarations ?? []).some((declaration) => ts8.isEnumDeclaration(declaration));
6315
+ };
6316
+ return (node) => {
6317
+ const tsNode = nodeMap.get(node);
6318
+ if (!tsNode) return localEnumBinding(context, node);
6319
+ const symbol = checker.getSymbolAtLocation(tsNode);
6320
+ if (symbol && isEnumSymbol(symbol)) return true;
6321
+ const typeSymbol = checker.getTypeAtLocation(tsNode).getSymbol();
6322
+ return typeSymbol ? isEnumSymbol(typeSymbol) : localEnumBinding(context, node);
6323
+ };
6324
+ }
6292
6325
  function directMappingRequiresQualifiedAccess(context, ownershipResolver, member) {
6293
6326
  const mapping = renamedDirectMapping(context, member);
6294
6327
  if (!mapping || !ownershipResolver) return false;
@@ -6296,8 +6329,8 @@ function directMappingRequiresQualifiedAccess(context, ownershipResolver, member
6296
6329
  const targetResolution = ownershipResolver.targetProperty(mapping.property, mapping.targetName);
6297
6330
  return sourceResolution.kind === "data-contract" || targetResolution.kind === "data-contract";
6298
6331
  }
6299
- function memberCanBeDestructured(context, ownershipResolver, member) {
6300
- return memberCanBecomeLocal(member) && !directMappingRequiresQualifiedAccess(context, ownershipResolver, member);
6332
+ function memberCanBeDestructured(context, ownershipResolver, member, isEnumValue) {
6333
+ return !isEnumValue(member.object) && memberCanBecomeLocal(member) && !directMappingRequiresQualifiedAccess(context, ownershipResolver, member);
6301
6334
  }
6302
6335
  function objectUsage(scope, sourceText) {
6303
6336
  let usage = scope.objects.get(sourceText);
@@ -6322,9 +6355,9 @@ function memberIsDirectVariableInitializer(context, member) {
6322
6355
  const parent = context.sourceCode.getAncestors(member).at(-1);
6323
6356
  return parent?.type === "VariableDeclarator" && parent.init === member;
6324
6357
  }
6325
- function recordMemberUsage(context, scope, ownershipResolver, member) {
6358
+ function recordMemberUsage(context, scope, ownershipResolver, member, isEnumValue) {
6326
6359
  if (!scope || member.computed || member.optional || member.property.type !== "Identifier") return;
6327
- if (!memberCanBeDestructured(context, ownershipResolver, member)) return;
6360
+ if (!memberCanBeDestructured(context, ownershipResolver, member, isEnumValue)) return;
6328
6361
  if (!isGroupedUsageSource(member.object) || !memberIsRead(context, member)) return;
6329
6362
  const sourceText = context.sourceCode.getText(member.object);
6330
6363
  const usage = objectUsage(scope, sourceText);
@@ -6334,11 +6367,11 @@ function recordMemberUsage(context, scope, ownershipResolver, member) {
6334
6367
  usage.directMembers.push({ member, propertyName: propertyName5 });
6335
6368
  }
6336
6369
  }
6337
- function recordDestructuringUsage(context, scope, declaration) {
6370
+ function recordDestructuringUsage(context, scope, declaration, isEnumValue) {
6338
6371
  if (!scope) return;
6339
6372
  for (const declarator of declaration.declarations) {
6340
6373
  if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isGroupedUsageSource(declarator.init)) continue;
6341
- if (rootIdentifierName(declarator.init) === "locales") continue;
6374
+ if (rootIdentifierName(declarator.init) === "locales" || isEnumValue(declarator.init)) continue;
6342
6375
  const sourceText = context.sourceCode.getText(declarator.init);
6343
6376
  const usage = objectUsage(scope, sourceText);
6344
6377
  if (usage.directMembers.length > 0) continue;
@@ -6385,7 +6418,7 @@ function whitespaceKeepsStatementsAdjacent(text) {
6385
6418
  if (text.trim() !== "") return false;
6386
6419
  return (text.match(/\n/gu) ?? []).length <= 1;
6387
6420
  }
6388
- function groupedDeclarations(context, declaration, firstBinding) {
6421
+ function groupedDeclarations(context, declaration, firstBinding, isEnumValue) {
6389
6422
  if (declaration.declarations.length !== 1) {
6390
6423
  return [{ declaration, binding: firstBinding }];
6391
6424
  }
@@ -6405,7 +6438,7 @@ function groupedDeclarations(context, declaration, firstBinding) {
6405
6438
  if (nextNode.declarations.length !== 1) break;
6406
6439
  const nextDeclarator = nextNode.declarations[0];
6407
6440
  if (!nextDeclarator) break;
6408
- const nextBinding = directPropertyBinding(context, nextDeclarator);
6441
+ const nextBinding = directPropertyBinding(context, nextDeclarator, isEnumValue);
6409
6442
  if (nextBinding?.sourceText !== firstBinding.sourceText) break;
6410
6443
  if (seenProperties.has(nextBinding.propertyName)) break;
6411
6444
  const [, previousEnd] = context.sourceCode.getRange(previous);
@@ -6417,11 +6450,11 @@ function groupedDeclarations(context, declaration, firstBinding) {
6417
6450
  }
6418
6451
  return group;
6419
6452
  }
6420
- function destructuringSelection(context, declaration) {
6453
+ function destructuringSelection(context, declaration, isEnumValue) {
6421
6454
  if (declaration.declarations.length !== 1) return void 0;
6422
6455
  const declarator = declaration.declarations[0];
6423
6456
  if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
6424
- if (rootIdentifierName(declarator.init) === "locales") return void 0;
6457
+ if (rootIdentifierName(declarator.init) === "locales" || isEnumValue(declarator.init)) return void 0;
6425
6458
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
6426
6459
  const bindingTexts = [];
6427
6460
  const localNames = [];
@@ -6444,7 +6477,7 @@ function destructuringSelection(context, declaration) {
6444
6477
  propertyNames
6445
6478
  };
6446
6479
  }
6447
- function groupedDestructuringSelections(context, first) {
6480
+ function groupedDestructuringSelections(context, first, isEnumValue) {
6448
6481
  const parent = context.sourceCode.getAncestors(first.declaration).at(-1);
6449
6482
  if (parent?.type !== "Program" && parent?.type !== "BlockStatement") return [first];
6450
6483
  const body = parent.body;
@@ -6456,7 +6489,7 @@ function groupedDestructuringSelections(context, first) {
6456
6489
  const nextNode = body[index];
6457
6490
  const previous = group.at(-1)?.declaration;
6458
6491
  if (!previous || nextNode?.type !== "VariableDeclaration" || nextNode.kind !== first.declaration.kind) break;
6459
- const next = destructuringSelection(context, nextNode);
6492
+ const next = destructuringSelection(context, nextNode, isEnumValue);
6460
6493
  if (next?.sourceText !== first.sourceText) break;
6461
6494
  if (next.propertyNames.some((propertyName5) => seenProperties.has(propertyName5))) break;
6462
6495
  const [, previousEnd] = context.sourceCode.getRange(previous);
@@ -6497,6 +6530,7 @@ var preferObjectDestructuringRule = {
6497
6530
  },
6498
6531
  create(context) {
6499
6532
  const ownershipResolver = contractOwnershipResolver(context);
6533
+ const isEnumValue = enumValueResolver(context);
6500
6534
  const grouped = /* @__PURE__ */ new Set();
6501
6535
  const usageScopes = [];
6502
6536
  const currentUsageScope = () => usageScopes.at(-1);
@@ -6561,14 +6595,22 @@ ${indentation}`;
6561
6595
  ArrowFunctionExpression: enterUsageBarrier,
6562
6596
  "ArrowFunctionExpression:exit": exitUsageScope,
6563
6597
  MemberExpression(node) {
6564
- recordMemberUsage(context, currentUsageScope(), ownershipResolver, node);
6598
+ recordMemberUsage(context, currentUsageScope(), ownershipResolver, node, isEnumValue);
6565
6599
  },
6566
6600
  VariableDeclaration(node) {
6567
- recordDestructuringUsage(context, currentUsageScope(), node);
6601
+ for (const declarator of node.declarations) {
6602
+ if (declarator.id.type !== "ObjectPattern" || !declarator.init || !isEnumValue(declarator.init)) continue;
6603
+ const sourceText = context.sourceCode.getText(declarator.init);
6604
+ context.report({
6605
+ node: declarator.id,
6606
+ message: `"${sourceText}" is an enum. Keep enum member accesses qualified instead of destructuring it. ${DOC5}`
6607
+ });
6608
+ }
6609
+ recordDestructuringUsage(context, currentUsageScope(), node, isEnumValue);
6568
6610
  if (grouped.has(node)) return;
6569
- const selection = destructuringSelection(context, node);
6611
+ const selection = destructuringSelection(context, node, isEnumValue);
6570
6612
  if (selection) {
6571
- const group = groupedDestructuringSelections(context, selection);
6613
+ const group = groupedDestructuringSelections(context, selection, isEnumValue);
6572
6614
  if (group.length <= 1) return;
6573
6615
  for (const item of group.slice(1)) grouped.add(item.declaration);
6574
6616
  const lastDeclaration = group.at(-1)?.declaration;
@@ -6590,7 +6632,7 @@ ${indentation}`;
6590
6632
  });
6591
6633
  return;
6592
6634
  }
6593
- const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator)).filter((binding) => binding !== void 0);
6635
+ const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator, isEnumValue)).filter((binding) => binding !== void 0);
6594
6636
  if (bindings.length === 0) return;
6595
6637
  const firstBinding = bindings[0];
6596
6638
  if (!firstBinding) return;
@@ -6611,7 +6653,7 @@ ${indentation}`;
6611
6653
  return;
6612
6654
  }
6613
6655
  if (node.declarations.length === 1 && bindings.length === 1) {
6614
- const group = groupedDeclarations(context, node, firstBinding);
6656
+ const group = groupedDeclarations(context, node, firstBinding, isEnumValue);
6615
6657
  if (group.length > 1) {
6616
6658
  for (const item of group.slice(1)) grouped.add(item.declaration);
6617
6659
  const groupBindings = group.map(({ binding }) => binding);
@@ -7184,7 +7226,7 @@ var rootSupportPlacementRule = {
7184
7226
 
7185
7227
  // eslint/rules/route-handler-shape.ts
7186
7228
  import path48 from "path";
7187
- import ts8 from "typescript";
7229
+ import ts9 from "typescript";
7188
7230
  var HTTP_METHODS2 = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
7189
7231
  var REQUIRED_BOUNDARY = "withResponse";
7190
7232
  function isFunctionLike(node) {
@@ -7202,33 +7244,33 @@ function findHandler(node) {
7202
7244
  return void 0;
7203
7245
  }
7204
7246
  function isLoop(node) {
7205
- return ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
7247
+ return ts9.isForStatement(node) || ts9.isForOfStatement(node) || ts9.isForInStatement(node) || ts9.isWhileStatement(node) || ts9.isDoStatement(node);
7206
7248
  }
7207
7249
  function isFunctionBoundary(node) {
7208
- return ts8.isFunctionExpression(node) || ts8.isArrowFunction(node) || ts8.isFunctionDeclaration(node);
7250
+ return ts9.isFunctionExpression(node) || ts9.isArrowFunction(node) || ts9.isFunctionDeclaration(node);
7209
7251
  }
7210
7252
  function analyzeHandlerBody(body, sourceText) {
7211
7253
  const start = body.range?.[0] ?? 0;
7212
7254
  const end = body.range?.[1] ?? sourceText.length;
7213
- const sourceFile = ts8.createSourceFile(
7255
+ const sourceFile = ts9.createSourceFile(
7214
7256
  "route.ts",
7215
7257
  sourceText.slice(start, end),
7216
- ts8.ScriptTarget.Latest,
7258
+ ts9.ScriptTarget.Latest,
7217
7259
  true,
7218
- ts8.ScriptKind.TS
7260
+ ts9.ScriptKind.TS
7219
7261
  );
7220
7262
  const kinds = /* @__PURE__ */ new Set();
7221
7263
  const calledNames = /* @__PURE__ */ new Set();
7222
7264
  const visit = (node) => {
7223
- if (ts8.isTryStatement(node)) kinds.add("try");
7265
+ if (ts9.isTryStatement(node)) kinds.add("try");
7224
7266
  if (isLoop(node)) kinds.add("loop");
7225
- if (ts8.isIfStatement(node)) kinds.add("if");
7226
- if (ts8.isCallExpression(node) && ts8.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map") {
7267
+ if (ts9.isIfStatement(node)) kinds.add("if");
7268
+ if (ts9.isCallExpression(node) && ts9.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map") {
7227
7269
  kinds.add("map");
7228
7270
  }
7229
- if (ts8.isCallExpression(node) && ts8.isIdentifier(node.expression)) calledNames.add(node.expression.text);
7271
+ if (ts9.isCallExpression(node) && ts9.isIdentifier(node.expression)) calledNames.add(node.expression.text);
7230
7272
  if (isFunctionBoundary(node)) return;
7231
- ts8.forEachChild(node, visit);
7273
+ ts9.forEachChild(node, visit);
7232
7274
  };
7233
7275
  visit(sourceFile);
7234
7276
  return { kinds, calledNames };
@@ -7390,38 +7432,38 @@ var schemaCasingRule = {
7390
7432
 
7391
7433
  // eslint/rules/sole-state-owner.ts
7392
7434
  import path50 from "path";
7393
- import ts9 from "typescript";
7435
+ import ts10 from "typescript";
7394
7436
  function findStateHooks(node) {
7395
7437
  const hooks = [];
7396
7438
  const visit = (child) => {
7397
- if (ts9.isCallExpression(child) && ts9.isIdentifier(child.expression) && child.expression.text === "useState") {
7398
- if (ts9.isVariableDeclaration(child.parent)) {
7439
+ if (ts10.isCallExpression(child) && ts10.isIdentifier(child.expression) && child.expression.text === "useState") {
7440
+ if (ts10.isVariableDeclaration(child.parent)) {
7399
7441
  const { name } = child.parent;
7400
- if (ts9.isArrayBindingPattern(name) && name.elements.length >= 2) {
7442
+ if (ts10.isArrayBindingPattern(name) && name.elements.length >= 2) {
7401
7443
  const value = name.elements[0];
7402
7444
  const updater = name.elements[1];
7403
- if (value && updater && ts9.isBindingElement(value) && ts9.isBindingElement(updater)) {
7445
+ if (value && updater && ts10.isBindingElement(value) && ts10.isBindingElement(updater)) {
7404
7446
  const valueName = value.name;
7405
7447
  const updaterName = updater.name;
7406
- if (ts9.isIdentifier(valueName) && ts9.isIdentifier(updaterName)) {
7448
+ if (ts10.isIdentifier(valueName) && ts10.isIdentifier(updaterName)) {
7407
7449
  hooks.push({ value: valueName.text, updater: updaterName.text });
7408
7450
  }
7409
7451
  }
7410
7452
  }
7411
7453
  }
7412
7454
  }
7413
- ts9.forEachChild(child, visit);
7455
+ ts10.forEachChild(child, visit);
7414
7456
  };
7415
7457
  visit(node);
7416
7458
  return hooks;
7417
7459
  }
7418
7460
  function isHookUsage(node, hook) {
7419
- if (ts9.isCallExpression(node) && ts9.isIdentifier(node.expression) && node.expression.text === hook.updater) {
7461
+ if (ts10.isCallExpression(node) && ts10.isIdentifier(node.expression) && node.expression.text === hook.updater) {
7420
7462
  return "updater";
7421
7463
  }
7422
- if (ts9.isIdentifier(node) && node.text === hook.value) {
7464
+ if (ts10.isIdentifier(node) && node.text === hook.value) {
7423
7465
  const parent = node.parent;
7424
- if (ts9.isBindingElement(parent) || ts9.isPropertyAccessExpression(parent) || ts9.isShorthandPropertyAssignment(parent)) {
7466
+ if (ts10.isBindingElement(parent) || ts10.isPropertyAccessExpression(parent) || ts10.isShorthandPropertyAssignment(parent)) {
7425
7467
  return void 0;
7426
7468
  }
7427
7469
  return "value";
@@ -7431,16 +7473,16 @@ function isHookUsage(node, hook) {
7431
7473
  function topLevelJsxChildren(initial) {
7432
7474
  if (!initial) return void 0;
7433
7475
  let expression = initial;
7434
- while (ts9.isParenthesizedExpression(expression)) expression = expression.expression;
7435
- if (ts9.isJsxFragment(expression)) {
7476
+ while (ts10.isParenthesizedExpression(expression)) expression = expression.expression;
7477
+ if (ts10.isJsxFragment(expression)) {
7436
7478
  const children = expression.children.filter(
7437
- (c) => !ts9.isJsxText(c) && !ts9.isJsxSpreadAttribute(c)
7479
+ (c) => !ts10.isJsxText(c) && !ts10.isJsxSpreadAttribute(c)
7438
7480
  );
7439
7481
  return { root: expression, children };
7440
7482
  }
7441
- if (ts9.isJsxElement(expression)) {
7483
+ if (ts10.isJsxElement(expression)) {
7442
7484
  const children = expression.children.filter(
7443
- (c) => !ts9.isJsxText(c) && !ts9.isJsxSpreadAttribute(c)
7485
+ (c) => !ts10.isJsxText(c) && !ts10.isJsxSpreadAttribute(c)
7444
7486
  );
7445
7487
  return { root: expression, children };
7446
7488
  }
@@ -7454,8 +7496,8 @@ function collectUsesIn(child, hook) {
7454
7496
  positions.push(node);
7455
7497
  count += 1;
7456
7498
  }
7457
- if (ts9.isFunctionDeclaration(node) || ts9.isClassDeclaration(node)) return;
7458
- ts9.forEachChild(node, visit);
7499
+ if (ts10.isFunctionDeclaration(node) || ts10.isClassDeclaration(node)) return;
7500
+ ts10.forEachChild(node, visit);
7459
7501
  };
7460
7502
  visit(child);
7461
7503
  return { positions, count };
@@ -7494,18 +7536,18 @@ var soleStateOwnerRule = {
7494
7536
  }
7495
7537
  };
7496
7538
  function analyzeSoleOwner(declaration, hook) {
7497
- const body = ts9.isFunctionDeclaration(declaration) ? declaration.body : void 0;
7498
- if (!body || !ts9.isBlock(body)) return void 0;
7539
+ const body = ts10.isFunctionDeclaration(declaration) ? declaration.body : void 0;
7540
+ if (!body || !ts10.isBlock(body)) return void 0;
7499
7541
  const returns = [];
7500
7542
  const visit = (node) => {
7501
- if (node !== body && (ts9.isFunctionLike(node) || ts9.isClassLike(node))) return;
7502
- if (ts9.isReturnStatement(node)) returns.push(node);
7503
- ts9.forEachChild(node, visit);
7543
+ if (node !== body && (ts10.isFunctionLike(node) || ts10.isClassLike(node))) return;
7544
+ if (ts10.isReturnStatement(node)) returns.push(node);
7545
+ ts10.forEachChild(node, visit);
7504
7546
  };
7505
7547
  visit(body);
7506
7548
  if (returns.length !== 1) return void 0;
7507
7549
  const single = returns[0];
7508
- if (!single?.expression || !ts9.isExpression(single.expression)) return void 0;
7550
+ if (!single?.expression || !ts10.isExpression(single.expression)) return void 0;
7509
7551
  const returnExpression = single.expression;
7510
7552
  const root = topLevelJsxChildren(returnExpression);
7511
7553
  if (!root || root.children.length === 0) return void 0;
@@ -7528,11 +7570,11 @@ function usesOutsideJsx(declaration, hook, children) {
7528
7570
  let outside = false;
7529
7571
  const visit = (node) => {
7530
7572
  if (outside) return;
7531
- if (node !== declaration && (ts9.isFunctionDeclaration(node) || ts9.isClassDeclaration(node))) return;
7573
+ if (node !== declaration && (ts10.isFunctionDeclaration(node) || ts10.isClassDeclaration(node))) return;
7532
7574
  if (isHookUsage(node, hook)) {
7533
7575
  let current = node;
7534
7576
  let isInJsxChild = false;
7535
- while (!ts9.isSourceFile(current)) {
7577
+ while (!ts10.isSourceFile(current)) {
7536
7578
  if (children.includes(current)) {
7537
7579
  isInJsxChild = true;
7538
7580
  break;
@@ -7541,7 +7583,7 @@ function usesOutsideJsx(declaration, hook, children) {
7541
7583
  }
7542
7584
  if (!isInJsxChild) outside = true;
7543
7585
  }
7544
- ts9.forEachChild(node, visit);
7586
+ ts10.forEachChild(node, visit);
7545
7587
  };
7546
7588
  visit(declaration);
7547
7589
  return outside;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.84",
3
+ "version": "0.10.85",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",