pasika 0.10.61 → 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.
@@ -5041,9 +5041,20 @@ function isExportedVariable2(context, variable) {
5041
5041
  (definition) => definition.type === "Variable" && context.sourceCode.getAncestors(definition.parent).at(-1)?.type === "ExportNamedDeclaration"
5042
5042
  );
5043
5043
  }
5044
- function canRenameIdentifierProducer(context, node) {
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) {
5045
5054
  const variable = findVariable(context, node);
5046
5055
  if (!variable || isExportedVariable2(context, variable)) return false;
5056
+ const targetVariable = visibleVariable(context, node, targetName);
5057
+ if (targetVariable && targetVariable !== variable) return false;
5047
5058
  const definition = variable.defs[0];
5048
5059
  if (!definition || variable.defs.length !== 1) return false;
5049
5060
  if (definition.type === "ImportBinding") return false;
@@ -5056,17 +5067,53 @@ function memberRootIdentifier(node) {
5056
5067
  while (current.type === "MemberExpression") current = current.object;
5057
5068
  return current.type === "Identifier" ? current : void 0;
5058
5069
  }
5059
- function canBindMemberExpression(context, node) {
5070
+ function canBindMemberExpression(context, node, targetName) {
5071
+ if (visibleVariable(context, node, targetName)) return false;
5060
5072
  const root = memberRootIdentifier(node);
5061
5073
  if (!root) return true;
5062
5074
  if (/^[A-Z]/u.test(root.name)) return false;
5063
5075
  const variable = findVariable(context, root);
5064
5076
  return !variable?.defs.some((definition) => definition.type === "ImportBinding");
5065
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
+ }
5066
5112
  var noRedundantAliasRule = {
5067
5113
  meta: {
5068
5114
  schema: [],
5069
5115
  type: "problem",
5116
+ fixable: "code",
5070
5117
  docs: {
5071
5118
  description: "Disallow redundant aliases and inline identifier/member-expression object mappings."
5072
5119
  }
@@ -5089,16 +5136,20 @@ var noRedundantAliasRule = {
5089
5136
  if (node.parent.type !== "ObjectExpression" || node.computed || node.key.type !== "Identifier") return;
5090
5137
  if (node.value.type !== "Identifier" && node.value.type !== "MemberExpression") return;
5091
5138
  const propertyName4 = node.key.name;
5092
- const source = context.sourceCode.getText(node.value);
5093
- if (node.value.type === "Identifier") {
5139
+ const propertyValue = node.value;
5140
+ const source = context.sourceCode.getText(propertyValue);
5141
+ if (propertyValue.type === "Identifier") {
5094
5142
  if (node.shorthand) return;
5095
- if (source !== propertyName4 && !canRenameIdentifierProducer(context, node.value)) return;
5096
- } else if (!canBindMemberExpression(context, node.value)) {
5143
+ if (source !== propertyName4 && !canRenameIdentifierProducer(context, propertyValue, propertyName4)) return;
5144
+ } else if (!canBindMemberExpression(context, propertyValue, propertyName4)) {
5097
5145
  return;
5098
5146
  }
5099
5147
  context.report({
5100
5148
  node,
5101
- 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
+ }
5102
5153
  });
5103
5154
  },
5104
5155
  TSTypeAliasDeclaration(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.61",
3
+ "version": "0.10.62",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",