Skip to content
96 changes: 0 additions & 96 deletions biome.json

This file was deleted.

56 changes: 0 additions & 56 deletions eslint.config.mjs

This file was deleted.

11 changes: 11 additions & 0 deletions oxfmt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig, type OxfmtConfig } from "oxfmt";

const config: OxfmtConfig = defineConfig({
printWidth: 80,
tabWidth: 4,
sortImports: true,
sortPackageJson: true,
ignorePatterns: [".*", "package-lock.json"],
});

export default config;
224 changes: 224 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import { builtinModules } from "node:module";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use Node-20-compatible lint configuration files

On the advertised Node >=20.19 environment, npm run lint invokes Oxlint, which auto-discovers this TypeScript configuration before linting; however, Oxlint documents that TypeScript configs require Node v22.18+ or v24+. The same issue affects oxfmt.config.ts during the formatting check, so contributors using a supported Node 20 release cannot run the lint workflow. Use JSON/JSONC configurations or raise the package's minimum Node version.

Useful? React with 👍 / 👎.


import { defineConfig, type OxlintConfig } from "oxlint";

import manifest from "./package.json" with { type: "json" };

const runtimePackages = Object.keys(manifest.dependencies);
const toolingPackages = Object.keys(manifest.devDependencies);

/**
* Rules turned off (each group says why they do not fit this code).
*
* @param rules The names of the rules.
* @returns The rules, each turned off.
*/
const off = (...rules: string[]): Record<string, "off"> =>
Object.fromEntries(rules.map((rule) => [rule, "off"]));

const config: OxlintConfig = defineConfig({
plugins: [
"eslint",
"typescript",
"unicorn",
"oxc",
"import",
"jsdoc",
"node",
"promise",
"vitest",
],
// Every rule, except those turned off below.
categories: {
correctness: "error",
suspicious: "error",
pedantic: "error",
perf: "error",
style: "error",
restriction: "error",
},
options: { typeAware: true, reportUnusedDisableDirectives: "error" },
ignorePatterns: ["coverage/", "dist/", "docs/", "src/__fixtures__/"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: [
"**",
"!./**",
"!../**",
"!node:*{,/**}",
...[
...builtinModules,
...runtimePackages,
...toolingPackages,
].map((name) => `!${name}{,/**}`),
],
message:
"Declare tooling dependencies in package.json before importing them.",
},
],
},
],
eqeqeq: ["error", "smart"],
"one-var": ["error", "never"],
"func-style": ["error", "declaration", { allowArrowFunctions: true }],
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
"prefer-destructuring": ["error", { object: true, array: false }],
"capitalized-comments": [
"error",
"always",
// (Lines continuing a comment continue its sentence.)
{ ignorePattern: "oxfmt-ignore", ignoreConsecutiveComments: true },
],
yoda: ["error", "never"],
curly: ["error", "multi-line"],
"no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"typescript/no-unnecessary-condition": "error",
"typescript/strict-boolean-expressions": [
"error",
{ allowNullableBoolean: true },
],
// DOM node types are exposed as prototype getters with constant values.
"class-methods-use-this": ["error", { exceptMethods: ["nodeType"] }],
"typescript/class-literal-property-style": ["error", "getters"],
// Getter summaries describe the value they expose.
"jsdoc/require-returns": ["error", { checkGetters: false }],
"vitest/consistent-test-filename": [
"error",
{ pattern: String.raw`\.spec\.ts$` },
],
"vitest/consistent-test-it": ["error", { fn: "it" }],
"unicorn/numeric-separators-style": [
"error",
{ hexadecimal: { onlyIfContainsSeparator: true } },
],
"typescript/explicit-member-accessibility": [
"error",
{ accessibility: "no-public" },
],
"typescript/explicit-function-return-type": [
"error",
{ allowExpressions: true },
],
"typescript/no-confusing-void-expression": [
"error",
{ ignoreArrowShorthand: true },
],
"typescript/switch-exhaustiveness-check": [
"error",
{ considerDefaultExhaustiveForUnions: true },
],
"vitest/prefer-lowercase-title": ["error", { ignore: ["describe"] }],
// DOM node type IDs are standardized numbers, and T is a conventional type parameter.
...off("no-magic-numbers", "id-length"),
// Node APIs use null for absent links and accept undefined for optional inputs.
...off("unicorn/no-null", "no-undefined"),
// Modern syntax and the runtime's features are fine.
...off(
"oxc/no-async-await",
"oxc/no-optional-chaining",
"oxc/no-rest-spread-properties",
"no-plusplus",
"no-continue",
"no-ternary",
"no-nested-ternary",
"unicorn/no-nested-ternary",
"unicorn/no-array-reduce",
"promise/avoid-new",
"node/no-top-level-await",
"node/no-sync",
"import/no-nodejs-modules",
"unicorn/import-style",
),
// Async functions without `await` return their values and errors as promises.
...off("require-await", "typescript/require-await"),
// Sizes, and orders that do not follow the code's structure.
...off(
"max-params",
"max-statements",
"max-lines",
"max-lines-per-function",
"max-classes-per-file",
"unicorn/max-nested-calls",
"sort-keys",
"no-use-before-define",
"no-inline-comments",
"init-declarations",
),
// Let the formatter sort imports and keep the existing module structure.
...off(
"sort-imports",
"import/consistent-type-specifier-style",
"import/no-named-export",
"import/no-default-export",
"import/prefer-default-export",
"import/group-exports",
"import/exports-last",
"import/no-relative-parent-imports",
),
// TypeScript supplies the JSDoc types, and mutable inputs are supported.
...off(
"jsdoc/require-param-type",
"jsdoc/require-returns-type",
"jsdoc/require-yields-type",
"jsdoc/require-throws-type",
"typescript/prefer-readonly-parameter-types",
),
// Nullish equality is allowed by eqeqeq's smart mode.
...off("no-eq-null"),
// Synchronous tests import their APIs explicitly and check exact values.
...off(
"vitest/prefer-expect-assertions",
"vitest/require-test-timeout",
"vitest/no-importing-vitest-globals",
"vitest/max-expects",
"vitest/prefer-to-be-truthy",
"vitest/prefer-to-be-falsy",
),
},
overrides: [
{
// Published modules run in browsers.
files: ["src/**/*.ts"],
excludeFiles: ["**/*.spec.ts"],
rules: {
"import/no-nodejs-modules": "error",
"no-restricted-imports": [
"error",
{
patterns: [
// Check test paths before allowing relative imports.
{
regex: String.raw`(?:^|/)(?:__fixtures__|__snapshots__|__tests__|tests?)(?:/|$)|\.(?:spec|test)(?:\.[cm]?[jt]sx?)?$`,
message:
"Published modules must not import tests or fixtures.",
},
{
group: [
"**",
"!./**",
"!../**",
...runtimePackages.map(
(name) => `!${name}{,/**}`,
),
],
message:
"Published modules may import only runtime dependencies and relative modules.",
},
],
},
],
// Keep indexed sibling lookup in parser and traversal hot paths.
...off("unicorn/prefer-at"),
},
},
],
});

export default config;
Loading