@murky-web/oxlint-plugin-solid 1.3.0 → 1.4.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/README.md CHANGED
@@ -22,33 +22,36 @@ Aktuell sind enthalten:
22
22
  `solid/no-setter-in-effect` (meldet Effects, die nur in ein Signal oder einen
23
23
  Store schreiben, statt den Wert abzuleiten -- und Effects, die etwas awaiten
24
24
  und das Ergebnis zurueckschreiben, statt es aus einer Derivation zu liefern)
25
- `solid/no-untracked-effect-read` (meldet reaktive Reads in der
26
- apply-Phase eines zweiphasigen `createEffect`, die dort nicht tracken) und
25
+ `solid/no-untracked-effect-read` (meldet reaktive Reads in der apply-Phase
26
+ eines zweiphasigen `createEffect`, die dort nicht tracken) und
27
27
  `solid/no-owned-primitives-in-ref` (meldet `createEffect`/`onCleanup` und
28
- Verwandte in einem Ref-Callback -- der laeuft ohne Owner, nichts raeumt sie
29
- je wieder ab),
30
- `solid/reactive-async`, `solid/no-server-import-in-client` und
28
+ Verwandte in einem Ref-Callback -- der laeuft ohne Owner, nichts raeumt sie je
29
+ wieder ab), `solid/reactive-async`, `solid/no-server-import-in-client` und
31
30
  `solid/strict-void-return` (siehe unten)
32
- - ein Test-Harness, der die exportierte Rule-Surface und echte Diagnostik
33
- gegen Temp-Projekte prueft
34
-
35
- Aktuell wird das Paket nicht direkt im Zielprojekt installiert. Stattdessen
36
- kopiert `@murky-web/config` die Rule-Runtime in `./oxc/jsplugins/solid/`, damit
37
- Oxlint sie ueber einen lokalen `jsPlugins`-Pfad laden kann.
38
-
39
- Wichtig dabei:
31
+ - ein Test-Harness, der die exportierte Rule-Surface und echte Diagnostik gegen
32
+ Temp-Projekte prueft
33
+
34
+ Das Paket wird als normale Dependency installiert und in der
35
+ Oxlint-Konfiguration als JS-Plugin geladen:
36
+
37
+ ```jsonc
38
+ {
39
+ "jsPlugins": ["@murky-web/oxlint-plugin-solid"],
40
+ "rules": {
41
+ "solid/reactivity": "error",
42
+ "solid/prefer-arrow-components": "error",
43
+ },
44
+ }
45
+ ```
40
46
 
41
- - `@murky-web/config` loest dieses Paket als normale Workspace-Dependency auf
42
- - der Installer kopiert den lokalen Plugin-Src-Ordner aus der installierten
43
- Paketauflösung
44
- - Zielprojekte brauchen dadurch weiter nur die kopierte Runtime unter
45
- `./oxc/jsplugins/solid/`, nicht dieses Paket als direkte Dependency
47
+ Die Regeln heissen `solid/<name>`. Welche Regeln dieses Repo selbst einschaltet,
48
+ steht in `config/oxc/linting/solid.jsonc`.
46
49
 
47
50
  ## Regeln fuer das Solid-2.0-Modell
48
51
 
49
- Die drei Regeln arbeiten ohne Typinformation, nur mit Syntax und Scope. Sie
50
- sind in `config/oxc/linting/solid.jsonc` aktiv und ersetzen dort fuer
51
- `*.tsx`/`*.jsx` die Typ-Regeln `typescript/promise-function-async` und
52
+ Die drei Regeln arbeiten ohne Typinformation, nur mit Syntax und Scope. Sie sind
53
+ in `config/oxc/linting/solid.jsonc` aktiv und ersetzen dort fuer `*.tsx`/`*.jsx`
54
+ die Typ-Regeln `typescript/promise-function-async` und
52
55
  `typescript/strict-void-return`.
53
56
 
54
57
  ### `solid/reactive-async`
@@ -65,9 +68,9 @@ Gemeldet wird
65
68
  Memos, `props.x`, Property-Read eines Stores): Solid meldet das zur Laufzeit
66
69
  als `UNTRACKED_READ_AFTER_AWAIT`, es wird nie eine Dependency. Lies den Wert
67
70
  vor dem `await` in eine lokale Variable.
68
- - ein `async`-Callback, dessen einziges `await` ein `return await x` ist: `async`
69
- und `await` weglassen und das Promise zurueckgeben. Innerhalb von `try` bleibt
70
- `return await` erlaubt, weil es das `catch` erst moeglich macht.
71
+ - ein `async`-Callback, dessen einziges `await` ein `return await x` ist:
72
+ `async` und `await` weglassen und das Promise zurueckgeben. Innerhalb von
73
+ `try` bleibt `return await` erlaubt, weil es das `catch` erst moeglich macht.
71
74
 
72
75
  Grenzen: Reads in verschachtelten Funktionen, Helfern und `.then`-Callbacks
73
76
  sieht die Regel nicht (die Laufzeit-Diagnose schon). Ob ein Name ein Signal ist,
@@ -77,15 +80,32 @@ Datei und aus dem Namen `props`.
77
80
  ### `solid/no-server-import-in-client`
78
81
 
79
82
  Client-Dateien (`.tsx` und `.ts` ausserhalb von `src/server/`, ohne
80
- Test-Dateien) duerfen ein Modul unter `src/server/` nur importieren, wenn dessen
81
- erste Anweisung `"use server"` ist. Der Pfad wird vom importierenden File aus
82
- aufgeloest (relativ oder `~/` = `<Projekt>/src/`, Projektwurzel = naechstes
83
- Verzeichnis mit `package.json`) und die Zieldatei gelesen. Fehlt das Ziel,
84
- wird nichts gemeldet. `import type` wird ignoriert. Geprueft werden auch
85
- `export ... from` und `import("...")` mit String-Literal.
86
-
87
- Grenze: andere Aliase und Server-Code ausserhalb von `src/server/` kennt die
88
- Regel nicht.
83
+ Test-Dateien) duerfen ein Modul unter `src/server/` nur importieren, wenn es die
84
+ Direktive `"use server"` hat. Der Pfad wird vom importierenden File aus
85
+ aufgeloest (relativ oder `~/` = `<Projekt>/src/`) und die Zieldatei gelesen.
86
+ Projektwurzel ist das naechste Verzeichnis ueber der Datei, das `src/server`
87
+ enthaelt (nicht das naechste `package.json`: das kann in jedem Unterordner
88
+ liegen). Die Suche nach oben endet beim ersten Verzeichnis mit `.git` oder mit
89
+ einer `package.json` mit `workspaces`; ein `src/server` weiter oben (etwa im
90
+ Home-Verzeichnis) gehoert zu etwas anderem. Ohne ein solches Verzeichnis meldet
91
+ die Regel nichts. Das Ergebnis wird pro Verzeichnis fuer die Laufzeit des
92
+ Prozesses gemerkt: ein `src/server`, das ein laufender Language Server erst
93
+ spaeter sieht, wird nach einem Neustart gefunden. Fehlt das Ziel, wird nichts
94
+ gemeldet. `import type` wird ignoriert. Geprueft werden auch `export ... from`,
95
+ `import("...")` und `require("...")`, jeweils mit String- oder Template-Literal
96
+ ohne Platzhalter.
97
+
98
+ Die Direktive muss im Direktiven-Prolog stehen, also unter den
99
+ String-Anweisungen am Dateianfang (`"use strict"; "use server";` zaehlt).
100
+ Kommentare davor sind erlaubt, ein Ausdruck wie `"use server".length;` oder
101
+ `("use server");` und ein Escape wie `"use\x20server"` nicht. Ein Zeilenumbruch
102
+ ohne Semikolon beendet die Anweisung nur dort, wo auch JavaScript ein Semikolon
103
+ einfuegt (eine Folgezeile mit `.`, `(`, `[`, einem Operator oder einem
104
+ Template-Literal gehoert noch zum String).
105
+
106
+ Grenzen: andere Aliase als `~/` und Server-Code ausserhalb von `src/server/`
107
+ kennt die Regel nicht, ein `require`, das lokal neu definiert ist, wird trotzdem
108
+ geprueft, und `package.json`-`exports`/`paths` werden nicht gelesen.
89
109
 
90
110
  ### `solid/strict-void-return`
91
111
 
@@ -104,21 +124,56 @@ Die Regel ist schwaecher als `typescript/strict-void-return`: sie sieht nur
104
124
  Inline-Callbacks, keine Funktionen, die per Namen uebergeben werden, und bei
105
125
  `onCleanup`/`onSettled` keine Calls, deren Rueckgabetyp sie nicht kennt.
106
126
 
107
- ## Nutzung ueber @murky-web/config
108
-
109
- Im Zielprojekt:
110
-
111
- ```bash
112
- web-dev-config init --oxc --typescript --frontend-solid
113
- ```
114
-
115
- Danach:
116
-
117
- - liegt die lokale Rule-Runtime unter `./oxc/jsplugins/solid/`
118
- - wird `./linting/solid.jsonc` in die Oxc-Konfiguration eingehängt
119
- - zeigt `jsPlugins` auf `./jsplugins/solid/index.mjs`
120
- - feuern sowohl die portierten Solid-Regeln als auch
121
- `solid/prefer-arrow-components`
127
+ ### `solid/validate-jsx-nesting`
128
+
129
+ Meldet HTML-Verschachtelung, die der Browser umbaut, so dass das gerenderte DOM
130
+ nicht dem JSX entspricht: `<p><div /></p>`, ein Link im Link, ein Button im
131
+ Button, `<tr>` direkt in `<table>` (der Parser setzt ein `<tbody>` dazwischen),
132
+ `<td>` ausserhalb einer Zeile, ein `<div>` im `<svg>` und aehnliches. Der
133
+ Elternknoten wird durch Fragmente, Expression-Container, Arrays und `&&`/`?:`
134
+ hindurch gesucht; ein Kind, das erst durch einen Ausdruck (`{cond && <div />}`)
135
+ in den Elternknoten kommt, bekommt die Meldung fuer Hydration (der Client baut
136
+ es wie geschrieben, nur der vom Server gerenderte HTML-Text wird umgebaut).
137
+
138
+ Die Regel ist die aus `eslint-plugin-solid` 0.20 (MIT, Josh Wilson) und arbeitet
139
+ wie dort in zwei Schritten: `validate-html-nesting` (ISC) sagt, ob ein Paar nach
140
+ der HTML-Spezifikation gueltig ist, und parse5 -- der Parser, den auch Solids
141
+ Compiler fuer Templates nutzt -- entscheidet, ob er das Kind wirklich anders
142
+ einsortiert. Nur dann gibt es eine Meldung; Markup, das die Spezifikation
143
+ verbietet, der Parser aber so laesst (`<div><figcaption /></div>`,
144
+ `<h1><div /></h1>`), wird nicht gemeldet. Der Inhalt von `<svg>` und `<math>`
145
+ wird in dem Namensraum geprueft, den der Parser dort hat
146
+ (`<svg><a><a /></a></svg>` bleibt erlaubt, unter `<foreignObject>` oder `<p>`
147
+ gilt wieder HTML). Abweichung von Upstream: ein `<input type="hidden">` in einer
148
+ Tabelle wird nicht gemeldet, der Parser laesst es dort stehen. Grenzen: ein
149
+ Elternknoten, der kein DOM-Element ist (`<Show>`, eine Komponente, ein
150
+ `.map()`-Callback), wird nicht durchschaut.
151
+
152
+ ## Autofixes
153
+
154
+ `oxlint --fix` schreibt nur Code, der danach noch dasselbe tut. Wo ein Umbau das
155
+ nicht sicher kann, bleibt es bei der Meldung ohne Fix:
156
+
157
+ - `solid/prefer-arrow-components`: eine Funktion, die vor ihrer Deklaration
158
+ gelesen wird (`export const routes = [{ component: Home }]` vor
159
+ `export function Home`), wird nicht umgeschrieben, weil die `const` dort noch
160
+ nicht initialisiert waere (ReferenceError). Zaehlt jede Stelle vor der
161
+ Deklaration, auch in einer Funktion, weil das Plugin nicht weiss, wann sie
162
+ laeuft. `export default function Page` wird zu `const Page ... ;` plus
163
+ `export default Page;`. Der `solid-js`-Typ-Import steht einmal oben in der
164
+ Datei, nach einer `"use client"`-Direktive.
165
+ - `solid/no-destructure`: ein verschachteltes Muster (`{ user: { name } }`), ein
166
+ berechneter Schluessel, der kein Literal ist (`{ [key]: label }`), eine
167
+ Zuweisung an einen destrukturierten Namen und ein Default, der einen frueheren
168
+ Prop liest, werden nur gemeldet. Der neue Parameter heisst `props`, oder
169
+ `props2`, `props3`, ... wenn der Name in einem umgebenden Scope schon vergeben
170
+ ist (sonst faengt er die Reads des aeusseren `props` ab). Ein Shorthand
171
+ (`{ title }`) wird zu `{ title: props.title }`.
172
+ - `solid/imports`: ein Wert wird nie in ein `import type` verschoben, ein Typ
173
+ kommt in einem Wert-Import als `type Name` an und in einem `import type` ohne
174
+ `type`; passt keine vorhandene Deklaration, schreibt der Fix eine neue.
175
+ - `solid/prefer-class-object`: steht neben `classList` schon ein `class`, wird
176
+ nur gemeldet (der Fix haette `class` doppelt geschrieben).
122
177
 
123
178
  Ein typischer Fix-Fall:
124
179
 
@@ -0,0 +1,54 @@
1
+ # Third-party notices
2
+
3
+ ## eslint-plugin-solid
4
+
5
+ https://github.com/solidjs-community/eslint-plugin-solid
6
+
7
+ Most rules of this package are ports of rules from eslint-plugin-solid,
8
+ rewritten as plain JavaScript on the Oxlint AST (the original port is the 0.14.5
9
+ state, see `meta.version` in `src/index.mjs`; `validate-jsx-nesting` was ported
10
+ again from 0.20.0). The rules and the helpers they share are covered by its
11
+ licence:
12
+
13
+ - `components-return-once`, `event-handlers`, `imports`,
14
+ `jsx-no-duplicate-props`, `jsx-no-script-url`, `jsx-no-undef`,
15
+ `jsx-uses-vars`, `no-array-handlers`, `no-destructure`, `no-innerhtml`,
16
+ `no-proxy-apis`, `no-react-deps`, `no-react-specific-props`,
17
+ `no-unknown-namespaces`, `prefer-for`, `prefer-show`, `reactivity`,
18
+ `self-closing-comp`, `style-prop`, `validate-jsx-nesting` (`src/rules/`)
19
+ - `prefer-class-object`, derived from the upstream rule `prefer-classlist`
20
+ - the helpers in `src/utils.mjs` and `src/compat.mjs`
21
+
22
+ The rules `no-owned-primitives-in-ref`, `no-server-import-in-client`,
23
+ `no-setter-in-effect`, `no-untracked-effect-read`, `prefer-arrow-components`,
24
+ `reactive-async` and `strict-void-return` are not from eslint-plugin-solid.
25
+
26
+ ```
27
+ MIT License
28
+
29
+ Copyright (c) 2021 Josh Wilson
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ of this software and associated documentation files (the "Software"), to deal
33
+ in the Software without restriction, including without limitation the rights
34
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
+ copies of the Software, and to permit persons to whom the Software is
36
+ furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in all
39
+ copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47
+ SOFTWARE.
48
+ ```
49
+
50
+ ## validate-html-nesting
51
+
52
+ `validate-html-nesting` (ISC, Copyright (c) Manan Tank) is a dependency of this
53
+ package and no code of it is copied into the repository, so its own licence file
54
+ travels with the installed package.
package/package.json CHANGED
@@ -1,43 +1,47 @@
1
1
  {
2
2
  "name": "@murky-web/oxlint-plugin-solid",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
+ "private": false,
4
5
  "description": "Local Oxlint JS plugin port for Solid rules plus Murky-specific Solid conventions.",
6
+ "homepage": "https://github.com/MurkyTheMurloc/web_dev_tools/tree/main/packages/oxlint-plugin-solid",
7
+ "bugs": {
8
+ "url": "https://github.com/MurkyTheMurloc/web_dev_tools/issues"
9
+ },
5
10
  "license": "MIT",
6
- "private": false,
7
- "type": "module",
8
- "exports": {
9
- ".": "./src/index.mjs"
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/MurkyTheMurloc/web_dev_tools.git",
14
+ "directory": "packages/oxlint-plugin-solid"
10
15
  },
11
16
  "files": [
12
17
  "README.md",
18
+ "THIRD_PARTY_NOTICES.md",
13
19
  "src"
14
20
  ],
15
- "scripts": {
16
- "test": "bun test ./tests"
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "exports": {
24
+ ".": "./src/index.mjs"
17
25
  },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/MurkyTheMurloc/web_dev_tools.git",
21
- "directory": "packages/oxlint-plugin-solid"
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
22
29
  },
23
- "homepage": "https://github.com/MurkyTheMurloc/web_dev_tools/tree/main/packages/oxlint-plugin-solid",
24
- "bugs": {
25
- "url": "https://github.com/MurkyTheMurloc/web_dev_tools/issues"
30
+ "scripts": {
31
+ "test": "vitest run"
26
32
  },
27
- "sideEffects": false,
28
33
  "dependencies": {
29
- "@eslint-community/eslint-utils": "^4.9.1",
34
+ "@eslint-community/eslint-utils": "^4.10.1",
30
35
  "estraverse": "^5.3.0",
31
- "is-html": "^2.0.0",
32
- "kebab-case": "^1.0.2",
33
- "known-css-properties": "^0.30.0",
34
- "style-to-object": "^1.0.8"
36
+ "is-html": "^3.2.0",
37
+ "kebab-case": "^2.0.2",
38
+ "known-css-properties": "^0.37.0",
39
+ "parse5": "^8.1.1",
40
+ "style-to-object": "^2.0.2",
41
+ "validate-html-nesting": "^1.2.4"
35
42
  },
36
43
  "devDependencies": {
37
- "solid-js": "^1.9.15"
38
- },
39
- "publishConfig": {
40
- "access": "public",
41
- "provenance": true
44
+ "@solidjs/web": "^2.0.3",
45
+ "solid-js": "^2.0.3"
42
46
  }
43
47
  }
package/src/index.mjs CHANGED
@@ -12,8 +12,8 @@ import noOwnedPrimitivesInRefRule from "./rules/no_owned_primitives_in_ref.mjs";
12
12
  import noProxyApisRule from "./rules/no_proxy_apis.mjs";
13
13
  import noReactDepsRule from "./rules/no_react_deps.mjs";
14
14
  import { noReactSpecificPropsRule } from "./rules/no_react_specific_props.mjs";
15
- import noSetterInEffectRule from "./rules/no_setter_in_effect.mjs";
16
15
  import { noServerImportInClientRule } from "./rules/no_server_import_in_client.mjs";
16
+ import noSetterInEffectRule from "./rules/no_setter_in_effect.mjs";
17
17
  import noUnknownNamespacesRule from "./rules/no_unknown_namespaces.mjs";
18
18
  import noUntrackedEffectReadRule from "./rules/no_untracked_effect_read.mjs";
19
19
  import { preferArrowComponentsRule } from "./rules/prefer_arrow_components.mjs";
@@ -113,13 +113,12 @@ export default {
113
113
  messages: {
114
114
  "detected-attr":
115
115
  'The {{name}} prop is named as an event handler (starts with "on"), but Solid knows its value ({{staticValue}}) is a string or number, so it will be treated as an attribute. If this is intentional, use the plain attribute name instead of an on-prefixed one.',
116
- naming: "The {{name}} prop is ambiguous. If it is an event handler, change it to {{handlerName}}. If it is an attribute, change it to {{attrName}}.",
116
+ naming: "In Solid 2.0, {{name}} is a plain attribute, not an event handler, so a function value is never called. If it is an event handler, change it to {{handlerName}}.",
117
117
  capitalization:
118
118
  "The {{name}} prop should be renamed to {{fixedName}} for readability.",
119
119
  nonstandard:
120
120
  "The {{name}} prop should be renamed to {{fixedName}}, because it's not a standard event handler.",
121
121
  "make-handler": "Change the {{name}} prop to {{handlerName}}.",
122
- "make-attr": "Change the {{name}} prop to {{attrName}}.",
123
122
  "spread-handler":
124
123
  "The {{name}} prop should be added as a JSX attribute, not spread in. Solid doesn't add listeners when spreading into JSX.",
125
124
  },
@@ -216,14 +215,15 @@ export default {
216
215
  }
217
216
  } else if (name[2] === name[2].toLowerCase()) {
218
217
  // this includes words like `only` and `ongoing` as well as unknown handlers like `onfoobar`.
219
- // Enforce using either /^on[A-Z]/ (event handler) or /^attr:on[a-z]/ (forced regular attribute)
220
- // to make user intent clear and code maximally readable
218
+ // Enforce /^on[A-Z]/ (event handler) to make user intent clear. Solid 2.0
219
+ // removed the `attr:` namespace: attributes are the default there, so a
220
+ // lowercase `on...` name is already a plain attribute and there is no
221
+ // `attr:` form to suggest.
221
222
  const handlerName = `on${name[2].toUpperCase()}${name.slice(3)}`;
222
- const attrName = `attr:${name}`;
223
223
  context.report({
224
224
  node: node.name,
225
225
  messageId: "naming",
226
- data: { name, attrName, handlerName },
226
+ data: { name, handlerName },
227
227
  suggest: [
228
228
  {
229
229
  messageId: "make-handler",
@@ -234,12 +234,6 @@ export default {
234
234
  handlerName,
235
235
  ),
236
236
  },
237
- {
238
- messageId: "make-attr",
239
- data: { name, attrName },
240
- fix: (fixer) =>
241
- fixer.replaceText(node.name, attrName),
242
- },
243
237
  ],
244
238
  });
245
239
  }
@@ -1,36 +1,38 @@
1
1
  import { getSourceCode } from "../compat.mjs";
2
- import { appendImports, insertImports, removeSpecifier } from "../utils.mjs";
2
+ import {
3
+ appendImports,
4
+ canTakeSpecifier,
5
+ insertImports,
6
+ removeSpecifier,
7
+ } from "../utils.mjs";
3
8
  // Solid 2.0 moved the renderers into `@solidjs/*` packages and pulled the store
4
9
  // APIs into the core. Symbols that are legitimately exported from more than one
5
10
  // package (the control-flow components, `ComponentProps`) are deliberately left
6
- // out of these maps: there is no single correct source to point at.
11
+ // out of these maps: there is no single correct source to point at. That also
12
+ // covers `dynamicComponent`, which `@solidjs/web` re-exports from `solid-js`.
7
13
  const primitiveMap = new Map();
8
14
  for (const primitive of [
9
15
  "action",
10
16
  "affects",
11
17
  "children",
12
18
  "createContext",
19
+ "createDeferred",
13
20
  "createEffect",
14
- // The primitive forms of `Loading`, `Errored` and `Reveal`. Only custom
15
- // boundary components and renderer integrations reach for them, which is
16
- // why they were missing here — and why a wrong-module import of one went
17
- // unreported while every neighbouring primitive was checked.
18
- "createErrorBoundary",
19
- "createLoadingBoundary",
20
21
  "createMemo",
21
22
  "createOptimistic",
22
23
  "createOptimisticStore",
23
24
  "createProjection",
24
25
  "createReaction",
25
26
  "createRenderEffect",
26
- "createRevealOrder",
27
27
  "createRoot",
28
28
  "createSignal",
29
29
  "createStore",
30
+ "createTrackedEffect",
30
31
  "createUniqueId",
31
32
  "deep",
32
33
  "DEV",
33
34
  "flush",
35
+ "from",
34
36
  "getObserver",
35
37
  "getOwner",
36
38
  "isEqual",
@@ -41,13 +43,14 @@ for (const primitive of [
41
43
  "merge",
42
44
  "omit",
43
45
  "onCleanup",
46
+ "onFlush",
44
47
  "onSettled",
45
48
  "reconcile",
46
49
  "refresh",
50
+ "repeat",
47
51
  "resolve",
48
52
  "runWithOwner",
49
53
  "snapshot",
50
- "storePath",
51
54
  "untrack",
52
55
  "until",
53
56
  "useContext",
@@ -91,17 +94,42 @@ for (const type of [
91
94
  "Ref",
92
95
  "ResolvedChildren",
93
96
  "Signal",
94
- "ValidComponent",
95
97
  "VoidComponent",
96
98
  "VoidProps",
97
99
  ]) {
98
100
  typeMap.set(type, "solid-js");
99
101
  }
100
- for (const type of ["ClassValue", "IntrinsicElement", "JSX", "RequestEvent"]) {
102
+ // `ClassValue` is not listed: it only exists as `JSX.ClassValue`. Neither is
103
+ // `ValidComponent`: `solid-js` and `@solidjs/web` each declare their own.
104
+ for (const type of ["IntrinsicElement", "JSX", "RequestEvent"]) {
101
105
  typeMap.set(type, "@solidjs/web");
102
106
  }
103
107
  const sourceRegex = /^(?:solid-js|@solidjs\/(?:web|h|html|universal))$/;
104
108
  const isSource = (source) => sourceRegex.test(source);
109
+ const isTypeDeclaration = (declaration) => declaration.importKind === "type";
110
+ // The text of a specifier without its own `type` modifier, with one if asked
111
+ // for: the modifier belongs to the declaration the specifier ends up in.
112
+ const specifierText = (specifier, asType) => {
113
+ const imported = specifier.imported.name ?? specifier.imported.value;
114
+ const local = specifier.local.name;
115
+ const text = imported === local ? imported : `${imported} as ${local}`;
116
+ return asType ? `type ${text}` : text;
117
+ };
118
+ // The declaration from `source` that a specifier can join: for a type one a
119
+ // type declaration first, then a value declaration. None if every one is of
120
+ // the wrong kind; the caller then writes a declaration of its own.
121
+ const findTarget = (program, source, isType) => {
122
+ const candidates = program.body.filter(
123
+ (node) =>
124
+ node.type === "ImportDeclaration" &&
125
+ node.source.value === source &&
126
+ canTakeSpecifier(node, isType),
127
+ );
128
+ return (
129
+ (isType ? candidates.find(isTypeDeclaration) : undefined) ??
130
+ candidates.at(0)
131
+ );
132
+ };
105
133
  export default {
106
134
  meta: {
107
135
  type: "suggestion",
@@ -140,14 +168,16 @@ export default {
140
168
  fix(fixer) {
141
169
  const sourceCode = getSourceCode(context);
142
170
  const program = sourceCode.ast;
143
- const correctDeclaration =
144
- program.body.find(
145
- (node) =>
146
- node.type ===
147
- "ImportDeclaration" &&
148
- node.source.value ===
149
- correctSource,
150
- );
171
+ // A value never joins an `import type`
172
+ // (it would be gone at run time), and a
173
+ // type joins a value import only as
174
+ // `type Name`: the specifier is written
175
+ // for the declaration that takes it.
176
+ const correctDeclaration = findTarget(
177
+ program,
178
+ correctSource,
179
+ isType,
180
+ );
151
181
  if (correctDeclaration) {
152
182
  return [
153
183
  removeSpecifier(
@@ -159,7 +189,14 @@ export default {
159
189
  fixer,
160
190
  sourceCode,
161
191
  correctDeclaration,
162
- [sourceCode.getText(specifier)],
192
+ [
193
+ specifierText(
194
+ specifier,
195
+ isType &&
196
+ correctDeclaration.importKind !==
197
+ "type",
198
+ ),
199
+ ],
163
200
  ),
164
201
  ].filter(Boolean);
165
202
  }
@@ -180,7 +217,7 @@ export default {
180
217
  fixer,
181
218
  sourceCode,
182
219
  correctSource,
183
- [sourceCode.getText(specifier)],
220
+ [specifierText(specifier, false)],
184
221
  firstSolidDeclaration,
185
222
  isType,
186
223
  ),
@@ -2,9 +2,13 @@ import { getStaticValue } from "@eslint-community/eslint-utils";
2
2
 
3
3
  import { getScope } from "../compat.mjs";
4
4
 
5
- const JAVASCRIPT_PROTOCOL_PATTERN =
6
- "^[\\\\u0000-\\\\u001F ]*j[\\\\r\\\\n\\\\t]*a[\\\\r\\\\n\\\\t]*v[\\\\r\\\\n\\\\t]*a[\\\\r\\\\n\\\\t]*s[\\\\r\\\\n\\\\t]*c[\\\\r\\\\n\\\\t]*r[\\\\r\\\\n\\\\t]*i[\\\\r\\\\n\\\\t]*p[\\\\r\\\\n\\\\t]*t[\\\\r\\\\n\\\\t]*:";
7
- const JAVASCRIPT_PROTOCOL_REGEX = new RegExp(JAVASCRIPT_PROTOCOL_PATTERN, "i");
5
+ // A browser strips leading C0 control characters and spaces and drops tabs and
6
+ // newlines inside the scheme before it reads the protocol, so all of
7
+ // `"\njavascript:"`, `"\u0001javascript:"` and `"java\tscript:"` run code.
8
+ // The regex literal is the one of eslint-plugin-solid 0.20: it is not an
9
+ // escaped string, where `\\u0000` would match a backslash and the text `u0000`.
10
+ const JAVASCRIPT_PROTOCOL_REGEX =
11
+ /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;
8
12
 
9
13
  export const jsxNoScriptUrlRule = {
10
14
  meta: {
@@ -70,6 +70,7 @@ export default {
70
70
  const missingComponentsSet = new Set();
71
71
  /**
72
72
  * Compare an identifier with the variables declared in the scope
73
+ *
73
74
  * @param {ASTNode} node - Identifier or JSXIdentifier node
74
75
  * @returns {void}
75
76
  */