diff --git a/.changeset/dirty-toys-live.md b/.changeset/dirty-toys-live.md new file mode 100644 index 00000000..abccdcc6 --- /dev/null +++ b/.changeset/dirty-toys-live.md @@ -0,0 +1,7 @@ +--- +'@kitajs/fastify-html-plugin': patch +'@kitajs/ts-html-plugin': patch +'@kitajs/html': patch +--- + +Improved code with Biome.js lint result diff --git a/benchmarks/runner/assertions.js b/benchmarks/runner/assertions.js index 7b749d9b..c1485cf3 100644 --- a/benchmarks/runner/assertions.js +++ b/benchmarks/runner/assertions.js @@ -1,7 +1,7 @@ -import KitaHtmlJSXRuntimeRenderers from '@kitajs/bench-html-kitajs'; -import PreactRuntimeRenderers from '@kitajs/bench-html-preact'; //import ReactRuntimeRenderers from '@kitajs/bench-html-react'; same as reactjsx import JSXTERuntimeRenderers from '@kitajs/bench-html-jsxte'; +import KitaHtmlJSXRuntimeRenderers from '@kitajs/bench-html-kitajs'; +import PreactRuntimeRenderers from '@kitajs/bench-html-preact'; import ReactJSXRuntimeRenderers from '@kitajs/bench-html-reactjsx'; import StringTemplateRenderers from '@kitajs/bench-html-templates'; import TypedHtmlRenderers from '@kitajs/bench-html-typed-html'; @@ -52,8 +52,8 @@ function saveHtml(name, code) { vueIndentScriptAndStyle: false, tsdoc: true }) - .then((code) => writeFileSync('./samples/' + name + '.html', code)) - .then(() => console.log('Saved ' + name + '.html sample file.')) + .then((code) => writeFileSync(`./samples/${name}.html`, code)) + .then(() => console.log(`Saved ${name}.html sample file.`)) ); } diff --git a/examples/suspense-server.tsx b/examples/suspense-server.tsx index ae97d56d..efae0697 100644 --- a/examples/suspense-server.tsx +++ b/examples/suspense-server.tsx @@ -1,6 +1,6 @@ -import http from 'http'; -import { setTimeout } from 'timers/promises'; -import Html, { PropsWithChildren } from '../index'; +import http from 'node:http'; +import { setTimeout } from 'node:timers/promises'; +import Html, { type PropsWithChildren } from '../packages/html'; import { Suspense, renderToStream } from '../packages/html/suspense'; async function SleepForMs({ ms, children }: PropsWithChildren<{ ms: number }>) { diff --git a/packages/fastify-html-plugin/test/stream-html.test.tsx b/packages/fastify-html-plugin/test/stream-html.test.tsx index dc8d6388..5d83e907 100644 --- a/packages/fastify-html-plugin/test/stream-html.test.tsx +++ b/packages/fastify-html-plugin/test/stream-html.test.tsx @@ -4,7 +4,7 @@ // // This was adapted to work inside a fastify route handler. -import Html, { PropsWithChildren } from '@kitajs/html'; +import Html, { type PropsWithChildren } from '@kitajs/html'; import { Suspense, SuspenseScript } from '@kitajs/html/suspense'; import fastify from 'fastify'; import { JSDOM } from 'jsdom'; diff --git a/packages/fastify-html-plugin/types/index.d.ts b/packages/fastify-html-plugin/types/index.d.ts index 5b7312c1..eeef67f2 100644 --- a/packages/fastify-html-plugin/types/index.d.ts +++ b/packages/fastify-html-plugin/types/index.d.ts @@ -1,4 +1,4 @@ -import { FastifyPluginCallback } from 'fastify'; +import type { FastifyPluginCallback } from 'fastify'; declare module 'fastify' { interface FastifyReply { diff --git a/packages/html/hotwire-turbo.d.ts b/packages/html/hotwire-turbo.d.ts index 649ae39d..0fceb128 100644 --- a/packages/html/hotwire-turbo.d.ts +++ b/packages/html/hotwire-turbo.d.ts @@ -32,14 +32,14 @@ declare namespace HotwireTurbo { * @default { end } * @link {https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#parameters} */ - ['data-autoscroll-block']?: 'end' | 'start' | 'center' | 'nearest'; + 'data-autoscroll-block'?: 'end' | 'start' | 'center' | 'nearest'; /** * Controls the autoscroll behavior * * @default { end } * @link {https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#parameters} */ - ['data-autoscroll-behavior']?: 'auto' | 'smooth'; + 'data-autoscroll-behavior'?: 'auto' | 'smooth'; } interface TurboStreamTag extends JSX.HtmlTag { @@ -49,8 +49,8 @@ declare namespace HotwireTurbo { } interface Elements { - ['turbo-frame']: TurboFrameTag; - ['turbo-stream']: TurboStreamTag; + 'turbo-frame': TurboFrameTag; + 'turbo-stream': TurboStreamTag; } /** @@ -62,20 +62,20 @@ declare namespace HotwireTurbo { * False: disables Turbo Drive on links and forms including descendants. Use "true" to * renable when an ancestor has opted out */ - ['data-turbo']?: 'true' | 'false'; + 'data-turbo'?: 'true' | 'false'; /** Tracks the element’s HTML and performs a full page reload when it changes */ - ['data-turbo-track']?: 'reload'; + 'data-turbo-track'?: 'reload'; /** Identifies the Turbo Frame to navigate. */ - ['data-turbo-frame']?: string; + 'data-turbo-frame'?: string; /** * Customizes the Turbo.visit action. * * "Replace" will visit a link without pushing a new history entry onto the stack. It * will discard your current location in the history stack. */ - ['data-turbo-action']?: 'replace' | 'advance'; + 'data-turbo-action'?: 'replace' | 'advance'; /** * Persists element between page loads * @@ -83,19 +83,19 @@ declare namespace HotwireTurbo { * * @link {https://turbo.hotwired.dev/handbook/building#persisting-elements-across-page-loads} */ - ['data-turbo-permanent']?: boolean; + 'data-turbo-permanent'?: boolean; /** * Removes the element before the document is cached, preventing it from reappearing * when restored. */ - ['data-turbo-temporary']?: boolean; + 'data-turbo-temporary'?: boolean; /** Prevents inline scripts from being re-evaluated on Visits. */ - ['data-turbo-eval']?: 'false'; + 'data-turbo-eval'?: 'false'; /** * Changes the request link method from the default "GET" request You should prefer a * form in most cases */ - ['data-turbo-method']?: string; + 'data-turbo-method'?: string; /** * Specifies that a link/form can accept a turbo stream response @@ -104,12 +104,12 @@ declare namespace HotwireTurbo { * * This is useful when trying to request turbo streams on GET requests */ - ['data-turbo-stream']?: boolean; + 'data-turbo-stream'?: boolean; /** * Presents a confirm dialog with the given value. This can be used on form elements * or links with the data-turbo-method attribute. */ - ['data-turbo-confirm']?: string; + 'data-turbo-confirm'?: string; /** * Specifies text to display when submitting a form. Can be used on input or button * elements. While the form is submitting, the text of the element will show with this @@ -119,6 +119,6 @@ declare namespace HotwireTurbo { * * Useful for feedback like "Saving..." while an operation is in progress */ - ['data-turbo-submits-with']?: string; + 'data-turbo-submits-with'?: string; } } diff --git a/packages/html/htmx.d.ts b/packages/html/htmx.d.ts index 3f69a907..06e97178 100644 --- a/packages/html/htmx.d.ts +++ b/packages/html/htmx.d.ts @@ -204,35 +204,35 @@ declare namespace Htmx { * * @see https://htmx.org/attributes/hx-get/ */ - ['hx-get']?: string; + 'hx-get'?: string; /** * Issues a `POST` to the specified URL. * * @see https://htmx.org/attributes/hx-post/ */ - ['hx-post']?: string; + 'hx-post'?: string; /** * Issues a `PUT` to the specified URL. * * @see https://htmx.org/attributes/hx-put/ */ - ['hx-put']?: string; + 'hx-put'?: string; /** * Issues a `DELETE` to the specified URL. * * @see https://htmx.org/attributes/hx-delete/ */ - ['hx-delete']?: string; + 'hx-delete'?: string; /** * Issues a `PATCH` to the specified URL. * * @see https://htmx.org/attributes/hx-patch/ */ - ['hx-patch']?: string; + 'hx-patch'?: string; /** * Add or remove [progressive enhancement] for links and forms. @@ -241,7 +241,7 @@ declare namespace Htmx { * * [progressive enhancement]: https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement */ - ['hx-boost']?: BoolStr; + 'hx-boost'?: BoolStr; /** * Handle any event with a script inline. @@ -256,7 +256,7 @@ declare namespace Htmx { * @since 1.9.3 * @see https://htmx.org/attributes/hx-on/ */ - [`hx-on:`]?: string; + 'hx-on:'?: string; /** * Handle any event with a script inline. Each listener is specified on a separate @@ -267,21 +267,21 @@ declare namespace Htmx { * @since 1.9.0 * @see https://htmx.org/attributes/hx-on/ */ - ['hx-on']?: string; + 'hx-on'?: string; /** * Pushes the URL into the browser location bar, creating a new history entry. * * @see https://htmx.org/attributes/hx-push-url/ */ - ['hx-push-url']?: BoolStr | AnyStr; + 'hx-push-url'?: BoolStr | AnyStr; /** * Select content to swap in from a response. * * @see https://htmx.org/attributes/hx-select/ */ - ['hx-select']?: string; + 'hx-select'?: string; /** * Select content to swap in from a response, out of band (somewhere other than the @@ -289,7 +289,7 @@ declare namespace Htmx { * * @see https://htmx.org/attributes/hx-select-oob/ */ - ['hx-select-oob']?: string; + 'hx-select-oob'?: string; /** * Controls how content is swapped in (`outerHTML`, `beforeend`, `afterend`, …). @@ -301,7 +301,7 @@ declare namespace Htmx { * @see https://htmx.org/attributes/hx-swap/ * @see {@linkcode InsertPosition} which is used in [{@linkcode Element.insertAdjacentHTML}](https://developer.mozilla.org/docs/Web/API/Element/insertAdjacentHTML) */ - ['hx-swap']?: HxSwap | AnyStr; + 'hx-swap'?: HxSwap | AnyStr; /** * Marks content in a response to be out of band (should swap in somewhere other than @@ -309,56 +309,56 @@ declare namespace Htmx { * * @see https://htmx.org/attributes/hx-swap-oob/ */ - ['hx-swap-oob']?: 'true' | HxSwap | AnyStr; + 'hx-swap-oob'?: 'true' | HxSwap | AnyStr; /** * Specifies the target element to be swapped. * * @see https://htmx.org/attributes/hx-target/ */ - ['hx-target']?: HxTarget | AnyStr; + 'hx-target'?: HxTarget | AnyStr; /** * Specifies the event that triggers the request. * * @see https://htmx.org/attributes/hx-trigger/ */ - ['hx-trigger']?: 'every ' | HxTriggerModifier | AnyStr; + 'hx-trigger'?: 'every ' | HxTriggerModifier | AnyStr; /** * Adds values to the parameters to submit with the request (JSON-formatted). * * @see https://htmx.org/attributes/hx-vals/ */ - ['hx-vals']?: HxHeaders; + 'hx-vals'?: HxHeaders; /** * Shows a `confirm()` dialog before issuing a request. * * @see https://htmx.org/attributes/hx-confirm/ */ - ['hx-confirm']?: string; + 'hx-confirm'?: string; /** * Disables htmx processing for the given node and any children nodes. * * @see https://htmx.org/attributes/hx-disable/ */ - ['hx-disable']?: boolean; + 'hx-disable'?: boolean; /** * Control and disable automatic attribute inheritance for child nodes. * * @see https://htmx.org/attributes/hx-disinherit/ */ - ['hx-disinherit']?: '*' | AnyStr; + 'hx-disinherit'?: '*' | AnyStr; /** * Changes the request encoding type. * * @see https://htmx.org/attributes/hx-encoding/ */ - ['hx-encoding']?: 'multipart/form-data'; + 'hx-encoding'?: 'multipart/form-data'; /** * Extensions to use for this element. @@ -366,49 +366,49 @@ declare namespace Htmx { * @see https://htmx.org/attributes/hx-ext/ * @see {@linkcode Extensions} for how to declare extensions in JSX. */ - ['hx-ext']?: Htmx.Extensions[keyof Htmx.Extensions] | 'ignore:' | AnyStr; + 'hx-ext'?: Htmx.Extensions[keyof Htmx.Extensions] | 'ignore:' | AnyStr; /** * Adds to the headers that will be submitted with the request. * * @see https://htmx.org/attributes/hx-headers/ */ - ['hx-headers']?: HxHeaders | AnyStr; + 'hx-headers'?: HxHeaders | AnyStr; /** * Prevent sensitive data being saved to the history cache. * * @see https://htmx.org/attributes/hx-history/ */ - ['hx-history']?: 'false'; + 'hx-history'?: 'false'; /** * The element to snapshot and restore during history navigation. * * @see https://htmx.org/attributes/hx-history-elt/ */ - ['hx-history-elt']?: boolean; + 'hx-history-elt'?: boolean; /** * Include additional data in requests. * * @see https://htmx.org/attributes/hx-include/ */ - ['hx-include']?: string; + 'hx-include'?: string; /** * The element to put the `htmx-request` class on during the request. * * @see https://htmx.org/attributes/hx-indicator/ */ - ['hx-indicator']?: string; + 'hx-indicator'?: string; /** * Filters the parameters that will be submitted with a request. * * @see https://htmx.org/attributes/hx-params/ */ - ['hx-params']?: '*' | 'none' | 'not ' | AnyStr; + 'hx-params'?: '*' | 'none' | 'not ' | AnyStr; /** * Specifies elements to keep unchanged between requests. @@ -418,70 +418,70 @@ declare namespace Htmx { * element from being removed from the ``. * @see https://htmx.org/attributes/hx-preserve/ */ - ['hx-preserve']?: boolean | 'true'; + 'hx-preserve'?: boolean | 'true'; /** * Shows a `prompt()` before submitting a request. * * @see https://htmx.org/attributes/hx-prompt/ */ - ['hx-prompt']?: string; + 'hx-prompt'?: string; /** * Replace the URL in the browser location bar. * * @see https://htmx.org/attributes/hx-replace-url/ */ - ['hx-replace-url']?: BoolStr | AnyStr; + 'hx-replace-url'?: BoolStr | AnyStr; /** * Configures various aspects of the request. * * @see https://htmx.org/attributes/hx-request/ */ - ['hx-request']?: `"timeout": ` | `"credentials": ` | `"noHeaders": ` | HxHeaders; + 'hx-request'?: `"timeout": ` | `"credentials": ` | `"noHeaders": ` | HxHeaders; /** * Control how requests made by different elements are synchronized. * * @see https://htmx.org/attributes/hx-sync/ */ - ['hx-sync']?: HxSync; + 'hx-sync'?: HxSync; /** * Force elements to validate themselves before a request. * * @see https://htmx.org/attributes/hx-validate/ */ - ['hx-validate']?: boolean; + 'hx-validate'?: boolean; /** * Adds values dynamically to the parameters to submit with the request. * * @deprecated Superseded by `hx-vals` */ - ['hx-vars']?: AnyStr; + 'hx-vars'?: AnyStr; /** * The URL of the SSE server. * * @see https://htmx.org/extensions/server-sent-events/ */ - ['sse-connect']?: string; + 'sse-connect'?: string; /** * The name of the message to swap into the DOM. * * @see https://htmx.org/extensions/server-sent-events/ */ - ['sse-swap']?: string; + 'sse-swap'?: string; /** * A URL to establish a WebSocket connection against. * * @see https://htmx.org/extensions/web-sockets/ */ - ['ws-connect']?: string; + 'ws-connect'?: string; /** * Sends a message to the nearest websocket based on the trigger value for the @@ -489,14 +489,14 @@ declare namespace Htmx { * * @see https://htmx.org/extensions/web-sockets/ */ - ['ws-send']?: boolean; + 'ws-send'?: boolean; /** * Apply class transitions on this element. * * @see https://htmx.org/extensions/class-tools/ */ - ['classes']?: `add ` | `remove ` | `toggle ` | AnyStr; + classes?: `add ` | `remove ` | `toggle ` | AnyStr; /** * The element or elements to disable during requests. Accepts CSS selectors. This @@ -505,21 +505,21 @@ declare namespace Htmx { * * @see https://htmx.org/extensions/disable-element/ */ - ['hx-disable-element']?: 'self' | AnyStr; + 'hx-disable-element'?: 'self' | AnyStr; /** * The element or elements to disable during requests. Accepts CSS selectors. * * @see https://htmx.org/attributes/hx-disabled-elt/ */ - ['hx-disabled-elt']?: 'this' | AnyStr; + 'hx-disabled-elt'?: 'this' | AnyStr; /** * The strategy for merging new head content. * * @see https://htmx.org/extensions/head-support/ */ - ['hx-head']?: 'merge' | 'append' | 're-eval'; + 'hx-head'?: 'merge' | 'append' | 're-eval'; /** * Hyperscript expression diff --git a/packages/html/index.js b/packages/html/index.js index 345a8a77..3615cd93 100644 --- a/packages/html/index.js +++ b/packages/html/index.js @@ -381,7 +381,7 @@ function contentsToString(contents, escape) { let result = ''; for (let index = 0; index < length; index++) { - let content = contents[index]; + const content = contents[index]; switch (typeof content) { case 'string': @@ -563,7 +563,6 @@ function compile(htmlFn, strict = true, separator = '/*\x00*/') { ) { body += html.slice(nextStart, index) + '\\`'; nextStart = index + 1; - continue; } } diff --git a/packages/html/jsx.d.ts b/packages/html/jsx.d.ts index 1a10a4df..471ac012 100644 --- a/packages/html/jsx.d.ts +++ b/packages/html/jsx.d.ts @@ -230,7 +230,7 @@ declare namespace JSX { } interface HtmlFormTag extends HtmlTag { - ['accept-charset']?: undefined | string; + 'accept-charset'?: undefined | string; action?: undefined | string; autocomplete?: undefined | string; enctype?: undefined | string; @@ -359,7 +359,7 @@ declare namespace JSX { interface HtmlMetaTag extends HtmlTag { name?: undefined | string; property?: undefined | string; - ['http-equiv']?: undefined | string; + 'http-equiv'?: undefined | string; content?: undefined | string; charset?: undefined | string; } diff --git a/packages/html/register.d.ts b/packages/html/register.d.ts index 854a2cf4..e8f9ff5c 100644 --- a/packages/html/register.d.ts +++ b/packages/html/register.d.ts @@ -9,4 +9,4 @@ declare global { var Html: typeof import('./index'); } -export {}; +export type {}; diff --git a/packages/html/register.js b/packages/html/register.js index 95ed06d0..2e6e2120 100644 --- a/packages/html/register.js +++ b/packages/html/register.js @@ -1,5 +1,3 @@ -'use strict'; - process.emitWarning( 'The `@kitajs/html/register` import has been DEPRECATED and will be removed in the next major version. See https://github.com/kitajs/html/tree/master/packages/html#deprecating-global-register', 'DeprecationWarning', diff --git a/packages/ts-html-plugin/src/util.ts b/packages/ts-html-plugin/src/util.ts index 8af99590..98246a7b 100644 --- a/packages/ts-html-plugin/src/util.ts +++ b/packages/ts-html-plugin/src/util.ts @@ -1,4 +1,4 @@ -import ts, { JsxFragment } from 'typescript'; +import ts, { type JsxFragment } from 'typescript'; import type { Diagnostic, JsxElement, @@ -123,7 +123,6 @@ export function diagnoseJsxElement( !diagnostics.some((d) => d.start === safeAttribute.pos + 1 && d.file === file) ) { diagnostics.push(diagnostic(safeAttribute, 'UnusedSafe', 'Warning')); - continue; } } @@ -354,7 +353,7 @@ export function getSafeAttribute(element: JsxOpeningElement) { export function proxyObject(obj: T): T { const proxy: T = Object.create(null); - for (let k of Object.keys(obj) as Array) { + for (const k of Object.keys(obj) as Array) { const x = obj[k]!; // @ts-expect-error - JS runtime trickery which is tricky to type tersely proxy[k] = (...args: Array<{}>) => x.apply(obj, args); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad2cde6a..d9a318ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -203,10 +203,10 @@ importers: packages/fastify-html-plugin: dependencies: '@kitajs/html': - specifier: workspace:^ + specifier: workspace:^4 version: link:../html '@kitajs/ts-html-plugin': - specifier: workspace:^ + specifier: workspace:^4 version: link:../ts-html-plugin fastify-plugin: specifier: ^4.0.0 @@ -245,9 +245,6 @@ importers: packages/html: dependencies: - '@kitajs/ts-html-plugin': - specifier: workspace:^ - version: link:../ts-html-plugin csstype: specifier: ^3.1.3 version: 3.1.3 @@ -274,7 +271,7 @@ importers: packages/ts-html-plugin: dependencies: '@kitajs/html': - specifier: workspace:^ + specifier: workspace:^4 version: link:../html chalk: specifier: ^4.1.2 @@ -4326,7 +4323,7 @@ packages: name: '@kitajs/ts-html-plugin' hasBin: true peerDependencies: - '@kitajs/html': workspace:^ + '@kitajs/html': workspace:^4 typescript: ^5.3.3 dependencies: '@kitajs/html': link:packages/html