pasika 0.10.64 → 0.10.66

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.
@@ -210,6 +210,7 @@ declare const pasikaPlugin: {
210
210
  "value-extraction": eslint.Rule.RuleModule;
211
211
  "constant-casing": eslint.Rule.RuleModule;
212
212
  "prefer-enum": eslint.Rule.RuleModule;
213
+ "prefer-object-destructuring": eslint.Rule.RuleModule;
213
214
  "enum-placement": eslint.Rule.RuleModule;
214
215
  "type-extraction": eslint.Rule.RuleModule;
215
216
  "zod-schema-validation": eslint.Rule.RuleModule;
@@ -5108,9 +5108,7 @@ function canRenameIdentifierProducer(context, node, targetName) {
5108
5108
  if (targetVariable && targetVariable !== variable) return false;
5109
5109
  const definition = variable.defs[0];
5110
5110
  if (!definition || variable.defs.length !== 1) return false;
5111
- if (definition.type === "ImportBinding") return false;
5112
- if (definition.type === "Variable" && definition.parent.kind !== "const") return false;
5113
- if (definition.type !== "Variable" && definition.type !== "Parameter") return false;
5111
+ if (definition.type !== "Variable" || definition.parent.kind !== "const") return false;
5114
5112
  return variable.references.filter((reference) => reference.isRead()).length === 1;
5115
5113
  }
5116
5114
  function memberRootIdentifier(node) {
@@ -5126,40 +5124,6 @@ function canBindMemberExpression(context, node, targetName) {
5126
5124
  const variable = findVariable(context, root);
5127
5125
  return !variable?.defs.some((definition) => definition.type === "ImportBinding");
5128
5126
  }
5129
- function listStatement(node) {
5130
- let current = node;
5131
- while (current.parent && current.parent.type !== "Program" && current.parent.type !== "BlockStatement") {
5132
- current = current.parent;
5133
- }
5134
- return current.parent ? current : void 0;
5135
- }
5136
- function identifierPropertyFixes(context, node, value, propertyName4, fixer) {
5137
- if (value.name === propertyName4) return [fixer.replaceText(node, propertyName4)];
5138
- const variable = findVariable(context, value);
5139
- const definition = variable?.defs[0];
5140
- if (variable?.defs.length !== 1 || definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.id.type !== "Identifier") {
5141
- return [];
5142
- }
5143
- return [fixer.replaceText(definition.node.id, propertyName4), fixer.replaceText(node, propertyName4)];
5144
- }
5145
- function memberPropertyFixes(context, node, value, propertyName4, source, fixer) {
5146
- const statement = listStatement(node);
5147
- if (!statement) return [];
5148
- const root = memberRootIdentifier(value);
5149
- const rootVariable = root ? findVariable(context, root) : void 0;
5150
- if (rootVariable?.defs.some((definition) => {
5151
- const [statementStart, statementEnd] = context.sourceCode.getRange(statement);
5152
- const [definitionStart, definitionEnd] = context.sourceCode.getRange(definition.node);
5153
- return definitionStart >= statementStart && definitionEnd <= statementEnd;
5154
- })) {
5155
- return [];
5156
- }
5157
- return [
5158
- fixer.insertTextBefore(statement, `const ${propertyName4} = ${source};
5159
- `),
5160
- fixer.replaceText(node, propertyName4)
5161
- ];
5162
- }
5163
5127
  var noRedundantAliasRule = {
5164
5128
  meta: {
5165
5129
  schema: [],
@@ -5200,7 +5164,7 @@ var noRedundantAliasRule = {
5200
5164
  node,
5201
5165
  message: objectPropertyMessage(propertyName4, source, propertyValue.type === "Identifier"),
5202
5166
  fix(fixer) {
5203
- return propertyValue.type === "Identifier" ? identifierPropertyFixes(context, node, propertyValue, propertyName4, fixer) : memberPropertyFixes(context, node, propertyValue, propertyName4, source, fixer);
5167
+ return propertyValue.type === "Identifier" && propertyValue.name === propertyName4 ? fixer.replaceText(node, propertyName4) : null;
5204
5168
  }
5205
5169
  });
5206
5170
  },
@@ -5755,6 +5719,140 @@ var preferEnumRule = {
5755
5719
  }
5756
5720
  };
5757
5721
 
5722
+ // eslint/rules/prefer-object-destructuring.ts
5723
+ var DOC5 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
5724
+ function hasTypeAnnotation(identifier) {
5725
+ return "typeAnnotation" in identifier && identifier.typeAnnotation !== void 0;
5726
+ }
5727
+ function directPropertyBinding(context, declarator) {
5728
+ if (declarator.id.type !== "Identifier" || hasTypeAnnotation(declarator.id)) return void 0;
5729
+ if (declarator.init?.type !== "MemberExpression") return void 0;
5730
+ const member = declarator.init;
5731
+ if (member.computed || member.optional || member.property.type !== "Identifier" || member.object.type === "Super") {
5732
+ return void 0;
5733
+ }
5734
+ if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
5735
+ const propertyName4 = member.property.name;
5736
+ const localName = declarator.id.name;
5737
+ const source = member.object;
5738
+ const sourceText = context.sourceCode.getText(source);
5739
+ return {
5740
+ declarator,
5741
+ member,
5742
+ propertyName: propertyName4,
5743
+ localName,
5744
+ source,
5745
+ sourceText,
5746
+ bindingText: propertyName4 === localName ? propertyName4 : `${propertyName4}: ${localName}`
5747
+ };
5748
+ }
5749
+ function canGroupSource(source) {
5750
+ return source.type === "Identifier" || source.type === "ThisExpression";
5751
+ }
5752
+ function whitespaceKeepsStatementsAdjacent(text) {
5753
+ if (text.trim() !== "") return false;
5754
+ return (text.match(/\n/gu) ?? []).length <= 1;
5755
+ }
5756
+ function groupedDeclarations(context, declaration, firstBinding) {
5757
+ if (declaration.declarations.length !== 1 || !canGroupSource(firstBinding.source)) {
5758
+ return [{ declaration, binding: firstBinding }];
5759
+ }
5760
+ const parent = context.sourceCode.getAncestors(declaration).at(-1);
5761
+ if (parent?.type !== "Program" && parent?.type !== "BlockStatement") {
5762
+ return [{ declaration, binding: firstBinding }];
5763
+ }
5764
+ const body = parent.body;
5765
+ const startIndex = body.indexOf(declaration);
5766
+ if (startIndex < 0) return [{ declaration, binding: firstBinding }];
5767
+ const group = [{ declaration, binding: firstBinding }];
5768
+ const seenProperties = /* @__PURE__ */ new Set([firstBinding.propertyName]);
5769
+ for (let index = startIndex + 1; index < body.length; index += 1) {
5770
+ const nextNode = body[index];
5771
+ const previous = group.at(-1)?.declaration;
5772
+ if (!previous || nextNode?.type !== "VariableDeclaration" || nextNode.kind !== declaration.kind) break;
5773
+ if (nextNode.declarations.length !== 1) break;
5774
+ const nextDeclarator = nextNode.declarations[0];
5775
+ if (!nextDeclarator) break;
5776
+ const nextBinding = directPropertyBinding(context, nextDeclarator);
5777
+ if (nextBinding?.sourceText !== firstBinding.sourceText) break;
5778
+ if (!canGroupSource(nextBinding.source) || seenProperties.has(nextBinding.propertyName)) break;
5779
+ const [, previousEnd] = context.sourceCode.getRange(previous);
5780
+ const [nextStart] = context.sourceCode.getRange(nextNode);
5781
+ const gap = context.sourceCode.text.slice(previousEnd, nextStart);
5782
+ if (!whitespaceKeepsStatementsAdjacent(gap)) break;
5783
+ group.push({ declaration: nextNode, binding: nextBinding });
5784
+ seenProperties.add(nextBinding.propertyName);
5785
+ }
5786
+ return group;
5787
+ }
5788
+ function declarationTerminator(context, declaration) {
5789
+ return context.sourceCode.getText(declaration).trimEnd().endsWith(";") ? ";" : "";
5790
+ }
5791
+ function singleMessage(binding) {
5792
+ return `"${binding.localName}" is derived directly from "${binding.sourceText}.${binding.propertyName}". Use object destructuring. ${DOC5}`;
5793
+ }
5794
+ function groupMessage(bindings) {
5795
+ const firstBinding = bindings[0];
5796
+ if (!firstBinding) return `Use object destructuring. ${DOC5}`;
5797
+ const names = bindings.map(({ localName }) => `"${localName}"`).join(", ");
5798
+ return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use object destructuring. ${DOC5}`;
5799
+ }
5800
+ var preferObjectDestructuringRule = {
5801
+ meta: {
5802
+ schema: [],
5803
+ type: "problem",
5804
+ fixable: "code",
5805
+ docs: {
5806
+ description: "Require locals derived directly from object properties to use object destructuring."
5807
+ }
5808
+ },
5809
+ create(context) {
5810
+ const grouped = /* @__PURE__ */ new Set();
5811
+ return {
5812
+ VariableDeclaration(node) {
5813
+ if (grouped.has(node)) return;
5814
+ const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator)).filter((binding) => binding !== void 0);
5815
+ if (bindings.length === 0) return;
5816
+ const firstBinding = bindings[0];
5817
+ if (!firstBinding) return;
5818
+ if (node.declarations.length === 1 && bindings.length === 1) {
5819
+ const group = groupedDeclarations(context, node, firstBinding);
5820
+ if (group.length > 1) {
5821
+ for (const item of group.slice(1)) grouped.add(item.declaration);
5822
+ const groupBindings = group.map(({ binding }) => binding);
5823
+ const lastDeclaration = group.at(-1)?.declaration;
5824
+ if (!lastDeclaration) return;
5825
+ context.report({
5826
+ node,
5827
+ message: groupMessage(groupBindings),
5828
+ fix(fixer) {
5829
+ const [start] = context.sourceCode.getRange(node);
5830
+ const [, end] = context.sourceCode.getRange(lastDeclaration);
5831
+ const terminator = declarationTerminator(context, lastDeclaration);
5832
+ const pattern = groupBindings.map(({ bindingText }) => bindingText).join(", ");
5833
+ return fixer.replaceTextRange(
5834
+ [start, end],
5835
+ `${node.kind} { ${pattern} } = ${firstBinding.sourceText}${terminator}`
5836
+ );
5837
+ }
5838
+ });
5839
+ return;
5840
+ }
5841
+ }
5842
+ for (const binding of bindings) {
5843
+ context.report({
5844
+ node: binding.declarator,
5845
+ message: singleMessage(binding),
5846
+ fix(fixer) {
5847
+ return fixer.replaceText(binding.declarator, `{ ${binding.bindingText} } = ${binding.sourceText}`);
5848
+ }
5849
+ });
5850
+ }
5851
+ }
5852
+ };
5853
+ }
5854
+ };
5855
+
5758
5856
  // eslint/rules/pure-function-extract.ts
5759
5857
  import path43 from "path";
5760
5858
  var ROUTE_HANDLER_EXPORT_NAMES = /* @__PURE__ */ new Set([
@@ -8565,9 +8663,9 @@ var vulykRules = {
8565
8663
  // eslint/rules/with-response-helper.ts
8566
8664
  var HELPER3 = "withResponse";
8567
8665
  var ENTRY3 = "pasika/with-response";
8568
- var DOC5 = "docs/pasika-adoption-guide/rules/with-response-helper-rule.md";
8569
- var DECLARED3 = `A repository must not declare its own ${HELPER3}; import it from ${ENTRY3}. See ${DOC5}`;
8570
- var IMPORTED3 = `${HELPER3} must be imported from ${ENTRY3}. See ${DOC5}`;
8666
+ var DOC6 = "docs/pasika-adoption-guide/rules/with-response-helper-rule.md";
8667
+ var DECLARED3 = `A repository must not declare its own ${HELPER3}; import it from ${ENTRY3}. See ${DOC6}`;
8668
+ var IMPORTED3 = `${HELPER3} must be imported from ${ENTRY3}. See ${DOC6}`;
8571
8669
  function isNamed3(node, name) {
8572
8670
  return node?.type === "Identifier" && node.name === name;
8573
8671
  }
@@ -8688,10 +8786,10 @@ function referencesZirka(sourceCode) {
8688
8786
  // eslint/rules/zod-fetch-helper.ts
8689
8787
  var HELPER4 = "zodFetch";
8690
8788
  var ENTRY4 = "pasika/zod-fetch";
8691
- var DOC6 = "docs/pasika-adoption-guide/rules/zod-fetch-helper-rule.md";
8692
- var FETCHED = `fetch must not be called; make the request through ${HELPER4} from ${ENTRY4}. See ${DOC6}`;
8693
- var DECLARED4 = `A file must not declare its own ${HELPER4}; import it from ${ENTRY4}. See ${DOC6}`;
8694
- var IMPORTED4 = `${HELPER4} must be imported from ${ENTRY4}. See ${DOC6}`;
8789
+ var DOC7 = "docs/pasika-adoption-guide/rules/zod-fetch-helper-rule.md";
8790
+ var FETCHED = `fetch must not be called; make the request through ${HELPER4} from ${ENTRY4}. See ${DOC7}`;
8791
+ var DECLARED4 = `A file must not declare its own ${HELPER4}; import it from ${ENTRY4}. See ${DOC7}`;
8792
+ var IMPORTED4 = `${HELPER4} must be imported from ${ENTRY4}. See ${DOC7}`;
8695
8793
  var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "window", "self", "global"]);
8696
8794
  var TEST_FILE2 = /(?:^|[\\/])(?:__tests__|tests)[\\/]|[.](?:test|spec)[.][cm]?[jt]sx?$/;
8697
8795
  function isNamed4(node, name) {
@@ -8878,6 +8976,7 @@ var pasikaNextjsAppRules = {
8878
8976
  "value-extraction": valueExtractionRule,
8879
8977
  "constant-casing": constantCasingRule,
8880
8978
  "prefer-enum": preferEnumRule,
8979
+ "prefer-object-destructuring": preferObjectDestructuringRule,
8881
8980
  "enum-placement": enumPlacementRule,
8882
8981
  "type-extraction": typeExtractionRule,
8883
8982
  "zod-schema-validation": zodSchemaValidationRule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.64",
3
+ "version": "0.10.66",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",