@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
@@ -1,5 +1,7 @@
1
- import { isFunctionNode, trackImports } from "../utils.mjs";
1
+ import { getSourceCode } from "../compat.mjs";
2
+ import { isFunctionNode, trackImports, walkOwnBody } from "../utils.mjs";
2
3
 
4
+ const GETTER_INDEX = 0;
3
5
  const SETTER_INDEX = 1;
4
6
 
5
7
  /** `const [value, setValue] = createSignal(...)` -> "setValue". */
@@ -13,6 +15,21 @@ function getSetterName(declarator) {
13
15
  return element?.type === "Identifier" ? element.name : null;
14
16
  }
15
17
 
18
+ /**
19
+ * `const [value, setValue] = createSignal(...)` -> "value", and for `const [,
20
+ * setValue]` the name the setter implies.
21
+ */
22
+ function getGetterName(declarator, setterName) {
23
+ const element = declarator.id.elements[GETTER_INDEX];
24
+ if (element?.type === "Identifier") {
25
+ return element.name;
26
+ }
27
+
28
+ const implied = /^set([A-Z])(.*)$/u.exec(setterName);
29
+
30
+ return implied ? `${implied[1].toLowerCase()}${implied[2]}` : "value";
31
+ }
32
+
16
33
  /**
17
34
  * The phase that runs untracked and performs the work. Solid 2.0 passes it as
18
35
  * the second argument; a lone function is still the whole effect.
@@ -35,32 +52,80 @@ function isSetterCall(node, setterNames) {
35
52
  );
36
53
  }
37
54
 
38
- /** True when any statement anywhere in the phase writes to a signal or store. */
39
- function writesSignalsAnywhere(node, setterNames) {
55
+ /** The first setter call anywhere in the phase, or null. */
56
+ function findSetterCall(node, setterNames) {
40
57
  if (node === null || typeof node !== "object") {
41
- return false;
58
+ return null;
42
59
  }
43
60
 
44
61
  if (isSetterCall(node, setterNames)) {
45
- return true;
62
+ return node;
46
63
  }
47
64
 
48
- return Object.entries(node).some(([key, value]) => {
65
+ for (const [key, value] of Object.entries(node)) {
49
66
  // `parent` points back up the tree; following it would not terminate.
50
67
  if (key === "parent") {
51
- return false;
68
+ continue;
52
69
  }
53
70
 
54
71
  const candidates = Array.isArray(value) ? value : [value];
55
-
56
- return candidates.some(
57
- (candidate) =>
72
+ for (const candidate of candidates) {
73
+ if (
58
74
  candidate !== null &&
59
75
  typeof candidate === "object" &&
60
- !isFunctionNode(candidate) &&
61
- writesSignalsAnywhere(candidate, setterNames),
62
- );
76
+ !isFunctionNode(candidate)
77
+ ) {
78
+ const found = findSetterCall(candidate, setterNames);
79
+ if (found) {
80
+ return found;
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ return null;
87
+ }
88
+
89
+ /**
90
+ * The first setter call in the effect function whose value the compute function
91
+ * reads: `count()` for a signal, `store.x` (or `store` itself) for a store.
92
+ */
93
+ function findOwnSourceWrite(node, setterNames, sourceGetters) {
94
+ const [compute, effectFn] = node.arguments;
95
+ if (!isFunctionNode(compute) || !isFunctionNode(effectFn)) {
96
+ return null;
97
+ }
98
+
99
+ const reads = new Set();
100
+ walkOwnBody(compute.body, (candidate) => {
101
+ if (
102
+ candidate.type === "CallExpression" &&
103
+ candidate.callee.type === "Identifier"
104
+ ) {
105
+ reads.add(candidate.callee.name);
106
+ } else if (
107
+ candidate.type === "MemberExpression" &&
108
+ candidate.object.type === "Identifier"
109
+ ) {
110
+ reads.add(candidate.object.name);
111
+ } else if (
112
+ candidate.type === "Identifier" &&
113
+ candidate === compute.body
114
+ ) {
115
+ reads.add(candidate.name);
116
+ }
63
117
  });
118
+
119
+ let write = null;
120
+ walkOwnBody(effectFn.body, (candidate) => {
121
+ write ??=
122
+ isSetterCall(candidate, setterNames) &&
123
+ reads.has(sourceGetters.get(candidate.callee.name))
124
+ ? candidate
125
+ : null;
126
+ });
127
+
128
+ return write;
64
129
  }
65
130
 
66
131
  /** True when the phase does nothing but write to signals or stores. */
@@ -76,7 +141,7 @@ function onlyWritesSignals(phase, setterNames) {
76
141
  body.every(
77
142
  (statement) =>
78
143
  statement.type === "ExpressionStatement" &&
79
- isSetterCall(statement.expression, setterNames),
144
+ isSetterCall(statement.expression, setterNames)
80
145
  )
81
146
  );
82
147
  }
@@ -87,20 +152,47 @@ export default {
87
152
  docs: {
88
153
  description:
89
154
  "Disallow effects that only copy a reactive value into another signal or store.",
90
- url: "https://docs.solidjs.com/",
155
+ url: "https://github.com/MurkyTheMurloc/web_dev_tools/blob/main/docs/solid-2-effects.md"
91
156
  },
92
157
  schema: [],
93
158
  messages: {
94
159
  asyncSetterInEffect:
95
- "This effect awaits and then writes the result into a signal or store. Return the value from a derivation instead: `createMemo(async () => ...)`, or the function form of `createStore` for nested data. Solid coordinates readiness, error propagation, and dropping superseded runs.",
160
+ "This effect awaits and then writes the result with `{{setter}}`, so nothing shows that '{{getter}}' is loading, a rejection never reaches `<Errored>`, and a superseded run can overwrite a newer one (Solid reports EFFECT_RELAY_TEAR). Fix: derive the value with an async memo, `const {{getter}} = {{derivation}}`, read `{{getter}}()` inside `<Loading>` and `<Errored>`, and drop `{{setter}}` and the effect; for a list whose items keep identity use `createStore(async () => …, seed)`. Do not: add a loading flag or a run counter to drop stale results (Solid drops a superseded run's answer itself), move the write into `onSettled`, or disable the rule.",
161
+ effectWritesOwnSource:
162
+ "`{{setter}}` in the effect function writes '{{getter}}', which the compute function reads, so each change runs the effect twice and paints the pre-write value in between (Solid reports EFFECT_WRITES_OWN_SOURCE). Fix: compute the written value in a memo, `const next{{Getter}} = createMemo(() => …)`, read that where '{{getter}}' is read and delete the write; if the write normalizes '{{getter}}', normalize where it is written, in the handler or action that calls `{{setter}}`. Do not: guard the write with an `if` or a flag, read '{{getter}}' with `untrack()` or in the effect function instead of the compute function, or disable the rule.",
96
163
  noSetterInEffect:
97
- "This effect only writes to a signal or store. Calculate the value where it is read instead: a derived function, `createMemo`, or a writable derived `createSignal(() => ...)` for a local override.",
98
- },
164
+ "This effect only copies a value into '{{getter}}' with `{{setter}}`, so everything that reads '{{getter}}' paints one flush behind its source (Solid reports EFFECT_RELAY_TEAR in dev). Fix: delete the effect and the signal and derive the value where it is read, with a plain function, `const {{getter}} = () => …`, or `createMemo(() => …)` when several readers share it, returning what `{{setter}}` receives; if '{{getter}}' is a local editable copy, use a writable derivation, `const [{{getter}}, {{setter}}] = createSignal(() => props.value)`, or `createStore(() => props.x, seed)` for nested data, which resets when the source changes; for async data use an async `createMemo` read inside `<Loading>` and `<Errored>`. Do not: move the write into `onSettled` or `queueMicrotask`, wrap it in `untrack()`, or disable the rule; each keeps the copy."
165
+ }
99
166
  },
100
167
  defaultOptions: [],
101
168
  create(context) {
102
169
  const { matchImport, handleImportDeclaration } = trackImports();
103
- const setterNames = new Set();
170
+ // Setter name -> the name of the value it writes.
171
+ const setterNames = new Map();
172
+ // Setter name -> the getter that reads its value, when there is one.
173
+ const sourceGetters = new Map();
174
+ const sourceCode = getSourceCode(context);
175
+
176
+ /** What the fix derives `getter` from: the awaited call, if any. */
177
+ function derivationFor(call) {
178
+ const [argument] = call.arguments;
179
+ if (argument?.type === "AwaitExpression") {
180
+ const text = sourceCode.getText(argument.argument);
181
+ if (!text.includes("\n")) {
182
+ return `createMemo(() => ${text})`;
183
+ }
184
+ }
185
+
186
+ return "createMemo(async () => { … })";
187
+ }
188
+
189
+ function setterData(call) {
190
+ return {
191
+ derivation: derivationFor(call),
192
+ getter: setterNames.get(call.callee.name),
193
+ setter: call.callee.name
194
+ };
195
+ }
104
196
 
105
197
  return {
106
198
  ImportDeclaration: handleImportDeclaration,
@@ -110,7 +202,7 @@ export default {
110
202
  node.init.callee.type !== "Identifier" ||
111
203
  !matchImport(
112
204
  ["createSignal", "createStore"],
113
- node.init.callee.name,
205
+ node.init.callee.name
114
206
  )
115
207
  ) {
116
208
  return;
@@ -118,7 +210,14 @@ export default {
118
210
 
119
211
  const setterName = getSetterName(node);
120
212
  if (setterName) {
121
- setterNames.add(setterName);
213
+ setterNames.set(
214
+ setterName,
215
+ getGetterName(node, setterName)
216
+ );
217
+ const getter = node.id.elements[GETTER_INDEX];
218
+ if (getter?.type === "Identifier") {
219
+ sourceGetters.set(setterName, getter.name);
220
+ }
122
221
  }
123
222
  },
124
223
  CallExpression(node) {
@@ -126,7 +225,7 @@ export default {
126
225
  node.callee.type !== "Identifier" ||
127
226
  !matchImport(
128
227
  ["createEffect", "createRenderEffect"],
129
- node.callee.name,
228
+ node.callee.name
130
229
  )
131
230
  ) {
132
231
  return;
@@ -145,24 +244,48 @@ export default {
145
244
  // `onlyWritesSignals` never sees the multi-statement shape at
146
245
  // all — the `await` is not a setter call — which is why an
147
246
  // async phase gets its own search.
148
- if (
149
- phase.async === true &&
150
- writesSignalsAnywhere(phase.body, setterNames)
151
- ) {
247
+ const write =
248
+ phase.async === true
249
+ ? findSetterCall(phase.body, setterNames)
250
+ : null;
251
+ if (write) {
152
252
  context.report({
253
+ data: setterData(write),
153
254
  node: phase,
154
- messageId: "asyncSetterInEffect",
255
+ messageId: "asyncSetterInEffect"
155
256
  });
156
257
  return;
157
258
  }
158
259
 
159
260
  if (onlyWritesSignals(phase, setterNames)) {
160
261
  context.report({
262
+ data: setterData(
263
+ findSetterCall(phase.body, setterNames)
264
+ ),
161
265
  node: phase,
162
- messageId: "noSetterInEffect",
266
+ messageId: "noSetterInEffect"
163
267
  });
268
+ return;
164
269
  }
165
- },
270
+
271
+ const ownWrite = findOwnSourceWrite(
272
+ node,
273
+ setterNames,
274
+ sourceGetters
275
+ );
276
+ if (ownWrite) {
277
+ const getter = setterNames.get(ownWrite.callee.name);
278
+ context.report({
279
+ data: {
280
+ Getter: `${getter[0].toUpperCase()}${getter.slice(1)}`,
281
+ getter,
282
+ setter: ownWrite.callee.name
283
+ },
284
+ node: ownWrite,
285
+ messageId: "effectWritesOwnSource"
286
+ });
287
+ }
288
+ }
166
289
  };
167
- },
290
+ }
168
291
  };
@@ -0,0 +1,55 @@
1
+ // Ported from eslint-plugin-solid 0.20.1 (no-single-arg-create-effect).
2
+ // Solid 2.0 splits effects into a tracked compute function and an untracked
3
+ // effect function: `createEffect(compute, effect)`. The single-argument 1.x
4
+ // form types as `never` through a deprecated overload, which gives no compile
5
+ // error on a bare statement, and throws MISSING_EFFECT_FN only at runtime in
6
+ // dev. Async or not makes no difference.
7
+ import { trackImports } from "../utils.mjs";
8
+
9
+ export default {
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description:
14
+ "Require the two-argument `createEffect(compute, effect)` form used by Solid 2.0.",
15
+ url: "https://github.com/MurkyTheMurloc/web_dev_tools/blob/main/docs/solid-2-effects.md"
16
+ },
17
+ schema: [],
18
+ messages: {
19
+ singleArgEffect:
20
+ "`{{name}}` is called with one function, a form Solid 2.0 removed: it throws MISSING_EFFECT_FN in dev. Fix: split it into a tracked compute that reads the values and an untracked effect that does the work, `{{name}}(() => source(), (value) => doWork(value))`. For a derived value use `createMemo(() => …)` instead; for one-time work after mount use `onSettled(() => …)`.",
21
+ singleArgRenderEffect:
22
+ "`{{name}}` is called with one function, a form Solid 2.0 does not have: the function runs only as the tracked compute, with no effect phase. Fix: split it into a tracked compute that reads the values and an untracked effect that does the work, `{{name}}(() => source(), (value) => doWork(value))`. For a derived value use `createMemo(() => …)` instead."
23
+ }
24
+ },
25
+ defaultOptions: [],
26
+ create(context) {
27
+ const { matchImport, handleImportDeclaration } = trackImports();
28
+ return {
29
+ ImportDeclaration: handleImportDeclaration,
30
+ CallExpression(node) {
31
+ if (
32
+ node.callee.type !== "Identifier" ||
33
+ node.arguments.length !== 1
34
+ ) {
35
+ return;
36
+ }
37
+ if (matchImport("createEffect", node.callee.name)) {
38
+ context.report({
39
+ data: { name: node.callee.name },
40
+ messageId: "singleArgEffect",
41
+ node
42
+ });
43
+ } else if (
44
+ matchImport("createRenderEffect", node.callee.name)
45
+ ) {
46
+ context.report({
47
+ data: { name: node.callee.name },
48
+ messageId: "singleArgRenderEffect",
49
+ node
50
+ });
51
+ }
52
+ }
53
+ };
54
+ }
55
+ };
@@ -0,0 +1,99 @@
1
+ // Port of eslint-plugin-solid's no-unassigned-vars (MIT, d3e946c): eslint's
2
+ // no-unassigned-vars, except that `ref={el}` or `ref={el!}` counts as an
3
+ // assignment. Solid's compiler rewrites the single shorthand to `el = node`,
4
+ // but scope analysis only sees a read. A bare `el` inside `ref={[…]}` is never
5
+ // assigned, but solid/prefer-ref-shorthand reports that entry (its fix, a
6
+ // callback, assigns the variable), so this rule leaves the variable alone.
7
+ import { getSourceCode } from "../compat.mjs";
8
+ import { jsxPropName } from "../utils.mjs";
9
+
10
+ /** Whether `value` is the whole expression of a `ref` attribute. */
11
+ function isRefExpression(value) {
12
+ const container = value.parent;
13
+ return (
14
+ container?.type === "JSXExpressionContainer" &&
15
+ container.parent?.type === "JSXAttribute" &&
16
+ jsxPropName(container.parent) === "ref"
17
+ );
18
+ }
19
+
20
+ /** `el` or `el!` as the whole value of a `ref`, or as an entry of a ref array. */
21
+ function isRefValue(identifier) {
22
+ const value =
23
+ identifier.parent?.type === "TSNonNullExpression"
24
+ ? identifier.parent
25
+ : identifier;
26
+ return (
27
+ isRefExpression(value) ||
28
+ (value.parent?.type === "ArrayExpression" &&
29
+ isRefExpression(value.parent))
30
+ );
31
+ }
32
+
33
+ /** `declare let x: T;`, or any declaration in a `declare module`/`global`. */
34
+ function isAmbient(declaration) {
35
+ for (let node = declaration; node; node = node.parent) {
36
+ if (node.declare === true) {
37
+ return true;
38
+ }
39
+ }
40
+ return false;
41
+ }
42
+
43
+ export default {
44
+ meta: {
45
+ type: "problem",
46
+ docs: {
47
+ description:
48
+ "Disallow `let` and `var` variables that are read but never assigned, counting `ref={el}` as an assignment. Replaces eslint's `no-unassigned-vars`."
49
+ },
50
+ schema: [],
51
+ messages: {
52
+ unassigned:
53
+ "`{{name}}` is read but never assigned, so it is always `undefined`. Fix: assign it before it is read, or, if it should hold an element, pass it as `ref={{{name}}}`. Do not: add `= undefined` or `!` to silence it; the value stays missing."
54
+ }
55
+ },
56
+ defaultOptions: [],
57
+ create(context) {
58
+ const sourceCode = getSourceCode(context);
59
+
60
+ return {
61
+ VariableDeclarator(node) {
62
+ const declaration = node.parent;
63
+ if (
64
+ node.init ||
65
+ node.id.type !== "Identifier" ||
66
+ declaration.kind === "const" ||
67
+ isAmbient(declaration)
68
+ ) {
69
+ return;
70
+ }
71
+ const [variable] = sourceCode.getDeclaredVariables(node);
72
+ if (!variable) {
73
+ return;
74
+ }
75
+ let hasRead = false;
76
+ for (const reference of variable.references) {
77
+ if (
78
+ reference.isWrite() ||
79
+ isRefValue(reference.identifier)
80
+ ) {
81
+ return;
82
+ }
83
+ if (reference.isRead()) {
84
+ hasRead = true;
85
+ }
86
+ }
87
+ // A variable that is never read is no-unused-vars' to report.
88
+ if (!hasRead) {
89
+ return;
90
+ }
91
+ context.report({
92
+ data: { name: node.id.name },
93
+ messageId: "unassigned",
94
+ node
95
+ });
96
+ }
97
+ };
98
+ }
99
+ };
@@ -1,18 +1,52 @@
1
- import { isDOMElementName } from "../utils.mjs";
1
+ import { getSourceCode } from "../compat.mjs";
2
+ import { isDOMElementName, messageCode } from "../utils.mjs";
2
3
  // Solid 2.0 removed every Solid-specific JSX namespace. What is left are the
3
4
  // XML namespaces the DOM itself defines.
4
5
  const xmlNamespaces = ["xmlns", "xlink"];
5
- // Removed namespace -> what to write instead.
6
+ const REMOVED = "which Solid 2.0 removed.";
7
+ const LOWERCASE_EVENT = /^[a-z]+$/;
8
+ // Removed namespace -> why, and the replacement written with the prop's own
9
+ // name (`name`), its `=value` (`assign`) and its value as an expression
10
+ // (`value`).
6
11
  const replacements = {
7
- attr: "the standard attribute",
8
- bool: "the standard attribute (booleans are presence/absence)",
9
- class: "the `class` prop with an object or array value",
10
- on: "a camel-case event prop such as `onClick`, or a ref callback with `addEventListener` when listener options are needed",
11
- oncapture:
12
- "a camel-case event prop, or a ref callback with `addEventListener` when capture is needed",
13
- prop: "the standard property",
14
- style: "the `style` prop with an object value",
15
- use: "a ref callback or directive factory, composing with a ref array",
12
+ attr: {
13
+ why: `${REMOVED} Attributes are the default.`,
14
+ fix: ({ name, assign }) => `${name}${assign}`
15
+ },
16
+ bool: {
17
+ why: `${REMOVED} A boolean value adds or removes the attribute.`,
18
+ fix: ({ name, assign }) => `${name}${assign}`
19
+ },
20
+ class: {
21
+ why: `${REMOVED} \`class\` takes an object.`,
22
+ fix: ({ name, value }) => `class={{ "${name}": ${value} }}`
23
+ },
24
+ on: {
25
+ why: `${REMOVED} Event props are camelCase.`,
26
+ // `onClick` listens to `click`; any other event name needs a ref.
27
+ fix: ({ name, value }) =>
28
+ LOWERCASE_EVENT.test(name)
29
+ ? `on${name[0].toUpperCase()}${name.slice(1)}={${value}}`
30
+ : `ref={(el) => el.addEventListener("${name}", ${value})}`
31
+ },
32
+ oncapture: {
33
+ why: `${REMOVED} Listener options go through a ref callback.`,
34
+ fix: ({ name, value }) =>
35
+ `ref={(el) => el.addEventListener("${name}", ${value}, { capture: true })}`
36
+ },
37
+ prop: {
38
+ why: "which Solid 2.0's types reject on built-in elements: Solid sets `value`, `checked` and the like as properties from the plain name. (On a custom element such as `<my-chart prop:data={…}>`, `prop:` is right and not reported.)",
39
+ fix: ({ name, assign }) => `${name}${assign}`
40
+ },
41
+ style: {
42
+ why: `${REMOVED} \`style\` takes an object.`,
43
+ fix: ({ name, value }) => `style={{ "${name}": ${value} }}`
44
+ },
45
+ use: {
46
+ why: `${REMOVED} A directive is now a factory that returns the ref callback \`(el) => { … }\`.`,
47
+ fix: ({ name, assign, value }) =>
48
+ assign === "" ? `ref={${name}}` : `ref={${name}(${value})}`
49
+ }
16
50
  };
17
51
  export default {
18
52
  meta: {
@@ -20,7 +54,7 @@ export default {
20
54
  docs: {
21
55
  description:
22
56
  "Disallow Solid's removed JSX attribute namespaces. Solid 2.0 dropped `on:`, `oncapture:`, `use:`, `prop:`, `attr:`, `bool:`, `class:` and `style:`.",
23
- url: "https://docs.solidjs.com/",
57
+ url: "https://docs.solidjs.com/"
24
58
  },
25
59
  schema: [
26
60
  {
@@ -31,10 +65,10 @@ export default {
31
65
  "an array of additional namespace names to allow",
32
66
  type: "array",
33
67
  items: {
34
- type: "string",
68
+ type: "string"
35
69
  },
36
70
  minItems: 1,
37
- uniqueItems: true,
71
+ uniqueItems: true
38
72
  },
39
73
  allowedNamespacedProps: {
40
74
  description:
@@ -42,22 +76,23 @@ export default {
42
76
  type: "array",
43
77
  items: {
44
78
  type: "string",
45
- pattern: "^[^:]+:[^:]+$",
79
+ pattern: "^[^:]+:[^:]+$"
46
80
  },
47
81
  minItems: 1,
48
- uniqueItems: true,
49
- },
82
+ uniqueItems: true
83
+ }
50
84
  },
51
- additionalProperties: false,
52
- },
85
+ additionalProperties: false
86
+ }
53
87
  ],
54
88
  messages: {
55
89
  removed:
56
- "'{{namespace}}:' was removed in Solid 2.0. Use {{replacement}} instead.",
90
+ "`{{attribute}}` uses the `{{namespace}}:` namespace, {{why}} Fix: `{{fix}}`.",
57
91
  unknown:
58
- "'{{namespace}}:' is not a namespace Solid understands. Solid 2.0 has no special JSX prefixes.",
59
- component: "Namespaced props have no effect on components.",
60
- },
92
+ '`{{attribute}}` uses the `{{namespace}}:` namespace, which neither Solid 2.0 nor the DOM knows, so it is set as a literal `{{attribute}}` attribute. Fix: the plain name `{{name}}`, or, when a framework gives `{{namespace}}:` a meaning, allow it with this rule\'s `allowedNamespacedProps` option (`"{{attribute}}"`).',
93
+ component:
94
+ '`{{attribute}}` on `<{{element}}>` is a namespaced prop, and Solid gives a namespace no meaning on a component. Fix: a plain prop name, or, when a framework handles it (an island directive), allow it with this rule\'s `allowedNamespacedProps` option (`"{{attribute}}"`).'
95
+ }
61
96
  },
62
97
  defaultOptions: [],
63
98
  create(context) {
@@ -65,6 +100,7 @@ export default {
65
100
  context.options?.[0]?.allowedNamespaces;
66
101
  const explicitlyAllowedProps =
67
102
  context.options?.[0]?.allowedNamespacedProps;
103
+ const sourceCode = getSourceCode(context);
68
104
  return {
69
105
  "JSXAttribute > JSXNamespacedName": (node) => {
70
106
  const namespace = node.namespace?.name;
@@ -75,12 +111,13 @@ export default {
75
111
  if (
76
112
  explicitlyAllowedNamespaces?.includes(namespace) ||
77
113
  explicitlyAllowedProps?.includes(
78
- `${namespace}:${node.name?.name}`,
114
+ `${namespace}:${node.name?.name}`
79
115
  )
80
116
  ) {
81
117
  return;
82
118
  }
83
119
  const openingElement = node.parent.parent;
120
+ const attribute = `${namespace}:${node.name?.name}`;
84
121
  if (
85
122
  openingElement.name.type === "JSXIdentifier" &&
86
123
  !isDOMElementName(openingElement.name.name)
@@ -88,27 +125,69 @@ export default {
88
125
  // Solid itself gives a namespaced prop on a component no
89
126
  // meaning. No suggestion: deleting the prefix changes the
90
127
  // prop's name, and the rule cannot know which one is meant.
91
- context.report({ node, messageId: "component" });
128
+ context.report({
129
+ node,
130
+ messageId: "component",
131
+ data: {
132
+ attribute,
133
+ element: sourceCode.getText(openingElement.name)
134
+ }
135
+ });
92
136
  return;
93
137
  }
94
138
  if (xmlNamespaces.includes(namespace)) {
95
139
  return;
96
140
  }
141
+ // `prop:` is how Solid 2.0 sets a property on a custom element
142
+ // (`<my-chart prop:data={points()}>` is `el.data = points()`),
143
+ // typed through JSX.ExplicitProperties. Only built-in elements,
144
+ // whose properties Solid sets from the plain name, are reported.
145
+ if (
146
+ namespace === "prop" &&
147
+ openingElement.name.type === "JSXIdentifier" &&
148
+ openingElement.name.name.includes("-")
149
+ ) {
150
+ return;
151
+ }
97
152
  const replacement = replacements[namespace];
98
153
  if (replacement) {
154
+ const { value } = node.parent;
155
+ const parts = {
156
+ name: node.name.name,
157
+ assign: value ? `=${sourceCode.getText(value)}` : "",
158
+ value: value
159
+ ? sourceCode.getText(
160
+ value.type === "JSXExpressionContainer"
161
+ ? value.expression
162
+ : value
163
+ )
164
+ : "true"
165
+ };
99
166
  context.report({
100
167
  node,
101
168
  messageId: "removed",
102
- data: { namespace, replacement },
169
+ data: {
170
+ attribute,
171
+ namespace,
172
+ why: replacement.why,
173
+ fix: messageCode(
174
+ replacement.fix(parts),
175
+ replacement.fix({
176
+ name: parts.name,
177
+ assign: value ? "={…}" : "",
178
+ value: "…"
179
+ })
180
+ )
181
+ }
103
182
  });
104
183
  return;
105
184
  }
106
185
  context.report({
107
186
  node,
108
187
  messageId: "unknown",
109
- data: { namespace },
188
+ data: { attribute, namespace, name: node.name.name }
110
189
  });
111
- },
190
+ }
112
191
  };
113
- },
192
+ }
114
193
  };