Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/eslint-plugin-solid/docs/imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ import { render, createEffect } from "solid-js";
import { render } from "solid-js/web";
import { createEffect } from "solid-js";

import { createSignal, useHead } from "solid-js";
// after eslint --fix:
import { useHead } from "@solidjs/web";
import { createSignal } from "solid-js";

import { render, onFlush } from "@solidjs/web";
// after eslint --fix:
import { onFlush } from "solid-js";
import { render } from "@solidjs/web";

import { type JSX } from "solid-js";
// after eslint --fix:
import { type JSX } from "@solidjs/web";
Expand Down Expand Up @@ -105,6 +115,24 @@ import { createSignal, createStore, reconcile, merge } from "solid-js";

import { render, Portal, Dynamic, isServer } from "@solidjs/web";

import {
createDeferred,
createTrackedEffect,
onFlush,
until,
from,
Hydration,
NoHydration,
} from "solid-js";
import {
dynamic,
clientOnly,
useHead,
getRequestEvent,
redirect,
respond,
} from "@solidjs/web";

import type { JSX, ValidComponent, ComponentProps } from "@solidjs/web";

import type { ValidComponent, ComponentProps } from "solid-js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ This rule is enabled as an error in the `v2-strict` config only.
These snippets cause lint errors.

```js
import { createDeferred } from "solid-js";
export const results = createDeferred(async () => fetchResults());

import { createSignal } from "solid-js";
const [count, setCount] = createSignal(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ This rule is enabled as an error in the `v2` and `v2-strict` configs.
These snippets cause lint errors.

```js
import { createSignal, createDeferred } from "solid-js";
const [count, setCount] = createSignal(0);
const bad = createDeferred(() => {
setCount(count() + 1);
return count();
});

import { createSignal, createMemo } from "solid-js";
const [count, setCount] = createSignal(0);
const bad = createMemo(() => {
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin-solid/docs/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,32 @@ function Component(props) {
return <Test />;
}

import { createDeferred, createSignal } from "solid-js";
function Component() {
const [id] = createSignal(1);
const deferred = createDeferred(async () =>
(await fetch(`/x/${id()}`)).text()
);
return <p>{deferred()}</p>;
}

import { createSignal, until } from "solid-js";
function Component() {
const [count] = createSignal(0);
const ready = until(() => count() > 3);
ready.then(() => console.log("ready"));
return <p>{count()}</p>;
}

import { createSignal, onFlush } from "solid-js";
function Component() {
const [count] = createSignal(0);
onFlush(() => {
document.title = String(count());
});
return <p>{count()}</p>;
}

// Requires settings.solid.moduleSources: ["my-solid-renderer"].
import { createSignal } from "solid-js";
import { dynamicComponent } from "my-solid-renderer";
Expand Down
67 changes: 67 additions & 0 deletions packages/eslint-plugin-solid/docs/removed-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,48 @@ import type { Store } from "solid-js";

import { createStore, produce } from "solid-js/store";

import { createDynamic } from "@solidjs/web";

import { pipeToWritable, pipeToNodeWritable } from "@solidjs/web";

import { enableScheduling } from "solid-js";

import h from "solid-js/h";
// after eslint --fix:
import h from "@solidjs/h";

import html from "solid-js/html";
// after eslint --fix:
import html from "@solidjs/html";

import { createRenderer } from "solid-js/universal";
// after eslint --fix:
import { createRenderer } from "@solidjs/universal";

import { createContext } from "solid-js";
const Theme = createContext("light");
let el = (
<Theme.Provider value="dark">
<App />
</Theme.Provider>
);
// after eslint --fix:
import { createContext } from "solid-js";
const Theme = createContext("light");
let el = (
<Theme value="dark">
<App />
</Theme>
);

import { createContext as cc } from "solid-js";
const Theme = cc();
let el = <Theme.Provider value="dark" />;
// after eslint --fix:
import { createContext as cc } from "solid-js";
const Theme = cc();
let el = <Theme value="dark" />;

let el = <div classList={{ active: isActive() }} />;
// after eslint --fix:
let el = <div class={{ active: isActive() }} />;
Expand Down Expand Up @@ -128,5 +170,30 @@ let el = <div class={{ active: true }} />;

let el = <div class="btn" />;

import { dynamic, renderToStream } from "@solidjs/web";

import { createContext } from "solid-js";
const Theme = createContext("light");
let el = (
<Theme value="dark">
<App />
</Theme>
);

import { createContext } from "react";
const Theme = createContext("light");
let el = (
<Theme.Provider value="dark">
<App />
</Theme.Provider>
);

import { Theme } from "./theme";
let el = (
<Theme.Provider value="dark">
<App />
</Theme.Provider>
);

```
<!-- end-doc-gen -->
2 changes: 1 addition & 1 deletion packages/eslint-plugin-solid/docs/rule-confidence.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ rule infers intent and has documented escapes.
| `prefer-for` | Near-certain | `.map` returning JSX in JSX is list rendering; `<For>` is the canonical form and the fix is mechanical. The one soft spot — mapping a never-changing static array — still works identically under `<For>`, so the canonical-form value (one way to render lists, for humans and agents alike) outweighs it. |
| `event-handlers` | Certain (v2 mode) | Both v2 reports are structural facts: a camelCase handler with a static string/number value, and a lowercase `on*` attribute holding a function (a listener that never fires). Dynamic-string literal attributes are exempted. |
| `no-react-specific-props` | Certain on DOM | `className`/`htmlFor` on DOM elements are dead attributes in 2.0. On components they are technically the component's own API, but a Solid component exposing `className` contradicts ecosystem convention so thoroughly that the report is still the right guidance; kept. |
| `removed-api` | Certain | Import-based, verified against the 2.0 RC source. The `classList` JSX check also fires on components; as with `className`, a component exposing a `classList` prop in a 2.0 codebase is API that needs the same migration. |
| `removed-api` | Certain | Import-based, verified against the 2.0.0 source. The `classList` JSX check also fires on components; as with `className`, a component exposing a `classList` prop in a 2.0 codebase is API that needs the same migration. |
| `no-single-arg-create-effect` | Certain | Import-gated; the single-argument form throws at runtime in dev. (`createEffect(...tuple)` spread would false-positive; considered negligible.) |
| `no-accessor-as-prop` | Certain | Only fires when the identifier statically resolves to a signal/memo/function, only on plain attributes of DOM elements, with `ref`/`children`/`on*` excluded. |

Expand Down
21 changes: 19 additions & 2 deletions packages/eslint-plugin-solid/src/rules/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,19 @@ const alternateSourceMap = new Map<string, Source>([
// Solid 2.0: "solid-js/store" no longer exists (store exports live in core),
// and "solid-js/web" became the "@solidjs/web" package. When `settings.solid.
// version` is 2, the rule *requires* the 2.0 locations. Lists verified against
// the RC source (packages/solid/src/index.ts, packages/solid-web/src/index.ts).
// the 2.0.0 source (packages/solid/src/index.ts, packages/solid-web/src/index.ts).
type SourceV2 = "solid-js" | "@solidjs/web";

const primitiveMapV2 = new Map<string, SourceV2>();
for (const primitive of [
// reactive primitives
"createSignal",
"createMemo",
"createDeferred",
"createStore",
"createEffect",
"createRenderEffect",
"createTrackedEffect",
"createProjection",
"createOptimistic",
"createOptimisticStore",
Expand All @@ -162,7 +164,10 @@ for (const primitive of [
// lifecycle and utilities
"onCleanup",
"onSettled",
"onFlush",
"untrack",
"until",
"from",
"flush",
"merge",
"omit",
Expand All @@ -182,7 +187,8 @@ for (const primitive of [
"flatten",
"deep",
"affects",
"storePath",
"dynamicComponent",
"isHydrating",
"DEV",
// control flow components
"For",
Expand All @@ -193,6 +199,8 @@ for (const primitive of [
"Errored",
"Loading",
"Reveal",
"Hydration",
"NoHydration",
]) {
primitiveMapV2.set(primitive, "solid-js");
}
Expand All @@ -207,6 +215,15 @@ for (const primitive of [
// renderToStringAsync no longer exists in 2.0 (removed-api reports it)
"generateHydrationScript",
"HydrationScript",
"dynamic",
"clientOnly",
"useHead",
"getRequestEvent",
"redirect",
"reload",
"respond",
"httpStatus",
"httpHeader",
]) {
primitiveMapV2.set(primitive, "@solidjs/web");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Options = [];
const REACTIVE_PRIMITIVES = [
"createSignal",
"createMemo",
"createDeferred",
"createStore",
"createEffect",
"createRenderEffect",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createRule, findVariableInScope, getScope } from "../compat";
type MessageIds = "restatedDefault";
type Options = [];

// Defaults verified against the Solid 2.0 RC source (client/flow.ts):
// Defaults verified against the Solid 2.0.0 source (client/flow.ts):
// <For> is keyed by default; <Show> and <Match> are non-keyed by default.
const JSX_PROP_DEFAULTS: Record<string, Record<string, boolean>> = {
For: { keyed: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const v2MigrationGuidance: Record<string, string> = {
on: "For an event handler, use the camelCase form instead: `onClick`",
oncapture:
"There is no capture-phase prefix in Solid 2.0; add a capture listener with `addEventListener` in a `ref` if needed",
use: "Directives were removed in Solid 2.0; call the function in `ref` instead: `ref={(el) => myDirective(el)}`",
use: "Directives were removed in Solid 2.0; pass a directive factory to `ref` instead: `ref={myDirective(options)}`, with owned setup in the factory and element work in the callback it returns",
attr: "Use the plain attribute name; attributes are the default in Solid 2.0",
bool: "Use the plain attribute with a boolean or conditional value",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default createRule<Options, MessageIds>({
schema: [],
messages: {
writeInMemo:
"Calling the setter '{{name}}' inside createMemo makes the computation impure and creates an update cycle. Derive the value instead of storing it, or move the write to an effect.",
"Calling the setter '{{name}}' inside {{api}} makes the computation impure and creates an update cycle. Derive the value instead of storing it, or move the write to an effect.",
writeInCompute:
"Calling the setter '{{name}}' in the compute half of {{api}} — the compute function is tracked and must be pure. Move the write into the effect half (the second argument).",
writeInComponent:
Expand Down Expand Up @@ -189,10 +189,11 @@ export default createRule<Options, MessageIds>({

// Register pure computation callbacks. Ancestors are visited before
// descendants, so these are known before their setter calls are seen.
if (matchImport("createMemo", node.callee.name)) {
const memoName = matchImport(["createMemo", "createDeferred"], node.callee.name);
if (memoName) {
const fn = node.arguments[0];
if (isFunctionNode(fn)) {
computations.set(fn, { messageId: "writeInMemo", api: "createMemo" });
computations.set(fn, { messageId: "writeInMemo", api: memoName });
}
return;
}
Expand Down
18 changes: 14 additions & 4 deletions packages/eslint-plugin-solid/src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,16 +1371,23 @@ export default createRule<Options, MessageIds>({
"createRevealOrder",
"dynamic",
"dynamicComponent",
"until",
],
callee.name
)
) {
// createEffect, createMemo, etc. fn arg. createMemo, dynamic, and dynamicComponent
// may take an async function in Solid 2.0; only reads before its first `await` are tracked.
// createEffect, createMemo, etc. fn arg. createMemo, createDeferred, dynamic, and
// dynamicComponent may take an async function in Solid 2.0; only reads before its
// first `await` are tracked. until(fn) tracks its predicate until it is truthy.
pushTrackedScope(
arg0,
"function",
Boolean(matchImport(["createMemo", "dynamic", "dynamicComponent"], callee.name))
Boolean(
matchImport(
["createMemo", "createDeferred", "dynamic", "dynamicComponent"],
callee.name
)
)
);
if (
matchImport(["createErrorBoundary", "createLoadingBoundary"], callee.name) &&
Expand Down Expand Up @@ -1445,7 +1452,10 @@ export default createRule<Options, MessageIds>({
// is permissive under both semantics.
pushTrackedScope(arg0, "function", true);
} else if (
matchImport(["onMount", "onCleanup", "onError", "onSettled", "action"], callee.name) ||
matchImport(
["onMount", "onCleanup", "onError", "onSettled", "onFlush", "action"],
callee.name
) ||
[
// Timers
"setInterval",
Expand Down
Loading
Loading