@murky-web/oxlint-plugin-solid 1.5.0 → 1.6.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.
Files changed (45) hide show
  1. package/README.md +163 -18
  2. package/THIRD_PARTY_NOTICES.md +7 -4
  3. package/package.json +5 -2
  4. package/src/compat.mjs +3 -0
  5. package/src/index.mjs +26 -3
  6. package/src/rules/components_return_once.mjs +136 -89
  7. package/src/rules/event_handlers.mjs +55 -35
  8. package/src/rules/filename_matches_export.mjs +292 -0
  9. package/src/rules/function_size.mjs +189 -0
  10. package/src/rules/imports.mjs +24 -21
  11. package/src/rules/init_declarations.mjs +139 -0
  12. package/src/rules/jsx_no_duplicate_props.mjs +46 -18
  13. package/src/rules/jsx_no_script_url.mjs +7 -6
  14. package/src/rules/jsx_no_undef.mjs +35 -38
  15. package/src/rules/jsx_uses_vars.mjs +4 -4
  16. package/src/rules/no_array_handlers.mjs +38 -9
  17. package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
  18. package/src/rules/no_destructure.mjs +105 -35
  19. package/src/rules/no_innerhtml.mjs +64 -31
  20. package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
  21. package/src/rules/no_owned_primitives_in_ref.mjs +30 -9
  22. package/src/rules/no_proxy_apis.mjs +44 -15
  23. package/src/rules/no_react_deps.mjs +397 -41
  24. package/src/rules/no_react_specific_props.mjs +40 -11
  25. package/src/rules/no_server_import_in_client.mjs +9 -9
  26. package/src/rules/no_setter_in_effect.mjs +153 -30
  27. package/src/rules/no_single_arg_create_effect.mjs +55 -0
  28. package/src/rules/no_unassigned_vars.mjs +99 -0
  29. package/src/rules/no_unknown_namespaces.mjs +108 -29
  30. package/src/rules/no_untracked_effect_read.mjs +69 -32
  31. package/src/rules/no_write_in_pure_computation.mjs +273 -0
  32. package/src/rules/prefer_arrow_components.mjs +47 -21
  33. package/src/rules/prefer_class_object.mjs +52 -20
  34. package/src/rules/prefer_destructuring.mjs +164 -0
  35. package/src/rules/prefer_for.mjs +42 -12
  36. package/src/rules/prefer_ref_shorthand.mjs +142 -0
  37. package/src/rules/prefer_show.mjs +55 -24
  38. package/src/rules/reactive_async.mjs +64 -17
  39. package/src/rules/reactivity.mjs +1218 -350
  40. package/src/rules/self_closing_comp.mjs +23 -18
  41. package/src/rules/strict_void_return.mjs +50 -20
  42. package/src/rules/style_prop.mjs +53 -25
  43. package/src/rules/typed_merge_defaults.mjs +88 -0
  44. package/src/rules/validate_jsx_nesting.mjs +16 -16
  45. package/src/utils.mjs +65 -34
@@ -0,0 +1,73 @@
1
+ // Ported from eslint-plugin-solid 0.20.1 (no-module-scope-reactive-primitive).
2
+ // Reactive state created at module scope is shared across every request when
3
+ // server rendering, so one user's state leaks into another's response. Any
4
+ // enclosing function is the escape hatch, `createRoot` included.
5
+ import { getSourceCode } from "../compat.mjs";
6
+ import { findParent, isFunctionNode, trackImports } from "../utils.mjs";
7
+
8
+ // Upstream's list plus createTrackedEffect and createReaction, which Solid
9
+ // 2.0 exports and which own state the same way.
10
+ const REACTIVE_PRIMITIVES = [
11
+ "createSignal",
12
+ "createMemo",
13
+ "createDeferred",
14
+ "createStore",
15
+ "createEffect",
16
+ "createRenderEffect",
17
+ "createTrackedEffect",
18
+ "createReaction",
19
+ "createOptimistic",
20
+ "createOptimisticStore",
21
+ "createProjection"
22
+ ];
23
+
24
+ export default {
25
+ meta: {
26
+ type: "problem",
27
+ docs: {
28
+ description:
29
+ "Disallow reactive primitives at module scope, where state is shared across SSR requests.",
30
+ url: "https://github.com/solidjs/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-module-scope-reactive-primitive.md"
31
+ },
32
+ schema: [],
33
+ messages: {
34
+ moduleScopePrimitive:
35
+ "`{{statement}}` runs once per process at module scope, so with server rendering every request shares this state and one user's data reaches another's response. Fix: move `{{statement}}` into the component that uses it, or into a provider component that hands it down with `<Context value={…}>`. Only for client-only state that is meant to be global: wrap it in `createRoot(() => …)`."
36
+ }
37
+ },
38
+ defaultOptions: [],
39
+ create(context) {
40
+ const { matchImport, handleImportDeclaration } = trackImports();
41
+ return {
42
+ ImportDeclaration: handleImportDeclaration,
43
+ CallExpression(node) {
44
+ if (node.callee.type !== "Identifier") {
45
+ return;
46
+ }
47
+ if (!matchImport(REACTIVE_PRIMITIVES, node.callee.name)) {
48
+ return;
49
+ }
50
+ if (findParent(node, isFunctionNode) === null) {
51
+ // The whole declaration when there is one, so the fix can
52
+ // move it as written.
53
+ const declaration = findParent(
54
+ node,
55
+ (candidate) => candidate.type === "VariableDeclaration"
56
+ );
57
+ const text = getSourceCode(context).getText(
58
+ declaration ?? node
59
+ );
60
+ context.report({
61
+ data: {
62
+ statement: text.includes("\n")
63
+ ? `${node.callee.name}(…)`
64
+ : text
65
+ },
66
+ messageId: "moduleScopePrimitive",
67
+ node
68
+ });
69
+ }
70
+ }
71
+ };
72
+ }
73
+ };
@@ -13,9 +13,23 @@ const OWNED_PRIMITIVES = [
13
13
  "createReaction",
14
14
  "createRenderEffect",
15
15
  "onCleanup",
16
- "onSettled",
16
+ "onSettled"
17
17
  ];
18
18
 
19
+ /**
20
+ * What Solid 2.0 does in dev when a ref callback creates the primitive. A ref
21
+ * callback owns nothing, like an effect callback.
22
+ */
23
+ function diagnosticFor(primitive) {
24
+ if (primitive === "onCleanup") {
25
+ return " and Solid throws CLEANUP_IN_FORBIDDEN_SCOPE in dev";
26
+ }
27
+
28
+ return ["onSettled", "createReaction"].includes(primitive)
29
+ ? ""
30
+ : " and Solid throws PRIMITIVE_IN_EFFECT_CALLBACK in dev";
31
+ }
32
+
19
33
  /** The callbacks a `ref` prop applies, including the ones in a ref array. */
20
34
  function getRefCallbacks(expression) {
21
35
  if (isFunctionNode(expression)) {
@@ -27,7 +41,7 @@ function getRefCallbacks(expression) {
27
41
  // callback like any other.
28
42
  if (expression?.type === "ArrayExpression") {
29
43
  return expression.elements.flatMap((element) =>
30
- element !== null && isFunctionNode(element) ? [element] : [],
44
+ element !== null && isFunctionNode(element) ? [element] : []
31
45
  );
32
46
  }
33
47
 
@@ -73,13 +87,13 @@ export default {
73
87
  docs: {
74
88
  description:
75
89
  "Disallow creating owner-bound primitives inside a ref callback.",
76
- url: "https://docs.solidjs.com/",
90
+ url: "https://docs.solidjs.com/"
77
91
  },
78
92
  schema: [],
79
93
  messages: {
80
94
  ownedPrimitiveInRef:
81
- "`{{name}}` is called inside a ref callback, which runs without an owner — nothing will ever dispose it. Create it in the directive factory instead, and let the returned callback only store the element.",
82
- },
95
+ "`{{name}}` is called inside a ref callback, which runs without an owner, so nothing disposes it{{diagnostic}}. Fix: call `{{name}}` in the component body, or in a directive factory that returns the ref callback, `const directive = () => { {{name}}(…); return (el) => { /* store or update el */ }; }` used as `ref={directive()}`; the ref callback itself only touches the element."
96
+ }
83
97
  },
84
98
  defaultOptions: [],
85
99
  create(context) {
@@ -103,20 +117,27 @@ export default {
103
117
  candidate.callee.type !== "Identifier" ||
104
118
  !matchImport(
105
119
  OWNED_PRIMITIVES,
106
- candidate.callee.name,
120
+ candidate.callee.name
107
121
  )
108
122
  ) {
109
123
  return;
110
124
  }
111
125
 
126
+ const primitive = matchImport(
127
+ OWNED_PRIMITIVES,
128
+ candidate.callee.name
129
+ );
112
130
  context.report({
113
131
  node: candidate,
114
132
  messageId: "ownedPrimitiveInRef",
115
- data: { name: candidate.callee.name },
133
+ data: {
134
+ diagnostic: diagnosticFor(primitive),
135
+ name: candidate.callee.name
136
+ }
116
137
  });
117
138
  });
118
139
  }
119
- },
140
+ }
120
141
  };
121
- },
142
+ }
122
143
  };
@@ -1,14 +1,16 @@
1
+ import { getSourceCode } from "../compat.mjs";
1
2
  import {
2
3
  isFunctionNode,
3
4
  trackImports,
4
5
  isPropsByName,
5
- trace,
6
+ messageCode,
7
+ trace
6
8
  } from "../utils.mjs";
7
9
  // Store APIs that hand back a Proxy. Solid 2.0 exports these from `solid-js`.
8
10
  const PROXY_BACKED_STORE_APIS = new Set([
9
11
  "createStore",
10
12
  "createProjection",
11
- "createOptimisticStore",
13
+ "createOptimisticStore"
12
14
  ]);
13
15
  export default {
14
16
  meta: {
@@ -16,25 +18,28 @@ export default {
16
18
  docs: {
17
19
  description:
18
20
  "Disallow usage of APIs that use ES6 Proxies, only to target environments that don't support them.",
19
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-proxy-apis.md",
21
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-proxy-apis.md"
20
22
  },
21
23
  schema: [],
22
24
  messages: {
23
25
  noStore:
24
- "Solid Store APIs use Proxies, which are incompatible with your target environment.",
26
+ "`{{name}}` returns a store, which is a Proxy, and this rule is on because the target environment has no Proxy. Fix: keep the state in signals, `createSignal(initial)`, and replace the value on update; if every target has Proxy, turn `solid/no-proxy-apis` off in the lint config.",
25
27
  spreadCall:
26
- "Using a function call in JSX spread makes Solid use Proxies, which are incompatible with your target environment.",
28
+ "`{...{{expression}}}` spreads a call, so Solid wraps it in a Proxy to keep it reactive, and the target environment has no Proxy. Fix: pass the props one by one, `name={{{expression}}.name}`, or spread a plain object.",
27
29
  spreadMember:
28
- "Using a property access in JSX spread makes Solid use Proxies, which are incompatible with your target environment.",
30
+ "`{...{{expression}}}` spreads a property access, so Solid wraps it in a Proxy to keep it reactive, and the target environment has no Proxy. Fix: pass the props one by one, `name={{{expression}}.name}`, or spread a plain object.",
29
31
  proxyLiteral:
30
- "Proxies are incompatible with your target environment.",
32
+ "`{{expression}}` creates a Proxy, and the target environment has no Proxy, which cannot be polyfilled. Fix: use a plain object, with getters (`get value() { … }`) where a read must compute.",
31
33
  mergeProps:
32
- "If you pass a function to `mergeProps`, it will create a Proxy, which are incompatible with your target environment.",
33
- },
34
+ "`{{name}}` gets `{{argument}}`, which may be a function or a store, and reading such a source live needs a Proxy, which the target environment does not have. Fix: pass plain objects, with a getter for a value that must stay live, `{{name}}({ get size() { return size(); } }, props)`."
35
+ }
34
36
  },
35
37
  defaultOptions: [],
36
38
  create(context) {
37
39
  const { matchImport, handleImportDeclaration } = trackImports();
40
+ const sourceCode = getSourceCode(context);
41
+ const code = (node, fallback) =>
42
+ messageCode(sourceCode.getText(node), fallback);
38
43
  return {
39
44
  ImportDeclaration(node) {
40
45
  handleImportDeclaration(node); // track import aliases
@@ -44,7 +49,11 @@ export default {
44
49
  // Solid 2.0 moved them into `solid-js`, which every file
45
50
  // imports, so match the specifier names instead.
46
51
  if (source === "solid-js/store") {
47
- context.report({ node, messageId: "noStore" });
52
+ context.report({
53
+ node,
54
+ messageId: "noStore",
55
+ data: { name: "solid-js/store" }
56
+ });
48
57
  return;
49
58
  }
50
59
  if (source !== "solid-js") {
@@ -58,15 +67,24 @@ export default {
58
67
  context.report({
59
68
  node: specifier,
60
69
  messageId: "noStore",
70
+ data: { name: specifier.imported.name }
61
71
  });
62
72
  }
63
73
  }
64
74
  },
65
75
  "JSXSpreadAttribute MemberExpression"(node) {
66
- context.report({ node, messageId: "spreadMember" });
76
+ context.report({
77
+ node,
78
+ messageId: "spreadMember",
79
+ data: { expression: code(node, "props.rest") }
80
+ });
67
81
  },
68
82
  "JSXSpreadAttribute CallExpression"(node) {
69
- context.report({ node, messageId: "spreadCall" });
83
+ context.report({
84
+ node,
85
+ messageId: "spreadCall",
86
+ data: { expression: code(node, "getProps()") }
87
+ });
70
88
  },
71
89
  CallExpression(node) {
72
90
  if (node.callee.type === "Identifier") {
@@ -87,6 +105,10 @@ export default {
87
105
  context.report({
88
106
  node: badArg,
89
107
  messageId: "mergeProps",
108
+ data: {
109
+ argument: code(badArg, "…"),
110
+ name: node.callee.name
111
+ }
90
112
  });
91
113
  });
92
114
  }
@@ -100,6 +122,9 @@ export default {
100
122
  context.report({
101
123
  node,
102
124
  messageId: "proxyLiteral",
125
+ data: {
126
+ expression: code(node, "Proxy.revocable(…)")
127
+ }
103
128
  });
104
129
  }
105
130
  }
@@ -109,9 +134,13 @@ export default {
109
134
  node.callee.type === "Identifier" &&
110
135
  node.callee.name === "Proxy"
111
136
  ) {
112
- context.report({ node, messageId: "proxyLiteral" });
137
+ context.report({
138
+ node,
139
+ messageId: "proxyLiteral",
140
+ data: { expression: code(node, "new Proxy(…)") }
141
+ });
113
142
  }
114
- },
143
+ }
115
144
  };
116
- },
145
+ }
117
146
  };