pasika 0.10.69 → 0.10.71

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.
@@ -44,6 +44,11 @@ function importedContractMember(expression, propertyName4, imports) {
44
44
  }
45
45
  return expression.object.name;
46
46
  }
47
+ function isImportedContractReference(expression, imports) {
48
+ if (expression.type === "Identifier") return imports.has(expression.name);
49
+ if (expression.type !== "MemberExpression" || expression.object.type !== "Identifier") return false;
50
+ return imports.has(expression.object.name);
51
+ }
47
52
  function responseSchemaParserContract(callee, imports) {
48
53
  if (callee.type === "Super" || callee.type !== "MemberExpression" || memberPropertyName(callee) !== "parse") {
49
54
  return void 0;
@@ -136,7 +141,7 @@ var apiContractRule = {
136
141
  const contractProperty = objectProperty(options, "contract");
137
142
  if (contractProperty) {
138
143
  const value = contractProperty.value;
139
- if (!(value.type === "Identifier" && imports.has(value.name))) {
144
+ if (!isImportedContractReference(value, imports)) {
140
145
  context.report({ node: value, message: CLIENT_CONTRACT });
141
146
  }
142
147
  return;
@@ -5006,54 +5011,6 @@ var noMixedConcernsRule = {
5006
5011
  import path39 from "path";
5007
5012
  var DOC4 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
5008
5013
  var VALUE_SENTINELS = /* @__PURE__ */ new Set(["undefined", "NaN", "Infinity"]);
5009
- var RESERVED_LOCAL_NAMES = /* @__PURE__ */ new Set([
5010
- "await",
5011
- "break",
5012
- "case",
5013
- "catch",
5014
- "class",
5015
- "const",
5016
- "continue",
5017
- "debugger",
5018
- "default",
5019
- "delete",
5020
- "do",
5021
- "else",
5022
- "enum",
5023
- "export",
5024
- "extends",
5025
- "false",
5026
- "finally",
5027
- "for",
5028
- "function",
5029
- "if",
5030
- "implements",
5031
- "import",
5032
- "in",
5033
- "instanceof",
5034
- "interface",
5035
- "let",
5036
- "new",
5037
- "null",
5038
- "package",
5039
- "private",
5040
- "protected",
5041
- "public",
5042
- "return",
5043
- "static",
5044
- "super",
5045
- "switch",
5046
- "this",
5047
- "throw",
5048
- "true",
5049
- "try",
5050
- "typeof",
5051
- "var",
5052
- "void",
5053
- "while",
5054
- "with",
5055
- "yield"
5056
- ]);
5057
5014
  var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
5058
5015
  var PRIMITIVE_TYPE_NAMES = {
5059
5016
  TSBigIntKeyword: "bigint",
@@ -5086,61 +5043,12 @@ function aliasMessage(alias, source) {
5086
5043
  const sourceName = source ?? "the original symbol";
5087
5044
  return `"${aliasName}" only renames "${sourceName}". Use "${sourceName}" directly or rename the original symbol and its consumers. ${DOC4}`;
5088
5045
  }
5089
- function objectPropertyMessage(propertyName4, source, identifierValue) {
5090
- if (!identifierValue) {
5091
- return `"${propertyName4}" maps "${source}" inline. Bind it as "${propertyName4}" before this object and use property shorthand. ${DOC4}`;
5092
- }
5093
- if (source === propertyName4) return `Use property shorthand for "${propertyName4}". ${DOC4}`;
5094
- return `"${propertyName4}" maps the local "${source}" inline. Rename the producer to "${propertyName4}" and use property shorthand. ${DOC4}`;
5095
- }
5096
- function findVariable(context, node) {
5097
- let scope = context.sourceCode.getScope(node);
5098
- while (scope) {
5099
- const variable = scope.set.get(node.name);
5100
- if (variable) return variable;
5101
- scope = scope.upper;
5102
- }
5103
- return void 0;
5104
- }
5105
- function isExportedVariable2(context, variable) {
5106
- return variable.defs.some(
5107
- (definition) => definition.type === "Variable" && context.sourceCode.getAncestors(definition.parent).at(-1)?.type === "ExportNamedDeclaration"
5108
- );
5109
- }
5110
- function canUsePropertyNameAsLocal(name) {
5111
- return /^[a-z][A-Za-z0-9]*$/u.test(name) && !RESERVED_LOCAL_NAMES.has(name);
5112
- }
5113
- function visibleVariable(context, node, name) {
5114
- let scope = context.sourceCode.getScope(node);
5115
- while (scope) {
5116
- const variable = scope.set.get(name);
5117
- if (variable) return variable;
5118
- scope = scope.upper;
5119
- }
5120
- return void 0;
5121
- }
5122
- function canRenameIdentifierProducer(context, node, targetName) {
5123
- const variable = findVariable(context, node);
5124
- if (!variable || isExportedVariable2(context, variable)) return false;
5125
- const targetVariable = visibleVariable(context, node, targetName);
5126
- if (targetVariable && targetVariable !== variable) return false;
5127
- const definition = variable.defs[0];
5128
- if (!definition || variable.defs.length !== 1) return false;
5129
- if (definition.type !== "Variable" || definition.parent.kind !== "const") return false;
5130
- return variable.references.filter((reference) => reference.isRead()).length === 1;
5131
- }
5132
- function memberRootIdentifier(node) {
5133
- let current = node;
5134
- while (current.type === "MemberExpression") current = current.object;
5135
- return current.type === "Identifier" ? current : void 0;
5046
+ function bindingAliasMessage(alias, source) {
5047
+ return `"${alias}" renames "${source}" while creating a binding. Keep the original name and map it only at the object boundary. ${DOC4}`;
5136
5048
  }
5137
- function canBindMemberExpression(context, node, targetName) {
5138
- if (visibleVariable(context, node, targetName)) return false;
5139
- const root = memberRootIdentifier(node);
5140
- if (!root) return true;
5141
- if (/^[A-Z]/u.test(root.name)) return false;
5142
- const variable = findVariable(context, root);
5143
- return !variable?.defs.some((definition) => definition.type === "ImportBinding");
5049
+ function objectPropertyMessage(propertyName4, source) {
5050
+ if (source === propertyName4) return `Use property shorthand for "${propertyName4}". ${DOC4}`;
5051
+ return `"${propertyName4}" maps the local "${source}". Keep the local name or map directly from its source object instead. ${DOC4}`;
5144
5052
  }
5145
5053
  var noRedundantAliasRule = {
5146
5054
  meta: {
@@ -5148,41 +5056,68 @@ var noRedundantAliasRule = {
5148
5056
  type: "problem",
5149
5057
  fixable: "code",
5150
5058
  docs: {
5151
- description: "Disallow redundant aliases and inline identifier/member-expression object mappings."
5059
+ description: "Disallow renamed bindings while allowing explicit cross-object property mappings."
5152
5060
  }
5153
5061
  },
5154
5062
  create(context) {
5155
5063
  return {
5156
5064
  VariableDeclarator(node) {
5157
- if (node.id.type !== "Identifier" || node.init?.type !== "Identifier") return;
5065
+ if (node.id.type !== "Identifier" || !node.init) return;
5158
5066
  const declaration = node.parent;
5159
5067
  if (declaration.type !== "VariableDeclaration" || declaration.kind !== "const") return;
5160
- const exported = declaration.parent.type === "ExportNamedDeclaration";
5161
- const frameworkRouteAlias = path39.basename(context.filename) === "route.ts" && exported && HTTP_METHODS.has(node.id.name);
5162
- if (frameworkRouteAlias || VALUE_SENTINELS.has(node.init.name)) return;
5068
+ if (node.init.type === "Identifier") {
5069
+ const exported = declaration.parent.type === "ExportNamedDeclaration";
5070
+ const frameworkRouteAlias = path39.basename(context.filename) === "route.ts" && exported && HTTP_METHODS.has(node.id.name);
5071
+ if (frameworkRouteAlias || VALUE_SENTINELS.has(node.init.name)) return;
5072
+ context.report({
5073
+ node,
5074
+ message: aliasMessage(node.id.name, node.init.name)
5075
+ });
5076
+ return;
5077
+ }
5078
+ if (node.init.type !== "MemberExpression") return;
5079
+ let propertyName4;
5080
+ if (!node.init.computed && node.init.property.type === "Identifier") {
5081
+ propertyName4 = node.init.property.name;
5082
+ }
5083
+ if (node.init.computed && node.init.property.type === "Literal" && typeof node.init.property.value === "string") {
5084
+ propertyName4 = node.init.property.value;
5085
+ }
5086
+ if (propertyName4 === void 0 || propertyName4 === node.id.name) return;
5163
5087
  context.report({
5164
5088
  node,
5165
- message: aliasMessage(node.id.name, node.init.name)
5089
+ message: bindingAliasMessage(node.id.name, context.sourceCode.getText(node.init))
5166
5090
  });
5167
5091
  },
5168
5092
  Property(node) {
5169
- if (node.parent.type !== "ObjectExpression" || node.computed || node.key.type !== "Identifier") return;
5170
- if (node.value.type !== "Identifier" && node.value.type !== "MemberExpression") return;
5171
- const propertyName4 = node.key.name;
5172
- if (!canUsePropertyNameAsLocal(propertyName4)) return;
5173
- const propertyValue = node.value;
5174
- const source = context.sourceCode.getText(propertyValue);
5175
- if (propertyValue.type === "Identifier") {
5176
- if (node.shorthand) return;
5177
- if (source !== propertyName4 && !canRenameIdentifierProducer(context, propertyValue, propertyName4)) return;
5178
- } else if (!canBindMemberExpression(context, propertyValue, propertyName4)) {
5093
+ if (node.computed) return;
5094
+ let propertyName4;
5095
+ if (node.key.type === "Identifier") propertyName4 = node.key.name;
5096
+ if (node.key.type === "Literal" && typeof node.key.value === "string") {
5097
+ propertyName4 = node.key.value;
5098
+ }
5099
+ if (propertyName4 === void 0) return;
5100
+ if (node.parent.type === "ObjectPattern") {
5101
+ let binding;
5102
+ if (node.value.type === "Identifier") binding = node.value;
5103
+ if (node.value.type === "AssignmentPattern" && node.value.left.type === "Identifier") {
5104
+ binding = node.value.left;
5105
+ }
5106
+ if (!binding || binding.name === propertyName4) return;
5107
+ context.report({
5108
+ node,
5109
+ message: bindingAliasMessage(binding.name, propertyName4)
5110
+ });
5179
5111
  return;
5180
5112
  }
5113
+ if (node.parent.type !== "ObjectExpression" || node.value.type !== "Identifier") return;
5114
+ if (node.shorthand) return;
5115
+ const source = node.value.name;
5181
5116
  context.report({
5182
5117
  node,
5183
- message: objectPropertyMessage(propertyName4, source, propertyValue.type === "Identifier"),
5118
+ message: objectPropertyMessage(propertyName4, source),
5184
5119
  fix(fixer) {
5185
- return propertyValue.type === "Identifier" && propertyValue.name === propertyName4 ? fixer.replaceText(node, propertyName4) : null;
5120
+ return propertyName4 === source ? fixer.replaceText(node, propertyName4) : null;
5186
5121
  }
5187
5122
  });
5188
5123
  },
@@ -5197,6 +5132,13 @@ var noRedundantAliasRule = {
5197
5132
  message: aliasMessage(node.id?.name, source)
5198
5133
  });
5199
5134
  },
5135
+ ImportSpecifier(node) {
5136
+ if (node.imported.type !== "Identifier" || node.imported.name === node.local.name) return;
5137
+ context.report({
5138
+ node,
5139
+ message: bindingAliasMessage(node.local.name, node.imported.name)
5140
+ });
5141
+ },
5200
5142
  ExportNamedDeclaration(node) {
5201
5143
  for (const specifier of node.specifiers) {
5202
5144
  if (specifier.local.type !== "Identifier" || specifier.exported.type !== "Identifier") continue;
@@ -5747,10 +5689,10 @@ function directPropertyBinding(context, declarator) {
5747
5689
  if (declarator.init?.type !== "MemberExpression") return void 0;
5748
5690
  const member = declarator.init;
5749
5691
  if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
5750
- if (!canGroupSource(member.object)) return void 0;
5751
5692
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
5752
5693
  const propertyName4 = member.property.name;
5753
5694
  const localName = declarator.id.name;
5695
+ if (propertyName4 !== localName) return void 0;
5754
5696
  const source = member.object;
5755
5697
  const sourceText = context.sourceCode.getText(source);
5756
5698
  return {
@@ -5760,7 +5702,7 @@ function directPropertyBinding(context, declarator) {
5760
5702
  localName,
5761
5703
  source,
5762
5704
  sourceText,
5763
- bindingText: propertyName4 === localName ? propertyName4 : `${propertyName4}: ${localName}`
5705
+ bindingText: propertyName4
5764
5706
  };
5765
5707
  }
5766
5708
  function canGroupSource(source) {
@@ -5771,7 +5713,7 @@ function whitespaceKeepsStatementsAdjacent(text) {
5771
5713
  return (text.match(/\n/gu) ?? []).length <= 1;
5772
5714
  }
5773
5715
  function groupedDeclarations(context, declaration, firstBinding) {
5774
- if (declaration.declarations.length !== 1 || !canGroupSource(firstBinding.source)) {
5716
+ if (declaration.declarations.length !== 1) {
5775
5717
  return [{ declaration, binding: firstBinding }];
5776
5718
  }
5777
5719
  const parent = context.sourceCode.getAncestors(declaration).at(-1);
@@ -5792,7 +5734,7 @@ function groupedDeclarations(context, declaration, firstBinding) {
5792
5734
  if (!nextDeclarator) break;
5793
5735
  const nextBinding = directPropertyBinding(context, nextDeclarator);
5794
5736
  if (nextBinding?.sourceText !== firstBinding.sourceText) break;
5795
- if (!canGroupSource(nextBinding.source) || seenProperties.has(nextBinding.propertyName)) break;
5737
+ if (seenProperties.has(nextBinding.propertyName)) break;
5796
5738
  const [, previousEnd] = context.sourceCode.getRange(previous);
5797
5739
  const [nextStart] = context.sourceCode.getRange(nextNode);
5798
5740
  const gap = context.sourceCode.text.slice(previousEnd, nextStart);
@@ -5802,6 +5744,56 @@ function groupedDeclarations(context, declaration, firstBinding) {
5802
5744
  }
5803
5745
  return group;
5804
5746
  }
5747
+ function destructuringSelection(context, declaration) {
5748
+ if (declaration.declarations.length !== 1) return void 0;
5749
+ const declarator = declaration.declarations[0];
5750
+ if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
5751
+ if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
5752
+ const bindingTexts = [];
5753
+ const localNames = [];
5754
+ const propertyNames = [];
5755
+ for (const property of declarator.id.properties) {
5756
+ if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
5757
+ return void 0;
5758
+ }
5759
+ bindingTexts.push(context.sourceCode.getText(property));
5760
+ localNames.push(property.value.name);
5761
+ propertyNames.push(property.key.name);
5762
+ }
5763
+ if (bindingTexts.length === 0) return void 0;
5764
+ return {
5765
+ declaration,
5766
+ source: declarator.init,
5767
+ sourceText: context.sourceCode.getText(declarator.init),
5768
+ bindingTexts,
5769
+ localNames,
5770
+ propertyNames
5771
+ };
5772
+ }
5773
+ function groupedDestructuringSelections(context, first) {
5774
+ const parent = context.sourceCode.getAncestors(first.declaration).at(-1);
5775
+ if (parent?.type !== "Program" && parent?.type !== "BlockStatement") return [first];
5776
+ const body = parent.body;
5777
+ const startIndex = body.indexOf(first.declaration);
5778
+ if (startIndex < 0) return [first];
5779
+ const group = [first];
5780
+ const seenProperties = new Set(first.propertyNames);
5781
+ for (let index = startIndex + 1; index < body.length; index += 1) {
5782
+ const nextNode = body[index];
5783
+ const previous = group.at(-1)?.declaration;
5784
+ if (!previous || nextNode?.type !== "VariableDeclaration" || nextNode.kind !== first.declaration.kind) break;
5785
+ const next = destructuringSelection(context, nextNode);
5786
+ if (next?.sourceText !== first.sourceText) break;
5787
+ if (next.propertyNames.some((propertyName4) => seenProperties.has(propertyName4))) break;
5788
+ const [, previousEnd] = context.sourceCode.getRange(previous);
5789
+ const [nextStart] = context.sourceCode.getRange(nextNode);
5790
+ const gap = context.sourceCode.text.slice(previousEnd, nextStart);
5791
+ if (!whitespaceKeepsStatementsAdjacent(gap)) break;
5792
+ group.push(next);
5793
+ for (const propertyName4 of next.propertyNames) seenProperties.add(propertyName4);
5794
+ }
5795
+ return group;
5796
+ }
5805
5797
  function declarationTerminator(context, declaration) {
5806
5798
  return context.sourceCode.getText(declaration).trimEnd().endsWith(";") ? ";" : "";
5807
5799
  }
@@ -5810,9 +5802,15 @@ function singleMessage(binding) {
5810
5802
  }
5811
5803
  function groupMessage(bindings) {
5812
5804
  const firstBinding = bindings[0];
5813
- if (!firstBinding) return `Use object destructuring. ${DOC5}`;
5805
+ if (!firstBinding) return `Use one object destructuring declaration. ${DOC5}`;
5814
5806
  const names = bindings.map(({ localName }) => `"${localName}"`).join(", ");
5815
- return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use object destructuring. ${DOC5}`;
5807
+ return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use one object destructuring declaration. ${DOC5}`;
5808
+ }
5809
+ function repeatedDestructuringMessage(group) {
5810
+ const first = group[0];
5811
+ if (!first) return `Combine repeated destructuring into one declaration. ${DOC5}`;
5812
+ const names = group.flatMap(({ localNames }) => localNames).map((name) => `"${name}"`).join(", ");
5813
+ return `${names} destructure the same source "${first.sourceText}" repeatedly. Combine them into one object destructuring declaration. ${DOC5}`;
5816
5814
  }
5817
5815
  var preferObjectDestructuringRule = {
5818
5816
  meta: {
@@ -5828,10 +5826,50 @@ var preferObjectDestructuringRule = {
5828
5826
  return {
5829
5827
  VariableDeclaration(node) {
5830
5828
  if (grouped.has(node)) return;
5829
+ const selection = destructuringSelection(context, node);
5830
+ if (selection) {
5831
+ const group = groupedDestructuringSelections(context, selection);
5832
+ if (group.length <= 1) return;
5833
+ for (const item of group.slice(1)) grouped.add(item.declaration);
5834
+ const lastDeclaration = group.at(-1)?.declaration;
5835
+ if (!lastDeclaration) return;
5836
+ context.report({
5837
+ node,
5838
+ message: repeatedDestructuringMessage(group),
5839
+ fix(fixer) {
5840
+ if (!canGroupSource(selection.source)) return null;
5841
+ const [start] = context.sourceCode.getRange(node);
5842
+ const [, end] = context.sourceCode.getRange(lastDeclaration);
5843
+ const terminator = declarationTerminator(context, lastDeclaration);
5844
+ const pattern = group.flatMap(({ bindingTexts }) => bindingTexts).join(", ");
5845
+ return fixer.replaceTextRange(
5846
+ [start, end],
5847
+ `${node.kind} { ${pattern} } = ${selection.sourceText}${terminator}`
5848
+ );
5849
+ }
5850
+ });
5851
+ return;
5852
+ }
5831
5853
  const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator)).filter((binding) => binding !== void 0);
5832
5854
  if (bindings.length === 0) return;
5833
5855
  const firstBinding = bindings[0];
5834
5856
  if (!firstBinding) return;
5857
+ const sameSourceBindings = bindings.length > 1 && bindings.length === node.declarations.length && bindings.every(({ sourceText }) => sourceText === firstBinding.sourceText) && new Set(bindings.map(({ propertyName: propertyName4 }) => propertyName4)).size === bindings.length;
5858
+ if (sameSourceBindings) {
5859
+ context.report({
5860
+ node,
5861
+ message: groupMessage(bindings),
5862
+ fix(fixer) {
5863
+ if (!canGroupSource(firstBinding.source) || context.sourceCode.getCommentsInside(node).length > 0) {
5864
+ return null;
5865
+ }
5866
+ const terminator = declarationTerminator(context, node);
5867
+ const pattern = bindings.map(({ bindingText }) => bindingText).join(", ");
5868
+ return fixer.replaceText(node, `${node.kind} { ${pattern} } = ${firstBinding.sourceText}${terminator}`);
5869
+ }
5870
+ });
5871
+ return;
5872
+ }
5835
5873
  if (node.declarations.length === 1 && bindings.length === 1) {
5836
5874
  const group = groupedDeclarations(context, node, firstBinding);
5837
5875
  if (group.length > 1) {
@@ -5843,6 +5881,7 @@ var preferObjectDestructuringRule = {
5843
5881
  node,
5844
5882
  message: groupMessage(groupBindings),
5845
5883
  fix(fixer) {
5884
+ if (!canGroupSource(firstBinding.source)) return null;
5846
5885
  const [start] = context.sourceCode.getRange(node);
5847
5886
  const [, end] = context.sourceCode.getRange(lastDeclaration);
5848
5887
  const terminator = declarationTerminator(context, lastDeclaration);
@@ -5857,6 +5896,7 @@ var preferObjectDestructuringRule = {
5857
5896
  }
5858
5897
  }
5859
5898
  for (const binding of bindings) {
5899
+ if (!canGroupSource(binding.source)) continue;
5860
5900
  context.report({
5861
5901
  node: binding.declarator,
5862
5902
  message: singleMessage(binding),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.69",
3
+ "version": "0.10.71",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",