pasika 0.10.60 → 0.10.62

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.
@@ -5027,10 +5027,93 @@ function objectPropertyMessage(propertyName4, source, identifierValue) {
5027
5027
  if (source === propertyName4) return `Use property shorthand for "${propertyName4}". ${DOC4}`;
5028
5028
  return `"${propertyName4}" maps the local "${source}" inline. Rename the producer to "${propertyName4}" and use property shorthand. ${DOC4}`;
5029
5029
  }
5030
+ function findVariable(context, node) {
5031
+ let scope = context.sourceCode.getScope(node);
5032
+ while (scope) {
5033
+ const variable = scope.set.get(node.name);
5034
+ if (variable) return variable;
5035
+ scope = scope.upper;
5036
+ }
5037
+ return void 0;
5038
+ }
5039
+ function isExportedVariable2(context, variable) {
5040
+ return variable.defs.some(
5041
+ (definition) => definition.type === "Variable" && context.sourceCode.getAncestors(definition.parent).at(-1)?.type === "ExportNamedDeclaration"
5042
+ );
5043
+ }
5044
+ function visibleVariable(context, node, name) {
5045
+ let scope = context.sourceCode.getScope(node);
5046
+ while (scope) {
5047
+ const variable = scope.set.get(name);
5048
+ if (variable) return variable;
5049
+ scope = scope.upper;
5050
+ }
5051
+ return void 0;
5052
+ }
5053
+ function canRenameIdentifierProducer(context, node, targetName) {
5054
+ const variable = findVariable(context, node);
5055
+ if (!variable || isExportedVariable2(context, variable)) return false;
5056
+ const targetVariable = visibleVariable(context, node, targetName);
5057
+ if (targetVariable && targetVariable !== variable) return false;
5058
+ const definition = variable.defs[0];
5059
+ if (!definition || variable.defs.length !== 1) return false;
5060
+ if (definition.type === "ImportBinding") return false;
5061
+ if (definition.type === "Variable" && definition.parent.kind !== "const") return false;
5062
+ if (definition.type !== "Variable" && definition.type !== "Parameter") return false;
5063
+ return variable.references.filter((reference) => reference.isRead()).length === 1;
5064
+ }
5065
+ function memberRootIdentifier(node) {
5066
+ let current = node;
5067
+ while (current.type === "MemberExpression") current = current.object;
5068
+ return current.type === "Identifier" ? current : void 0;
5069
+ }
5070
+ function canBindMemberExpression(context, node, targetName) {
5071
+ if (visibleVariable(context, node, targetName)) return false;
5072
+ const root = memberRootIdentifier(node);
5073
+ if (!root) return true;
5074
+ if (/^[A-Z]/u.test(root.name)) return false;
5075
+ const variable = findVariable(context, root);
5076
+ return !variable?.defs.some((definition) => definition.type === "ImportBinding");
5077
+ }
5078
+ function listStatement(node) {
5079
+ let current = node;
5080
+ while (current.parent && current.parent.type !== "Program" && current.parent.type !== "BlockStatement") {
5081
+ current = current.parent;
5082
+ }
5083
+ return current.parent ? current : void 0;
5084
+ }
5085
+ function identifierPropertyFixes(context, node, value, propertyName4, fixer) {
5086
+ if (value.name === propertyName4) return [fixer.replaceText(node, propertyName4)];
5087
+ const variable = findVariable(context, value);
5088
+ if (!variable) return [];
5089
+ return [
5090
+ ...variable.identifiers.map((identifier) => fixer.replaceText(identifier, propertyName4)),
5091
+ fixer.replaceText(node, propertyName4)
5092
+ ];
5093
+ }
5094
+ function memberPropertyFixes(context, node, value, propertyName4, source, fixer) {
5095
+ const statement = listStatement(node);
5096
+ if (!statement) return [];
5097
+ const root = memberRootIdentifier(value);
5098
+ const rootVariable = root ? findVariable(context, root) : void 0;
5099
+ if (rootVariable?.defs.some((definition) => {
5100
+ const [statementStart, statementEnd] = context.sourceCode.getRange(statement);
5101
+ const [definitionStart, definitionEnd] = context.sourceCode.getRange(definition.node);
5102
+ return definitionStart >= statementStart && definitionEnd <= statementEnd;
5103
+ })) {
5104
+ return [];
5105
+ }
5106
+ return [
5107
+ fixer.insertTextBefore(statement, `const ${propertyName4} = ${source};
5108
+ `),
5109
+ fixer.replaceText(node, propertyName4)
5110
+ ];
5111
+ }
5030
5112
  var noRedundantAliasRule = {
5031
5113
  meta: {
5032
5114
  schema: [],
5033
5115
  type: "problem",
5116
+ fixable: "code",
5034
5117
  docs: {
5035
5118
  description: "Disallow redundant aliases and inline identifier/member-expression object mappings."
5036
5119
  }
@@ -5053,11 +5136,20 @@ var noRedundantAliasRule = {
5053
5136
  if (node.parent.type !== "ObjectExpression" || node.computed || node.key.type !== "Identifier") return;
5054
5137
  if (node.value.type !== "Identifier" && node.value.type !== "MemberExpression") return;
5055
5138
  const propertyName4 = node.key.name;
5056
- const source = context.sourceCode.getText(node.value);
5057
- if (node.value.type === "Identifier" && node.shorthand) return;
5139
+ const propertyValue = node.value;
5140
+ const source = context.sourceCode.getText(propertyValue);
5141
+ if (propertyValue.type === "Identifier") {
5142
+ if (node.shorthand) return;
5143
+ if (source !== propertyName4 && !canRenameIdentifierProducer(context, propertyValue, propertyName4)) return;
5144
+ } else if (!canBindMemberExpression(context, propertyValue, propertyName4)) {
5145
+ return;
5146
+ }
5058
5147
  context.report({
5059
5148
  node,
5060
- message: objectPropertyMessage(propertyName4, source, node.value.type === "Identifier")
5149
+ message: objectPropertyMessage(propertyName4, source, propertyValue.type === "Identifier"),
5150
+ fix(fixer) {
5151
+ return propertyValue.type === "Identifier" ? identifierPropertyFixes(context, node, propertyValue, propertyName4, fixer) : memberPropertyFixes(context, node, propertyValue, propertyName4, source, fixer);
5152
+ }
5061
5153
  });
5062
5154
  },
5063
5155
  TSTypeAliasDeclaration(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.60",
3
+ "version": "0.10.62",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",