move to biome (#297)

* switch to biome

* writer format

* migrate format

* packages format

* hudozka format

* writer fix

* biome config updated

* migrate fix

* packages fix

* hudozka fix

* claude updated
This commit is contained in:
tmshv authored and GitHub committed 2026-04-25 03:25:15 +03:00
1 parent 98dcaaa237
commit 467a218d00
112 files changed
+1472 -5914

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
export * from "./useToggle"
export * from "./useLockBodyScroll"
export * from "./useMediaQuery"
export * from "./useMobile"
export * from "./useReducedMotion"
export * from "./useToggle"
+2 -5
View File
@@ -1,5 +1,5 @@
import { renderHook } from "@testing-library/react"
import { describe, it, expect, beforeEach } from "vitest"
import { beforeEach, describe, expect, it } from "vitest"
import { useLockBodyScroll } from "./useLockBodyScroll"
describe("useLockBodyScroll", () => {
@@ -27,10 +27,7 @@ describe("useLockBodyScroll", () => {
})
it("responds to lock/unlock transitions", () => {
const { rerender } = renderHook(
({ locked }) => useLockBodyScroll(locked),
{ initialProps: { locked: false } },
)
const { rerender } = renderHook(({ locked }) => useLockBodyScroll(locked), { initialProps: { locked: false } })
expect(document.body.style.overflow).toBe("")
rerender({ locked: true })
expect(document.body.style.overflow).toBe("hidden")
+10 -6
View File
@@ -1,5 +1,5 @@
import { renderHook, act } from "@testing-library/react"
import { describe, it, expect, beforeEach, vi } from "vitest"
import { act, renderHook } from "@testing-library/react"
import { beforeEach, describe, expect, it, vi } from "vitest"
import { useMediaQuery } from "./useMediaQuery"
describe("useMediaQuery", () => {
@@ -13,10 +13,12 @@ describe("useMediaQuery", () => {
vi.stubGlobal("matchMedia", (query: string) => ({
matches: matches.get(query) ?? false,
addEventListener: (_: string, cb: () => void) => {
if (!listeners.has(query)) {
listeners.set(query, new Set())
let set = listeners.get(query)
if (!set) {
set = new Set()
listeners.set(query, set)
}
listeners.get(query)!.add(cb)
set.add(cb)
},
removeEventListener: (_: string, cb: () => void) => {
listeners.get(query)?.delete(cb)
@@ -42,7 +44,9 @@ describe("useMediaQuery", () => {
act(() => {
matches.set(query, true)
listeners.get(query)?.forEach((cb) => cb())
for (const cb of listeners.get(query) ?? []) {
cb()
}
})
expect(result.current).toBe(true)
})
+1 -1
View File
@@ -2,7 +2,7 @@ import { useSyncExternalStore } from "react"
export function useMediaQuery(query: string, defaultValue = false): boolean {
return useSyncExternalStore(
(callback) => {
callback => {
const mql = window.matchMedia(query)
mql.addEventListener("change", callback)
return () => mql.removeEventListener("change", callback)
+2 -2
View File
@@ -1,5 +1,5 @@
import { renderHook, act } from "@testing-library/react"
import { describe, it, expect } from "vitest"
import { act, renderHook } from "@testing-library/react"
import { describe, expect, it } from "vitest"
import { useToggle } from "./useToggle"
describe("useToggle", () => {
+1 -1
View File
@@ -3,7 +3,7 @@ import { useCallback, useState } from "react"
export function useToggle(initialValue: boolean): [boolean, (nextValue?: boolean) => void] {
const [state, setState] = useState(initialValue)
const toggle = useCallback((next?: boolean) => {
setState(prev => typeof next === "boolean" ? next : !prev)
setState(prev => (typeof next === "boolean" ? next : !prev))
}, [])
return [state, toggle]
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { markdownToHtml, typograf } from "./text"
describe("markdownToHtml", () => {
+9 -5
View File
@@ -1,5 +1,5 @@
import { render, screen } from "@testing-library/react"
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { Box } from "."
describe("Box", () => {
@@ -20,25 +20,29 @@ describe("Box", () => {
it("applies vertical class", () => {
const { container } = render(<Box vertical>v</Box>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/vertical/)
})
it("applies center class", () => {
const { container } = render(<Box center>c</Box>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/center/)
})
it("applies wrap class", () => {
const { container } = render(<Box wrap>w</Box>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/wrap/)
})
it("passes gap to inline style", () => {
const { container } = render(<Box gap={8}>g</Box>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el).toHaveStyle({ gap: "8px" })
})
})
+1 -2
View File
@@ -1,7 +1,6 @@
import s from "./box.module.css"
import classnames from "classnames/bind"
import { createElement } from "react"
import s from "./box.module.css"
const cx = classnames.bind(s)
@@ -1,5 +1,5 @@
import { render, within } from "@testing-library/react"
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { Breadcrumbs } from "."
describe("Breadcrumbs", () => {
@@ -9,9 +9,21 @@ describe("Breadcrumbs", () => {
{ name: "Team", href: "/about/team" },
]
function getNav(container: HTMLElement) {
const navEl = container.querySelector("nav")
if (!navEl) throw new Error("expected <nav> element to be rendered")
return within(navEl)
}
function getClosestLink(el: HTMLElement) {
const link = el.closest("a")
if (!link) throw new Error("expected ancestor <a> element")
return link
}
it("renders breadcrumb items with separators", () => {
const { container } = render(<Breadcrumbs items={items} path="/about/team" />)
const nav = within(container.querySelector("nav")!)
const nav = getNav(container)
expect(nav.getByText("Home")).toBeInTheDocument()
expect(nav.getByText("About")).toBeInTheDocument()
@@ -23,12 +35,12 @@ describe("Breadcrumbs", () => {
it("disables the button matching the current path", () => {
const { container } = render(<Breadcrumbs items={items} path="/about" />)
const nav = within(container.querySelector("nav")!)
const nav = getNav(container)
const aboutLink = nav.getByText("About").closest("a")!
const aboutLink = getClosestLink(nav.getByText("About"))
expect(aboutLink.className).toMatch(/disabled/)
const homeLink = nav.getByText("Home").closest("a")!
const homeLink = getClosestLink(nav.getByText("Home"))
expect(homeLink.className).not.toMatch(/disabled/)
})
})
+13 -24
View File
@@ -1,7 +1,6 @@
import s from "./styles.module.css"
import { Fragment } from "react"
import { Button } from "../Button"
import { insertBetween } from "@hudozka/utils"
import s from "./styles.module.css"
export type Crumb = {
name: string
@@ -14,33 +13,23 @@ export type BreadcrumbsProps = {
path: string
}
export const Breadcrumbs: React.FC<BreadcrumbsProps> = props => {
const items = insertBetween(props.items, () => "/")
export function Breadcrumbs(props: BreadcrumbsProps) {
return (
<nav className={s.breadcrumbs} style={props.style}>
{items.map((x, i) => {
if (typeof x === "string") {
return (
<li key={i}>
<span style={{ margin: "0 var(--size-xs)" }}>{x}</span>
{props.items.map((x, i) => (
<Fragment key={x.href}>
{i > 0 && (
<li>
<span style={{ margin: "0 var(--size-xs)" }}>/</span>
</li>
)
}
return (
<li key={x.href}>
<Button
href={x.href}
theme={"ghost"}
size={"small"}
disabled={x.href === props.path}
>
)}
<li>
<Button href={x.href} theme={"ghost"} size={"small"} disabled={x.href === props.path}>
{x.name}
</Button>
</li>
)
})}
</Fragment>
))}
</nav>
)
}
+10 -4
View File
@@ -1,5 +1,5 @@
import { render, screen, fireEvent } from "@testing-library/react"
import { describe, it, expect, vi } from "vitest"
import { fireEvent, render, screen } from "@testing-library/react"
import { describe, expect, it, vi } from "vitest"
import { Button } from "."
describe("Button", () => {
@@ -19,7 +19,11 @@ describe("Button", () => {
it("calls onClick with value when clicked", () => {
const onClick = vi.fn()
render(<Button value="test-value" onClick={onClick}>Click</Button>)
render(
<Button value="test-value" onClick={onClick}>
Click
</Button>,
)
fireEvent.click(screen.getByRole("button", { name: "Click" }))
expect(onClick).toHaveBeenCalledOnce()
expect(onClick).toHaveBeenCalledWith("test-value", expect.anything())
@@ -35,6 +39,8 @@ describe("Button", () => {
it("applies disabled class when disabled is true", () => {
const { container } = render(<Button disabled>Disabled</Button>)
expect(container.firstElementChild!.className).toMatch(/disabled/)
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/disabled/)
})
})
+13 -13
View File
@@ -1,9 +1,9 @@
import s from "./button.module.css"
import cx from "classnames"
import Link from "next/link"
import cx from "classnames"
import { useCallback } from "react"
import type { MouseEvent, MouseEventHandler } from "react"
import { useCallback } from "react"
import s from "./button.module.css"
const sizeClass = {
default: s.sizeDefault,
@@ -31,11 +31,15 @@ export const Button: React.FC<ButtonProps> = ({ size = "default", theme = "defau
const className = cx(s.button, sizeClass[size], themeClass[theme], {
[s.disabled]: disabled,
})
const onClick = useCallback<MouseEventHandler<HTMLButtonElement>>(event => {
if (typeof props.onClick === "function") {
props.onClick(props.value, event)
}
}, [props])
const { onClick: onClickProp, value } = props
const onClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
event => {
if (typeof onClickProp === "function") {
onClickProp(value, event)
}
},
[onClickProp, value],
)
if (props.href) {
return (
@@ -46,11 +50,7 @@ export const Button: React.FC<ButtonProps> = ({ size = "default", theme = "defau
}
return (
<button
className={className}
style={props.style}
onClick={onClick}
>
<button type="button" className={className} style={props.style} onClick={onClick}>
{props.children}
</button>
)
+1 -4
View File
@@ -17,10 +17,7 @@ export function Transition(props: TransitionProps) {
setMounted(false)
}
}, [opacity])
const transition = useMemo(
() => `all ${props.duration}ms`,
[props.duration],
)
const transition = useMemo(() => `all ${props.duration}ms`, [props.duration])
if (props.show && !mounted) {
setMounted(true)
+9 -8
View File
@@ -1,7 +1,6 @@
import s from "./styles.module.css"
import { Transition } from "./Transition"
import { useLockBodyScroll, useReducedMotion } from "@hudozka/hooks"
import s from "./styles.module.css"
import { Transition } from "./Transition"
export type OverlayProps = {
children?: React.ReactNode
@@ -18,16 +17,18 @@ export const Overlay: React.FC<OverlayProps> = props => {
useLockBodyScroll(props.show)
return (
<Transition
duration={duration}
show={props.show}
>
<Transition duration={duration} show={props.show}>
<div
onClick={(event) => {
onClick={event => {
if (event.target === event.currentTarget) {
props.onClickOverlay()
}
}}
onKeyDown={event => {
if (event.key === "Escape") {
props.onClickOverlay()
}
}}
className={s.overlay}
style={props.style}
>
+7 -4
View File
@@ -1,5 +1,5 @@
import { render } from "@testing-library/react"
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { Panel } from "."
describe("Panel", () => {
@@ -10,20 +10,23 @@ describe("Panel", () => {
it("applies the default variant class", () => {
const { container } = render(<Panel>content</Panel>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/default/)
})
it("applies the ghost variant class when ghost is true", () => {
const { container } = render(<Panel ghost>content</Panel>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toMatch(/ghost/)
expect(el.className).not.toMatch(/default/)
})
it("forwards a custom className", () => {
const { container } = render(<Panel className="custom">content</Panel>)
const el = container.firstElementChild!
const el = container.firstElementChild
if (!el) throw new Error("expected rendered element")
expect(el.className).toContain("custom")
})
})
+8 -9
View File
@@ -1,6 +1,5 @@
import s from "./panel.module.css"
import { Box } from "../Box"
import s from "./panel.module.css"
export type PanelProps = {
children?: React.ReactNode
@@ -9,16 +8,16 @@ export type PanelProps = {
ghost?: boolean
}
export function Panel({
style,
className,
children,
ghost = false,
}: PanelProps) {
export function Panel({ style, className, children, ghost = false }: PanelProps) {
const variant = ghost ? s.ghost : s.default
return (
<Box vertical align={false} className={`${s.panel} ${variant}${className ? ` ${className}` : ""}`} style={style}>
<Box
vertical
align={false}
className={`${s.panel} ${variant}${className ? ` ${className}` : ""}`}
style={style}
>
{children}
</Box>
)
+1 -1
View File
@@ -1,6 +1,6 @@
export * from "./Box"
export * from "./Breadcrumbs"
export * from "./Button"
export * from "./Overlay"
export * from "./Panel"
export * from "./Title"
export * from "./Overlay"
+3 -5
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { insertBetween, tail } from "./array"
describe("insertBetween", () => {
@@ -11,13 +11,11 @@ describe("insertBetween", () => {
})
it("should insert separators between items", () => {
expect(insertBetween(["a", "b", "c"], () => ",")).toEqual([
"a", ",", "b", ",", "c",
])
expect(insertBetween(["a", "b", "c"], () => ",")).toEqual(["a", ",", "b", ",", "c"])
})
it("should pass index to separator function", () => {
const result = insertBetween(["a", "b", "c"], (i) => i)
const result = insertBetween(["a", "b", "c"], i => i)
expect(result).toEqual(["a", 0, "b", 1, "c"])
})
})
-1
View File
@@ -16,4 +16,3 @@ export function tail<T>(items: T[]): T[] {
const [_, ...rest] = items
return rest
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { dateFormat } from "./date"
describe("dateFormat", () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { ext, size } from "./file"
describe("ext", () => {
+2 -6
View File
@@ -7,18 +7,14 @@ const mime = new Map([
])
export function ext(mimeType: string): string {
if (mime.has(mimeType)) {
return mime.get(mimeType)!
}
return mimeType
return mime.get(mimeType) ?? mimeType
}
export function size(bytes: number, precision = 1): string {
if (Number.isNaN(bytes) || !Number.isFinite(bytes)) return ""
const number = Math.floor(Math.log(bytes) / Math.log(1024))
const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision)
const size = (bytes / 1024 ** Math.floor(number)).toFixed(precision)
return `${size} ${units[number]}`
}
+3 -7
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { getResizedUrl } from "./image"
describe("getResizedUrl", () => {
@@ -7,9 +7,7 @@ describe("getResizedUrl", () => {
width: 800,
height: 600,
})
expect(result).toBe(
"https://images.weserv.nl/?url=example.com/img.jpg&w=800&h=600&n=1",
)
expect(result).toBe("https://images.weserv.nl/?url=example.com/img.jpg&w=800&h=600&n=1")
})
it("should use custom n parameter", () => {
@@ -18,8 +16,6 @@ describe("getResizedUrl", () => {
height: 300,
n: -1,
})
expect(result).toBe(
"https://images.weserv.nl/?url=example.com/img.jpg&w=400&h=300&n=-1",
)
expect(result).toBe("https://images.weserv.nl/?url=example.com/img.jpg&w=400&h=300&n=-1")
})
})
+4 -4
View File
@@ -1,7 +1,7 @@
export * from "./array"
export * from "./date"
export * from "./file"
export * from "./image"
export * from "./math"
export * from "./string"
export * from "./url"
export * from "./math"
export * from "./image"
export * from "./file"
export * from "./date"
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { clamp } from "./math"
describe("clamp", () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { titleCase } from "./string"
describe("titleCase", () => {
+2 -4
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"
import { describe, expect, it } from "vitest"
import { queryList } from "./url"
describe("queryList", () => {
@@ -11,8 +11,6 @@ describe("queryList", () => {
})
it("should join multiple values with &", () => {
expect(queryList("tag", ["art", "music", "photo"])).toBe(
"tag=art&tag=music&tag=photo",
)
expect(queryList("tag", ["art", "music", "photo"])).toBe("tag=art&tag=music&tag=photo")
})
})
+1 -3
View File
@@ -3,7 +3,5 @@ export function queryList(key: string, values: string[]): string {
return ""
}
return values
.map(value => `${key}=${value}`)
.join("&")
return values.map(value => `${key}=${value}`).join("&")
}