diff --git a/packages/eslint-plugin-solid/docs/imports.md b/packages/eslint-plugin-solid/docs/imports.md index 6db569c..a325d58 100644 --- a/packages/eslint-plugin-solid/docs/imports.md +++ b/packages/eslint-plugin-solid/docs/imports.md @@ -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"; @@ -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"; diff --git a/packages/eslint-plugin-solid/docs/no-module-scope-reactive-primitive.md b/packages/eslint-plugin-solid/docs/no-module-scope-reactive-primitive.md index 27b806d..504bf21 100644 --- a/packages/eslint-plugin-solid/docs/no-module-scope-reactive-primitive.md +++ b/packages/eslint-plugin-solid/docs/no-module-scope-reactive-primitive.md @@ -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); diff --git a/packages/eslint-plugin-solid/docs/no-write-in-pure-computation.md b/packages/eslint-plugin-solid/docs/no-write-in-pure-computation.md index 05995ea..3a320b6 100644 --- a/packages/eslint-plugin-solid/docs/no-write-in-pure-computation.md +++ b/packages/eslint-plugin-solid/docs/no-write-in-pure-computation.md @@ -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(() => { diff --git a/packages/eslint-plugin-solid/docs/reactivity.md b/packages/eslint-plugin-solid/docs/reactivity.md index a11ac95..16f1e7f 100644 --- a/packages/eslint-plugin-solid/docs/reactivity.md +++ b/packages/eslint-plugin-solid/docs/reactivity.md @@ -1454,6 +1454,32 @@ function Component(props) { return ; } +import { createDeferred, createSignal } from "solid-js"; +function Component() { + const [id] = createSignal(1); + const deferred = createDeferred(async () => + (await fetch(`/x/${id()}`)).text() + ); + return

{deferred()}

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

{count()}

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

{count()}

; +} + // Requires settings.solid.moduleSources: ["my-solid-renderer"]. import { createSignal } from "solid-js"; import { dynamicComponent } from "my-solid-renderer"; diff --git a/packages/eslint-plugin-solid/docs/removed-api.md b/packages/eslint-plugin-solid/docs/removed-api.md index 401ac85..7168942 100644 --- a/packages/eslint-plugin-solid/docs/removed-api.md +++ b/packages/eslint-plugin-solid/docs/removed-api.md @@ -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 = ( + + + +); +// after eslint --fix: +import { createContext } from "solid-js"; +const Theme = createContext("light"); +let el = ( + + + +); + +import { createContext as cc } from "solid-js"; +const Theme = cc(); +let el = ; +// after eslint --fix: +import { createContext as cc } from "solid-js"; +const Theme = cc(); +let el = ; + let el =
; // after eslint --fix: let el =
; @@ -128,5 +170,30 @@ let el =
; let el =
; +import { dynamic, renderToStream } from "@solidjs/web"; + +import { createContext } from "solid-js"; +const Theme = createContext("light"); +let el = ( + + + +); + +import { createContext } from "react"; +const Theme = createContext("light"); +let el = ( + + + +); + +import { Theme } from "./theme"; +let el = ( + + + +); + ``` diff --git a/packages/eslint-plugin-solid/docs/rule-confidence.md b/packages/eslint-plugin-solid/docs/rule-confidence.md index 3bdadd5..4c0212f 100644 --- a/packages/eslint-plugin-solid/docs/rule-confidence.md +++ b/packages/eslint-plugin-solid/docs/rule-confidence.md @@ -80,7 +80,7 @@ rule infers intent and has documented escapes. | `prefer-for` | Near-certain | `.map` returning JSX in JSX is list rendering; `` is the canonical form and the fix is mechanical. The one soft spot — mapping a never-changing static array — still works identically under ``, 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. | diff --git a/packages/eslint-plugin-solid/src/rules/imports.ts b/packages/eslint-plugin-solid/src/rules/imports.ts index 458995f..3008f54 100644 --- a/packages/eslint-plugin-solid/src/rules/imports.ts +++ b/packages/eslint-plugin-solid/src/rules/imports.ts @@ -134,7 +134,7 @@ const alternateSourceMap = new Map([ // 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(); @@ -142,9 +142,11 @@ for (const primitive of [ // reactive primitives "createSignal", "createMemo", + "createDeferred", "createStore", "createEffect", "createRenderEffect", + "createTrackedEffect", "createProjection", "createOptimistic", "createOptimisticStore", @@ -162,7 +164,10 @@ for (const primitive of [ // lifecycle and utilities "onCleanup", "onSettled", + "onFlush", "untrack", + "until", + "from", "flush", "merge", "omit", @@ -182,7 +187,8 @@ for (const primitive of [ "flatten", "deep", "affects", - "storePath", + "dynamicComponent", + "isHydrating", "DEV", // control flow components "For", @@ -193,6 +199,8 @@ for (const primitive of [ "Errored", "Loading", "Reveal", + "Hydration", + "NoHydration", ]) { primitiveMapV2.set(primitive, "solid-js"); } @@ -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"); } diff --git a/packages/eslint-plugin-solid/src/rules/no-module-scope-reactive-primitive.ts b/packages/eslint-plugin-solid/src/rules/no-module-scope-reactive-primitive.ts index 472f719..7a15352 100644 --- a/packages/eslint-plugin-solid/src/rules/no-module-scope-reactive-primitive.ts +++ b/packages/eslint-plugin-solid/src/rules/no-module-scope-reactive-primitive.ts @@ -15,6 +15,7 @@ type Options = []; const REACTIVE_PRIMITIVES = [ "createSignal", "createMemo", + "createDeferred", "createStore", "createEffect", "createRenderEffect", diff --git a/packages/eslint-plugin-solid/src/rules/no-restated-default-options.ts b/packages/eslint-plugin-solid/src/rules/no-restated-default-options.ts index aca7349..fc97247 100644 --- a/packages/eslint-plugin-solid/src/rules/no-restated-default-options.ts +++ b/packages/eslint-plugin-solid/src/rules/no-restated-default-options.ts @@ -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): // is keyed by default; and are non-keyed by default. const JSX_PROP_DEFAULTS: Record> = { For: { keyed: true }, diff --git a/packages/eslint-plugin-solid/src/rules/no-unknown-namespaces.ts b/packages/eslint-plugin-solid/src/rules/no-unknown-namespaces.ts index 0532556..5c81f8a 100644 --- a/packages/eslint-plugin-solid/src/rules/no-unknown-namespaces.ts +++ b/packages/eslint-plugin-solid/src/rules/no-unknown-namespaces.ts @@ -23,7 +23,7 @@ const v2MigrationGuidance: Record = { 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", }; diff --git a/packages/eslint-plugin-solid/src/rules/no-write-in-pure-computation.ts b/packages/eslint-plugin-solid/src/rules/no-write-in-pure-computation.ts index 1ecc506..9c1666b 100644 --- a/packages/eslint-plugin-solid/src/rules/no-write-in-pure-computation.ts +++ b/packages/eslint-plugin-solid/src/rules/no-write-in-pure-computation.ts @@ -41,7 +41,7 @@ export default createRule({ 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: @@ -189,10 +189,11 @@ export default createRule({ // 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; } diff --git a/packages/eslint-plugin-solid/src/rules/reactivity.ts b/packages/eslint-plugin-solid/src/rules/reactivity.ts index 0cde526..94d64ba 100644 --- a/packages/eslint-plugin-solid/src/rules/reactivity.ts +++ b/packages/eslint-plugin-solid/src/rules/reactivity.ts @@ -1371,16 +1371,23 @@ export default createRule({ "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) && @@ -1445,7 +1452,10 @@ export default createRule({ // 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", diff --git a/packages/eslint-plugin-solid/src/rules/removed-api.ts b/packages/eslint-plugin-solid/src/rules/removed-api.ts index fa5eaa3..f072c9f 100644 --- a/packages/eslint-plugin-solid/src/rules/removed-api.ts +++ b/packages/eslint-plugin-solid/src/rules/removed-api.ts @@ -1,10 +1,10 @@ import type { TSESLint } from "@typescript-eslint/utils"; import type { TSESTree as T } from "@typescript-eslint/utils"; import { createRule, findVariable } from "../compat"; -import { jsxGetProp } from "../utils"; +import { getSolidSourceRegex, jsxGetProp, trackImports } from "../utils"; -// Mechanical renames: same semantics, new name. Verified against the Solid 2.0 -// RC source (packages/solid/src/index.ts). +// Mechanical renames: same semantics, new name. Verified against the Solid 2.0.0 +// source (packages/solid/src/index.ts) and its migration guide. const RENAMED = new Map([ ["equalFn", "isEqual"], ["getListener", "getObserver"], @@ -46,7 +46,7 @@ const RENAMED_CHANGED = new Map([ [ @@ -87,6 +87,16 @@ const REMOVED = new Map([ "To consume an Observable or async iterable, adapt it with `from`; to publish a signal, push values out from a `createEffect`", ], ["indexArray", "Use `mapArray`, which handles index-mode mapping in Solid 2.0"], + ["enableScheduling", "Scheduling is built into Solid 2.0; there is nothing to enable"], + [ + "createDynamic", + 'Use the `dynamic(source)` factory from "@solidjs/web", which returns a stable component: `const View = dynamic(() => tag())`, then render ``', + ], + [ + "pipeToWritable", + "Use `renderToStream(fn).pipeTo(writable)`, or its `readable` stream for a `Response` body", + ], + ["pipeToNodeWritable", "Use `renderToStream(fn).pipe(writable)`"], [ "splitProps", 'Use `omit` from "solid-js" to exclude props, and pass the original props object along', @@ -125,7 +135,16 @@ const STORE_CHANGED = new Map([ // Includes "@solidjs/web" so 1.x APIs that survived a mechanical source // rewrite (e.g. renderToStringAsync) are still reported as removed. -const SOLID_SOURCE_REGEX = /^(?:solid-js(?:\/web|\/store)?|@solidjs\/web)$/; +const SOLID_SOURCE_REGEX = /^(?:solid-js(?:\/web|\/store|\/h|\/html|\/universal)?|@solidjs\/web)$/; + +// 1.x subpath modules that became their own packages in Solid 2.0. Same +// exports under the new name, so the import rewrite is safe. +const MOVED_MODULES = new Map([ + ["solid-js/web", "@solidjs/web"], + ["solid-js/h", "@solidjs/h"], + ["solid-js/html", "@solidjs/html"], + ["solid-js/universal", "@solidjs/universal"], +]); type MessageIds = | "renamed" @@ -133,6 +152,8 @@ type MessageIds = | "applyRename" | "removed" | "webMoved" + | "moduleMoved" + | "contextProvider" | "storeMoved" | "storeChanged" | "classList"; @@ -156,6 +177,9 @@ export default createRule({ applyRename: "Rename '{{name}}' to '{{replacement}}'.", removed: "'{{name}}' was removed in Solid 2.0. {{guidance}}.", webMoved: 'The "solid-js/web" module is now the "@solidjs/web" package in Solid 2.0.', + moduleMoved: 'The "{{source}}" module is now the "{{replacement}}" package in Solid 2.0.', + contextProvider: + "Context objects have no `.Provider` in Solid 2.0; the context is the provider component: `<{{name}} value={...}>`.", storeMoved: 'The "solid-js/store" module no longer exists in Solid 2.0; \'{{name}}\' is exported from "solid-js".', storeChanged: @@ -166,6 +190,21 @@ export default createRule({ }, defaultOptions: [], create(context) { + const { matchImport, handleImportDeclaration } = trackImports(getSolidSourceRegex(context)); + + /** Is `name` a local variable initialized with Solid's `createContext(...)`? */ + const isSolidContext = (name: T.JSXIdentifier): boolean => { + const variable = findVariable(context, name as unknown as T.Identifier); + const def = variable?.defs[0]; + if (!def || def.node.type !== "VariableDeclarator") return false; + const init = def.node.init; + return Boolean( + init?.type === "CallExpression" && + init.callee.type === "Identifier" && + matchImport("createContext", init.callee.name) + ); + }; + /** Rename the import specifier and, when it isn't aliased, all its references. */ const renameFix = ( fixer: TSESLint.RuleFixer, @@ -190,18 +229,18 @@ export default createRule({ return { ImportDeclaration(node) { + handleImportDeclaration(node); const source = node.source.value; if (!SOLID_SOURCE_REGEX.test(source)) return; - if (source === "solid-js/web") { + const movedTo = MOVED_MODULES.get(source); + if (movedTo) { context.report({ node: node.source, - messageId: "webMoved", + messageId: source === "solid-js/web" ? "webMoved" : "moduleMoved", + data: { source, replacement: movedTo }, fix: (fixer) => - fixer.replaceText( - node.source, - node.source.raw.replace("solid-js/web", "@solidjs/web") - ), + fixer.replaceText(node.source, node.source.raw.replace(source, movedTo)), }); } @@ -278,6 +317,29 @@ export default createRule({ } } }, + JSXOpeningElement(node) { + const name = node.name; + if ( + name.type !== "JSXMemberExpression" || + name.property.name !== "Provider" || + name.object.type !== "JSXIdentifier" || + !isSolidContext(name.object) + ) { + return; + } + const contextName = name.object.name; + const closing = (node.parent as T.JSXElement).closingElement; + context.report({ + node: name, + messageId: "contextProvider", + data: { name: contextName }, + fix: (fixer) => { + const fixes = [fixer.replaceText(name, contextName)]; + if (closing) fixes.push(fixer.replaceText(closing.name, contextName)); + return fixes; + }, + }); + }, JSXAttribute(node) { if (node.name.type === "JSXIdentifier" && node.name.name === "classList") { const element = node.parent as T.JSXOpeningElement; diff --git a/packages/eslint-plugin-solid/test/rules/imports.test.ts b/packages/eslint-plugin-solid/test/rules/imports.test.ts index a0af2a0..41c24e5 100644 --- a/packages/eslint-plugin-solid/test/rules/imports.test.ts +++ b/packages/eslint-plugin-solid/test/rules/imports.test.ts @@ -27,6 +27,11 @@ import type { Store } from "solid-js/store";`, code: `import { render, Portal, Dynamic, isServer } from "@solidjs/web";`, settings: { solid: { version: 2 } }, }, + { + code: `import { createDeferred, createTrackedEffect, onFlush, until, from, Hydration, NoHydration } from "solid-js"; +import { dynamic, clientOnly, useHead, getRequestEvent, redirect, respond } from "@solidjs/web";`, + settings: { solid: { version: 2 } }, + }, { code: `import type { JSX, ValidComponent, ComponentProps } from "@solidjs/web";`, settings: { solid: { version: 2 } }, @@ -139,6 +144,30 @@ import { render } from "solid-js/web"; import { createEffect } from "solid-js";`, }, // Solid 2.0: web exports live in "@solidjs/web", not core + { + code: `import { createSignal, useHead } from "solid-js";`, + settings: { solid: { version: 2 } }, + errors: [ + { + messageId: "prefer-source", + data: { name: "useHead", source: "@solidjs/web" }, + }, + ], + output: `import { useHead } from "@solidjs/web"; +import { createSignal, } from "solid-js";`, + }, + { + code: `import { render, onFlush } from "@solidjs/web";`, + settings: { solid: { version: 2 } }, + errors: [ + { + messageId: "prefer-source", + data: { name: "onFlush", source: "solid-js" }, + }, + ], + output: `import { onFlush } from "solid-js"; +import { render, } from "@solidjs/web";`, + }, { code: `import { type JSX } from "solid-js";`, settings: { solid: { version: 2 } }, diff --git a/packages/eslint-plugin-solid/test/rules/no-module-scope-reactive-primitive.test.ts b/packages/eslint-plugin-solid/test/rules/no-module-scope-reactive-primitive.test.ts index 0c35ba3..f4c0a43 100644 --- a/packages/eslint-plugin-solid/test/rules/no-module-scope-reactive-primitive.test.ts +++ b/packages/eslint-plugin-solid/test/rules/no-module-scope-reactive-primitive.test.ts @@ -20,6 +20,11 @@ export function createTodos() { const counter = createRoot(() => createSignal(0));`, ], invalid: [ + { + code: `import { createDeferred } from "solid-js"; +export const results = createDeferred(async () => fetchResults());`, + errors: [{ messageId: "moduleScopePrimitive", data: { name: "createDeferred" } }], + }, { code: `import { createSignal } from "solid-js"; const [count, setCount] = createSignal(0);`, diff --git a/packages/eslint-plugin-solid/test/rules/no-write-in-pure-computation.test.ts b/packages/eslint-plugin-solid/test/rules/no-write-in-pure-computation.test.ts index d8aa83e..0eb9c6c 100644 --- a/packages/eslint-plugin-solid/test/rules/no-write-in-pure-computation.test.ts +++ b/packages/eslint-plugin-solid/test/rules/no-write-in-pure-computation.test.ts @@ -114,6 +114,15 @@ function useCounter() { }`, ], invalid: [ + { + code: `import { createSignal, createDeferred } from "solid-js"; +const [count, setCount] = createSignal(0); +const bad = createDeferred(() => { + setCount(count() + 1); + return count(); +});`, + errors: [{ messageId: "writeInMemo", data: { name: "setCount", api: "createDeferred" } }], + }, { code: `import { createSignal, createMemo } from "solid-js"; const [count, setCount] = createSignal(0); diff --git a/packages/eslint-plugin-solid/test/rules/reactivity.test.ts b/packages/eslint-plugin-solid/test/rules/reactivity.test.ts index cc691c0..f0dcafa 100644 --- a/packages/eslint-plugin-solid/test/rules/reactivity.test.ts +++ b/packages/eslint-plugin-solid/test/rules/reactivity.test.ts @@ -652,6 +652,30 @@ export const cases = run("reactivity", rule, { }); return ; }`, + // createDeferred is an async memo in Solid 2.0 (#259) + `import { createDeferred, createSignal } from "solid-js"; + function Component() { + const [id] = createSignal(1); + const deferred = createDeferred(async () => (await fetch(\`/x/\${id()}\`)).text()); + return

{deferred()}

; + }`, + // until(fn) tracks its predicate + `import { createSignal, until } from "solid-js"; + function Component() { + const [count] = createSignal(0); + const ready = until(() => count() > 3); + ready.then(() => console.log("ready")); + return

{count()}

; + }`, + // onFlush runs its callback once after the pending flush; reading current values is fine + `import { createSignal, onFlush } from "solid-js"; + function Component() { + const [count] = createSignal(0); + onFlush(() => { + document.title = String(count()); + }); + return

{count()}

; + }`, // custom renderer sources use the same import matching { code: `// Requires settings.solid.moduleSources: ["my-solid-renderer"]. diff --git a/packages/eslint-plugin-solid/test/rules/removed-api.test.ts b/packages/eslint-plugin-solid/test/rules/removed-api.test.ts index fdd7247..1425b35 100644 --- a/packages/eslint-plugin-solid/test/rules/removed-api.test.ts +++ b/packages/eslint-plugin-solid/test/rules/removed-api.test.ts @@ -17,6 +17,18 @@ export const cases = run("removed-api", rule, { `import { createDeferred as defer, from as fromSource } from "solid-js";`, `let el =
;`, `let el =
;`, + // the 2.0 dynamic factory and stream API + `import { dynamic, renderToStream } from "@solidjs/web";`, + // the context itself is the provider in 2.0 + `import { createContext } from "solid-js"; +const Theme = createContext("light"); +let el = ;`, + // .Provider on something that is not a Solid context is left alone + `import { createContext } from "react"; +const Theme = createContext("light"); +let el = ;`, + `import { Theme } from "./theme"; +let el = ;`, ], invalid: [ // mechanical renames with reference rewriting @@ -199,10 +211,60 @@ om(() => {});`, }, { code: `import { createStore, produce } from "solid-js/store";`, + errors: [{ messageId: "storeChanged" }, { messageId: "removed" }], + }, + // removed in 2.0.0 + { + code: `import { createDynamic } from "@solidjs/web";`, + errors: [{ messageId: "removed" }], + }, + { + code: `import { pipeToWritable, pipeToNodeWritable } from "@solidjs/web";`, + errors: [{ messageId: "removed" }, { messageId: "removed" }], + }, + { + code: `import { enableScheduling } from "solid-js";`, + errors: [{ messageId: "removed" }], + }, + // other 1.x subpath modules that became packages + { + code: `import h from "solid-js/h";`, errors: [ - { messageId: "storeChanged" }, - { messageId: "removed" }, + { + messageId: "moduleMoved", + data: { source: "solid-js/h", replacement: "@solidjs/h" }, + }, ], + output: `import h from "@solidjs/h";`, + }, + { + code: `import html from "solid-js/html";`, + errors: [{ messageId: "moduleMoved" }], + output: `import html from "@solidjs/html";`, + }, + { + code: `import { createRenderer } from "solid-js/universal";`, + errors: [{ messageId: "moduleMoved" }], + output: `import { createRenderer } from "@solidjs/universal";`, + }, + // Context.Provider -> the context itself + { + code: `import { createContext } from "solid-js"; +const Theme = createContext("light"); +let el = ;`, + errors: [{ messageId: "contextProvider", data: { name: "Theme" } }], + output: `import { createContext } from "solid-js"; +const Theme = createContext("light"); +let el = ;`, + }, + { + code: `import { createContext as cc } from "solid-js"; +const Theme = cc(); +let el = ;`, + errors: [{ messageId: "contextProvider" }], + output: `import { createContext as cc } from "solid-js"; +const Theme = cc(); +let el = ;`, }, // classList -> class {