@pyreon/lint 0.11.9 → 0.12.0

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.
package/lib/index.js CHANGED
@@ -1130,39 +1130,72 @@ function containsJSXReturn(node) {
1130
1130
  }
1131
1131
  return false;
1132
1132
  }
1133
+ /**
1134
+ * Extract destructured property names from an ObjectPattern.
1135
+ * Returns names for the fix suggestion.
1136
+ */
1137
+ function getDestructuredNames(pattern) {
1138
+ if (pattern.type !== "ObjectPattern") return [];
1139
+ const names = [];
1140
+ for (const prop of pattern.properties ?? []) if (prop.type === "ObjectProperty" && prop.key?.type === "Identifier") names.push(prop.key.name);
1141
+ return names;
1142
+ }
1133
1143
  const noPropsDestructure = {
1134
1144
  meta: {
1135
1145
  id: "pyreon/no-props-destructure",
1136
1146
  category: "jsx",
1137
- description: "Disallow destructuring props in component functions — it breaks signal reactivity.",
1147
+ description: "Disallow destructuring props in component functions — breaks reactive prop tracking. Use props.x or splitProps().",
1138
1148
  severity: "error",
1139
1149
  fixable: false
1140
1150
  },
1141
1151
  create(context) {
1152
+ let functionDepth = 0;
1142
1153
  return {
1143
1154
  ArrowFunctionExpression(node) {
1144
- checkFunction(node, context);
1155
+ functionDepth++;
1156
+ checkFunction(node, context, functionDepth);
1157
+ },
1158
+ "ArrowFunctionExpression:exit"() {
1159
+ functionDepth--;
1145
1160
  },
1146
1161
  FunctionDeclaration(node) {
1147
- checkFunction(node, context);
1162
+ functionDepth++;
1163
+ checkFunction(node, context, functionDepth);
1164
+ },
1165
+ "FunctionDeclaration:exit"() {
1166
+ functionDepth--;
1148
1167
  },
1149
1168
  FunctionExpression(node) {
1150
- checkFunction(node, context);
1169
+ functionDepth++;
1170
+ checkFunction(node, context, functionDepth);
1171
+ },
1172
+ "FunctionExpression:exit"() {
1173
+ functionDepth--;
1151
1174
  }
1152
1175
  };
1153
1176
  }
1154
1177
  };
1155
- function checkFunction(node, context) {
1178
+ function checkFunction(node, context, depth) {
1156
1179
  const params = node.params;
1157
1180
  if (!params || params.length === 0) return;
1158
1181
  const firstParam = params[0];
1159
1182
  if (!isDestructuring(firstParam)) return;
1183
+ if (depth > 1) return;
1160
1184
  const body = node.body;
1161
1185
  if (!body) return;
1162
- if (containsJSXReturn(body)) context.report({
1163
- message: "Destructured props in a component function — this breaks signal reactivity. Use `props.x` or `splitProps()` instead.",
1164
- span: getSpan(firstParam)
1165
- });
1186
+ if (containsJSXReturn(body)) {
1187
+ const names = getDestructuredNames(firstParam);
1188
+ const hasRest = (firstParam.properties ?? []).some((p) => p.type === "RestElement");
1189
+ let suggestion = "Use `props.x` pattern for reactive prop access.";
1190
+ if (names.length > 0) {
1191
+ suggestion = `Use \`props\` parameter and access as ${names.map((n) => `props.${n}`).join(", ")}.`;
1192
+ if (hasRest) suggestion += ` For rest props, use \`splitProps(props, [${names.map((n) => `'${n}'`).join(", ")}])\`.`;
1193
+ }
1194
+ context.report({
1195
+ message: `Destructured props in component function — breaks reactive prop tracking. ${suggestion}`,
1196
+ span: getSpan(firstParam)
1197
+ });
1198
+ }
1166
1199
  }
1167
1200
 
1168
1201
  //#endregion