pasika 0.10.69 → 0.10.70

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.
@@ -5006,54 +5006,6 @@ var noMixedConcernsRule = {
5006
5006
  import path39 from "path";
5007
5007
  var DOC4 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
5008
5008
  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
5009
  var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
5058
5010
  var PRIMITIVE_TYPE_NAMES = {
5059
5011
  TSBigIntKeyword: "bigint",
@@ -5086,61 +5038,12 @@ function aliasMessage(alias, source) {
5086
5038
  const sourceName = source ?? "the original symbol";
5087
5039
  return `"${aliasName}" only renames "${sourceName}". Use "${sourceName}" directly or rename the original symbol and its consumers. ${DOC4}`;
5088
5040
  }
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;
5041
+ function bindingAliasMessage(alias, source) {
5042
+ return `"${alias}" renames "${source}" while creating a binding. Keep the original name and map it only at the object boundary. ${DOC4}`;
5136
5043
  }
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");
5044
+ function objectPropertyMessage(propertyName4, source) {
5045
+ if (source === propertyName4) return `Use property shorthand for "${propertyName4}". ${DOC4}`;
5046
+ return `"${propertyName4}" maps the local "${source}". Keep the local name or map directly from its source object instead. ${DOC4}`;
5144
5047
  }
5145
5048
  var noRedundantAliasRule = {
5146
5049
  meta: {
@@ -5148,41 +5051,68 @@ var noRedundantAliasRule = {
5148
5051
  type: "problem",
5149
5052
  fixable: "code",
5150
5053
  docs: {
5151
- description: "Disallow redundant aliases and inline identifier/member-expression object mappings."
5054
+ description: "Disallow renamed bindings while allowing explicit cross-object property mappings."
5152
5055
  }
5153
5056
  },
5154
5057
  create(context) {
5155
5058
  return {
5156
5059
  VariableDeclarator(node) {
5157
- if (node.id.type !== "Identifier" || node.init?.type !== "Identifier") return;
5060
+ if (node.id.type !== "Identifier" || !node.init) return;
5158
5061
  const declaration = node.parent;
5159
5062
  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;
5063
+ if (node.init.type === "Identifier") {
5064
+ const exported = declaration.parent.type === "ExportNamedDeclaration";
5065
+ const frameworkRouteAlias = path39.basename(context.filename) === "route.ts" && exported && HTTP_METHODS.has(node.id.name);
5066
+ if (frameworkRouteAlias || VALUE_SENTINELS.has(node.init.name)) return;
5067
+ context.report({
5068
+ node,
5069
+ message: aliasMessage(node.id.name, node.init.name)
5070
+ });
5071
+ return;
5072
+ }
5073
+ if (node.init.type !== "MemberExpression") return;
5074
+ let propertyName4;
5075
+ if (!node.init.computed && node.init.property.type === "Identifier") {
5076
+ propertyName4 = node.init.property.name;
5077
+ }
5078
+ if (node.init.computed && node.init.property.type === "Literal" && typeof node.init.property.value === "string") {
5079
+ propertyName4 = node.init.property.value;
5080
+ }
5081
+ if (propertyName4 === void 0 || propertyName4 === node.id.name) return;
5163
5082
  context.report({
5164
5083
  node,
5165
- message: aliasMessage(node.id.name, node.init.name)
5084
+ message: bindingAliasMessage(node.id.name, context.sourceCode.getText(node.init))
5166
5085
  });
5167
5086
  },
5168
5087
  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)) {
5088
+ if (node.computed) return;
5089
+ let propertyName4;
5090
+ if (node.key.type === "Identifier") propertyName4 = node.key.name;
5091
+ if (node.key.type === "Literal" && typeof node.key.value === "string") {
5092
+ propertyName4 = node.key.value;
5093
+ }
5094
+ if (propertyName4 === void 0) return;
5095
+ if (node.parent.type === "ObjectPattern") {
5096
+ let binding;
5097
+ if (node.value.type === "Identifier") binding = node.value;
5098
+ if (node.value.type === "AssignmentPattern" && node.value.left.type === "Identifier") {
5099
+ binding = node.value.left;
5100
+ }
5101
+ if (!binding || binding.name === propertyName4) return;
5102
+ context.report({
5103
+ node,
5104
+ message: bindingAliasMessage(binding.name, propertyName4)
5105
+ });
5179
5106
  return;
5180
5107
  }
5108
+ if (node.parent.type !== "ObjectExpression" || node.value.type !== "Identifier") return;
5109
+ if (node.shorthand) return;
5110
+ const source = node.value.name;
5181
5111
  context.report({
5182
5112
  node,
5183
- message: objectPropertyMessage(propertyName4, source, propertyValue.type === "Identifier"),
5113
+ message: objectPropertyMessage(propertyName4, source),
5184
5114
  fix(fixer) {
5185
- return propertyValue.type === "Identifier" && propertyValue.name === propertyName4 ? fixer.replaceText(node, propertyName4) : null;
5115
+ return propertyName4 === source ? fixer.replaceText(node, propertyName4) : null;
5186
5116
  }
5187
5117
  });
5188
5118
  },
@@ -5197,6 +5127,13 @@ var noRedundantAliasRule = {
5197
5127
  message: aliasMessage(node.id?.name, source)
5198
5128
  });
5199
5129
  },
5130
+ ImportSpecifier(node) {
5131
+ if (node.imported.type !== "Identifier" || node.imported.name === node.local.name) return;
5132
+ context.report({
5133
+ node,
5134
+ message: bindingAliasMessage(node.local.name, node.imported.name)
5135
+ });
5136
+ },
5200
5137
  ExportNamedDeclaration(node) {
5201
5138
  for (const specifier of node.specifiers) {
5202
5139
  if (specifier.local.type !== "Identifier" || specifier.exported.type !== "Identifier") continue;
@@ -5747,10 +5684,10 @@ function directPropertyBinding(context, declarator) {
5747
5684
  if (declarator.init?.type !== "MemberExpression") return void 0;
5748
5685
  const member = declarator.init;
5749
5686
  if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
5750
- if (!canGroupSource(member.object)) return void 0;
5751
5687
  if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
5752
5688
  const propertyName4 = member.property.name;
5753
5689
  const localName = declarator.id.name;
5690
+ if (propertyName4 !== localName) return void 0;
5754
5691
  const source = member.object;
5755
5692
  const sourceText = context.sourceCode.getText(source);
5756
5693
  return {
@@ -5760,7 +5697,7 @@ function directPropertyBinding(context, declarator) {
5760
5697
  localName,
5761
5698
  source,
5762
5699
  sourceText,
5763
- bindingText: propertyName4 === localName ? propertyName4 : `${propertyName4}: ${localName}`
5700
+ bindingText: propertyName4
5764
5701
  };
5765
5702
  }
5766
5703
  function canGroupSource(source) {
@@ -5771,7 +5708,7 @@ function whitespaceKeepsStatementsAdjacent(text) {
5771
5708
  return (text.match(/\n/gu) ?? []).length <= 1;
5772
5709
  }
5773
5710
  function groupedDeclarations(context, declaration, firstBinding) {
5774
- if (declaration.declarations.length !== 1 || !canGroupSource(firstBinding.source)) {
5711
+ if (declaration.declarations.length !== 1) {
5775
5712
  return [{ declaration, binding: firstBinding }];
5776
5713
  }
5777
5714
  const parent = context.sourceCode.getAncestors(declaration).at(-1);
@@ -5792,7 +5729,7 @@ function groupedDeclarations(context, declaration, firstBinding) {
5792
5729
  if (!nextDeclarator) break;
5793
5730
  const nextBinding = directPropertyBinding(context, nextDeclarator);
5794
5731
  if (nextBinding?.sourceText !== firstBinding.sourceText) break;
5795
- if (!canGroupSource(nextBinding.source) || seenProperties.has(nextBinding.propertyName)) break;
5732
+ if (seenProperties.has(nextBinding.propertyName)) break;
5796
5733
  const [, previousEnd] = context.sourceCode.getRange(previous);
5797
5734
  const [nextStart] = context.sourceCode.getRange(nextNode);
5798
5735
  const gap = context.sourceCode.text.slice(previousEnd, nextStart);
@@ -5802,6 +5739,56 @@ function groupedDeclarations(context, declaration, firstBinding) {
5802
5739
  }
5803
5740
  return group;
5804
5741
  }
5742
+ function destructuringSelection(context, declaration) {
5743
+ if (declaration.declarations.length !== 1) return void 0;
5744
+ const declarator = declaration.declarations[0];
5745
+ if (declarator?.id.type !== "ObjectPattern" || !declarator.init) return void 0;
5746
+ if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
5747
+ const bindingTexts = [];
5748
+ const localNames = [];
5749
+ const propertyNames = [];
5750
+ for (const property of declarator.id.properties) {
5751
+ if (property.type !== "Property" || property.computed || property.key.type !== "Identifier" || property.value.type !== "Identifier" || property.key.name !== property.value.name) {
5752
+ return void 0;
5753
+ }
5754
+ bindingTexts.push(context.sourceCode.getText(property));
5755
+ localNames.push(property.value.name);
5756
+ propertyNames.push(property.key.name);
5757
+ }
5758
+ if (bindingTexts.length === 0) return void 0;
5759
+ return {
5760
+ declaration,
5761
+ source: declarator.init,
5762
+ sourceText: context.sourceCode.getText(declarator.init),
5763
+ bindingTexts,
5764
+ localNames,
5765
+ propertyNames
5766
+ };
5767
+ }
5768
+ function groupedDestructuringSelections(context, first) {
5769
+ const parent = context.sourceCode.getAncestors(first.declaration).at(-1);
5770
+ if (parent?.type !== "Program" && parent?.type !== "BlockStatement") return [first];
5771
+ const body = parent.body;
5772
+ const startIndex = body.indexOf(first.declaration);
5773
+ if (startIndex < 0) return [first];
5774
+ const group = [first];
5775
+ const seenProperties = new Set(first.propertyNames);
5776
+ for (let index = startIndex + 1; index < body.length; index += 1) {
5777
+ const nextNode = body[index];
5778
+ const previous = group.at(-1)?.declaration;
5779
+ if (!previous || nextNode?.type !== "VariableDeclaration" || nextNode.kind !== first.declaration.kind) break;
5780
+ const next = destructuringSelection(context, nextNode);
5781
+ if (next?.sourceText !== first.sourceText) break;
5782
+ if (next.propertyNames.some((propertyName4) => seenProperties.has(propertyName4))) break;
5783
+ const [, previousEnd] = context.sourceCode.getRange(previous);
5784
+ const [nextStart] = context.sourceCode.getRange(nextNode);
5785
+ const gap = context.sourceCode.text.slice(previousEnd, nextStart);
5786
+ if (!whitespaceKeepsStatementsAdjacent(gap)) break;
5787
+ group.push(next);
5788
+ for (const propertyName4 of next.propertyNames) seenProperties.add(propertyName4);
5789
+ }
5790
+ return group;
5791
+ }
5805
5792
  function declarationTerminator(context, declaration) {
5806
5793
  return context.sourceCode.getText(declaration).trimEnd().endsWith(";") ? ";" : "";
5807
5794
  }
@@ -5810,9 +5797,15 @@ function singleMessage(binding) {
5810
5797
  }
5811
5798
  function groupMessage(bindings) {
5812
5799
  const firstBinding = bindings[0];
5813
- if (!firstBinding) return `Use object destructuring. ${DOC5}`;
5800
+ if (!firstBinding) return `Use one object destructuring declaration. ${DOC5}`;
5814
5801
  const names = bindings.map(({ localName }) => `"${localName}"`).join(", ");
5815
- return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use object destructuring. ${DOC5}`;
5802
+ return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use one object destructuring declaration. ${DOC5}`;
5803
+ }
5804
+ function repeatedDestructuringMessage(group) {
5805
+ const first = group[0];
5806
+ if (!first) return `Combine repeated destructuring into one declaration. ${DOC5}`;
5807
+ const names = group.flatMap(({ localNames }) => localNames).map((name) => `"${name}"`).join(", ");
5808
+ return `${names} destructure the same source "${first.sourceText}" repeatedly. Combine them into one object destructuring declaration. ${DOC5}`;
5816
5809
  }
5817
5810
  var preferObjectDestructuringRule = {
5818
5811
  meta: {
@@ -5828,10 +5821,50 @@ var preferObjectDestructuringRule = {
5828
5821
  return {
5829
5822
  VariableDeclaration(node) {
5830
5823
  if (grouped.has(node)) return;
5824
+ const selection = destructuringSelection(context, node);
5825
+ if (selection) {
5826
+ const group = groupedDestructuringSelections(context, selection);
5827
+ if (group.length <= 1) return;
5828
+ for (const item of group.slice(1)) grouped.add(item.declaration);
5829
+ const lastDeclaration = group.at(-1)?.declaration;
5830
+ if (!lastDeclaration) return;
5831
+ context.report({
5832
+ node,
5833
+ message: repeatedDestructuringMessage(group),
5834
+ fix(fixer) {
5835
+ if (!canGroupSource(selection.source)) return null;
5836
+ const [start] = context.sourceCode.getRange(node);
5837
+ const [, end] = context.sourceCode.getRange(lastDeclaration);
5838
+ const terminator = declarationTerminator(context, lastDeclaration);
5839
+ const pattern = group.flatMap(({ bindingTexts }) => bindingTexts).join(", ");
5840
+ return fixer.replaceTextRange(
5841
+ [start, end],
5842
+ `${node.kind} { ${pattern} } = ${selection.sourceText}${terminator}`
5843
+ );
5844
+ }
5845
+ });
5846
+ return;
5847
+ }
5831
5848
  const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator)).filter((binding) => binding !== void 0);
5832
5849
  if (bindings.length === 0) return;
5833
5850
  const firstBinding = bindings[0];
5834
5851
  if (!firstBinding) return;
5852
+ 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;
5853
+ if (sameSourceBindings) {
5854
+ context.report({
5855
+ node,
5856
+ message: groupMessage(bindings),
5857
+ fix(fixer) {
5858
+ if (!canGroupSource(firstBinding.source) || context.sourceCode.getCommentsInside(node).length > 0) {
5859
+ return null;
5860
+ }
5861
+ const terminator = declarationTerminator(context, node);
5862
+ const pattern = bindings.map(({ bindingText }) => bindingText).join(", ");
5863
+ return fixer.replaceText(node, `${node.kind} { ${pattern} } = ${firstBinding.sourceText}${terminator}`);
5864
+ }
5865
+ });
5866
+ return;
5867
+ }
5835
5868
  if (node.declarations.length === 1 && bindings.length === 1) {
5836
5869
  const group = groupedDeclarations(context, node, firstBinding);
5837
5870
  if (group.length > 1) {
@@ -5843,6 +5876,7 @@ var preferObjectDestructuringRule = {
5843
5876
  node,
5844
5877
  message: groupMessage(groupBindings),
5845
5878
  fix(fixer) {
5879
+ if (!canGroupSource(firstBinding.source)) return null;
5846
5880
  const [start] = context.sourceCode.getRange(node);
5847
5881
  const [, end] = context.sourceCode.getRange(lastDeclaration);
5848
5882
  const terminator = declarationTerminator(context, lastDeclaration);
@@ -5857,6 +5891,7 @@ var preferObjectDestructuringRule = {
5857
5891
  }
5858
5892
  }
5859
5893
  for (const binding of bindings) {
5894
+ if (!canGroupSource(binding.source)) continue;
5860
5895
  context.report({
5861
5896
  node: binding.declarator,
5862
5897
  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.70",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",