@pyreon/lint 0.11.10 → 0.12.1

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
@@ -1712,6 +1745,48 @@ const noSignalInLoop = {
1712
1745
  }
1713
1746
  };
1714
1747
 
1748
+ //#endregion
1749
+ //#region src/rules/reactivity/no-signal-in-props.ts
1750
+ function isComponentTag(name) {
1751
+ return name.length > 0 && name[0] === name[0]?.toUpperCase() && name[0] !== name[0]?.toLowerCase();
1752
+ }
1753
+ /**
1754
+ * Warn when a known signal/computed is called in a component prop position.
1755
+ * Component props are evaluated once at mount — signal reads are NOT reactive
1756
+ * unless the compiler wraps them with _rp(). The compiler handles this
1757
+ * automatically, but this rule catches manual h() calls and educates developers.
1758
+ */
1759
+ const noSignalInProps = {
1760
+ meta: {
1761
+ id: "pyreon/no-signal-in-props",
1762
+ category: "reactivity",
1763
+ description: "Signal call in component prop — value captured once unless compiler wraps it. Use props.x pattern for reactivity.",
1764
+ severity: "warn",
1765
+ fixable: false
1766
+ },
1767
+ create(context) {
1768
+ return { JSXExpressionContainer(node) {
1769
+ const expr = node.expression;
1770
+ if (!expr || expr.type !== "CallExpression") return;
1771
+ const callee = expr.callee;
1772
+ if (!callee || callee.type !== "Identifier") return;
1773
+ const source = context.getSourceText();
1774
+ let i = node.start - 1;
1775
+ while (i >= 0 && source[i] !== "<" && source[i] !== ">") i--;
1776
+ if (i < 0 || source[i] !== "<") return;
1777
+ const tagStart = i + 1;
1778
+ let tagEnd = tagStart;
1779
+ while (tagEnd < source.length && /[\w.]/.test(source[tagEnd] ?? "")) tagEnd++;
1780
+ const tagName = source.slice(tagStart, tagEnd);
1781
+ if (!tagName || !isComponentTag(tagName)) return;
1782
+ context.report({
1783
+ message: `Signal call in <${tagName}> prop — use props.x pattern inside the component for reactive access.`,
1784
+ span: getSpan(expr)
1785
+ });
1786
+ } };
1787
+ }
1788
+ };
1789
+
1715
1790
  //#endregion
1716
1791
  //#region src/rules/reactivity/no-signal-leak.ts
1717
1792
  const noSignalLeak = {
@@ -2430,6 +2505,7 @@ const allRules = [
2430
2505
  noBareSignalInJsx,
2431
2506
  noContextDestructure,
2432
2507
  noSignalInLoop,
2508
+ noSignalInProps,
2433
2509
  noNestedEffect,
2434
2510
  noPeekInTracked,
2435
2511
  noUnbatchedUpdates,
@@ -2671,10 +2747,19 @@ function lintFile(filePath, sourceText, rules, config, cache) {
2671
2747
  allCallbacks.push(rule.create(ctx));
2672
2748
  }
2673
2749
  new Visitor(mergeCallbacks(allCallbacks)).visit(program);
2674
- diagnostics.sort((a, b) => a.span.start - b.span.start);
2750
+ const lines = sourceText.split("\n");
2751
+ const filtered = diagnostics.filter((d) => {
2752
+ const prevLineIdx = d.loc.line - 2;
2753
+ if (prevLineIdx < 0) return true;
2754
+ const prevLine = lines[prevLineIdx]?.trim();
2755
+ if (!prevLine?.startsWith("// pyreon-lint-ignore")) return true;
2756
+ const rest = prevLine.slice(21).trim();
2757
+ return rest.length > 0 && rest !== d.ruleId;
2758
+ });
2759
+ filtered.sort((a, b) => a.span.start - b.span.start);
2675
2760
  return {
2676
2761
  filePath,
2677
- diagnostics
2762
+ diagnostics: filtered
2678
2763
  };
2679
2764
  }
2680
2765
  /**