Skip to content
Open
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
1 change: 1 addition & 0 deletions .hongdown.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ proper_nouns = [
"ngrok",
"Object Integrity Proofs",
"OpenTelemetry",
"Oxlint",
"Piefed",
"Pixelfed",
"Pleroma",
Expand Down
122 changes: 117 additions & 5 deletions docs/manual/lint.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
description: >-
Fedify provides linting plugins for Deno Lint and ESLint to help you catch
common mistakes and enforce best practices when building federated server
apps.
Fedify provides linting plugins for Deno Lint, ESLint, and Oxlint to help you
catch common mistakes and enforce best practices when building federated
server apps.
---

Linting
Expand All @@ -15,8 +15,9 @@ _This package is available since Fedify 2.0.0._
> app to catch common mistakes early and enforce best practices.

Fedify provides the [`@fedify/lint`] package, which includes lint rules
specifically designed for Fedify applications. It supports both [Deno Lint] and
[ESLint], so you can use it regardless of your JavaScript/TypeScript runtime.
specifically designed for Fedify applications. It supports [Deno Lint],
[ESLint], and [Oxlint], so you can use it regardless of your
JavaScript/TypeScript runtime.

The plugin includes rules that check for:

Expand All @@ -29,6 +30,7 @@ The plugin includes rules that check for:
[`@fedify/lint`]: https://jsr.io/@fedify/lint
[Deno Lint]: https://docs.deno.com/runtime/reference/lint_plugins/
[ESLint]: https://eslint.org/
[Oxlint]: https://oxc.rs/docs/guide/usage/linter/


Installation
Expand Down Expand Up @@ -262,6 +264,114 @@ bunx eslint .
:::


Oxlint
------

[Oxlint] is a fast Rust-based linter that supports ESLint-compatible JS
plugins. `@fedify/lint` exposes its rules through Oxlint's [JS plugin API]
via the `@fedify/lint/oxlint` subpath export.

> [!NOTE]
> Oxlint's JS plugin API is currently in alpha and not subject to semver.

[JS plugin API]: https://oxc.rs/docs/guide/usage/linter/writing-js-plugins.html

### Basic setup

Add the plugin to your _.oxlintrc.json_ via the `jsPlugins` field, then enable
the rules you want:

~~~~ json
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
"jsPlugins": ["@fedify/lint/oxlint"],
"rules": {
"@fedify/lint/actor-id-required": "error",
"@fedify/lint/actor-id-mismatch": "error"
}
}
~~~~

Rule IDs are namespaced under `@fedify/lint/`, matching the ESLint preset.

### Custom configuration

Each rule accepts `"error"`, `"warn"`, or `"off"`. Enable any subset listed in
the [*Rules* section](#rules) below:

~~~~ json
{
"jsPlugins": ["@fedify/lint/oxlint"],
"rules": {
"@fedify/lint/actor-id-required": "error",
"@fedify/lint/actor-id-mismatch": "error",
"@fedify/lint/actor-inbox-property-required": "warn",
"@fedify/lint/actor-outbox-property-required": "warn",
"@fedify/lint/actor-followers-property-required": "warn",
"@fedify/lint/actor-public-key-required": "warn",
"@fedify/lint/actor-assertion-method-required": "warn",
"@fedify/lint/collection-filtering-not-implemented": "warn"
}
}
~~~~

### Running Oxlint

Add a script to _package.json_:

~~~~ jsonc
{
"scripts": {
"lint": "oxlint ."
}
}
~~~~

Then run the linter:

::: code-group

~~~~ sh [npm]
npm run lint
~~~~

~~~~ sh [pnpm]
pnpm lint
~~~~

~~~~ sh [Yarn]
yarn lint
~~~~

~~~~ sh [Bun]
bun lint
~~~~

:::

Or invoke Oxlint directly:

::: code-group

~~~~ sh [npm]
npx oxlint .
~~~~

~~~~ sh [pnpm]
pnpx oxlint .
~~~~

~~~~ sh [Yarn]
yarn oxlint .
~~~~

~~~~ sh [Bun]
bunx oxlint .
~~~~

:::


Rules
-----

Expand Down Expand Up @@ -1217,10 +1327,12 @@ See also
- [`@fedify/lint` on npm]
- [Deno Lint plugins documentation]
- [ESLint documentation]
- [Oxlint documentation]
- [Example project]

[`@fedify/lint` on JSR]: https://jsr.io/@fedify/lint
[`@fedify/lint` on npm]: https://www.npmjs.com/package/@fedify/lint
[Deno Lint plugins documentation]: https://docs.deno.com/runtime/reference/lint_plugins/
[ESLint documentation]: https://eslint.org/
[Oxlint documentation]: https://oxc.rs/docs/guide/usage/linter/
[Example project]: https://github.com/fedify-dev/fedify/tree/main/examples/lint
11 changes: 11 additions & 0 deletions examples/lint/oxlint/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
"jsPlugins": ["@fedify/lint/oxlint"],
"rules": {
"@fedify/lint/actor-id-required": "error",
"@fedify/lint/actor-id-mismatch": "error",
"@fedify/lint/actor-inbox-property-required": "warn",
"@fedify/lint/actor-outbox-property-required": "warn",
"@fedify/lint/actor-followers-property-required": "warn"
}
}
63 changes: 63 additions & 0 deletions examples/lint/oxlint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!-- deno-fmt-ignore-file -->

@fedify/lint with Oxlint
========================

This example demonstrates how to use [`@fedify/lint`] together with [Oxlint]
to catch common Fedify federation mistakes. Note that Oxlint's JS plugin
support is upstream alpha and may be unstable.

[`@fedify/lint`]: https://www.npmjs.com/package/@fedify/lint
[Oxlint]: https://oxc.rs/docs/guide/usage/linter/


Layout
------

- *.oxlintrc.json* — Oxlint configuration that enables `@fedify/lint`
via the JS plugin API.
- *federation.ts* — code that intentionally violates several rules
(missing `id`, `inbox`, `outbox`, `followers`).
- *federation.fixed.ts* — corrected version that passes all rules.


Usage
-----

Install dependencies and run the linter:

~~~~ sh
pnpm install
pnpm lint
~~~~

You should see at least one `@fedify/lint(actor-id-required)` error on
*federation.ts*. Running against *federation.fixed.ts* alone produces no
diagnostics:

~~~~ sh
pnpm lint:fixed
~~~~


How it works
------------

The plugin is loaded via the `jsPlugins` field in *.oxlintrc.json*:

~~~~ json
{
"jsPlugins": ["@fedify/lint/oxlint"],
"rules": {
"@fedify/lint/actor-id-required": "error"
}
}
~~~~

`@fedify/lint/oxlint` is a subpath export that exposes the same rules as the
ESLint plugin in Oxlint's plugin shape. Rule IDs are namespaced under
`@fedify/lint/`.

See the [Linting] manual for the full rule reference.

[Linting]: https://fedify.dev/manual/lint
21 changes: 21 additions & 0 deletions examples/lint/oxlint/federation.fixed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
createFederation,
InProcessMessageQueue,
MemoryKvStore,
} from "@fedify/fedify";
import { Person } from "@fedify/vocab";

const federation = createFederation<void>({
kv: new MemoryKvStore(),
queue: new InProcessMessageQueue(),
});

federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => {
return new Person({
id: ctx.getActorUri(identifier),
name: "Example User",
inbox: ctx.getInboxUri(identifier),
outbox: ctx.getOutboxUri(identifier),
followers: ctx.getFollowersUri(identifier),
});
});
17 changes: 17 additions & 0 deletions examples/lint/oxlint/federation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
createFederation,
InProcessMessageQueue,
MemoryKvStore,
} from "@fedify/fedify";
import { Person } from "@fedify/vocab";

const federation = createFederation<void>({
kv: new MemoryKvStore(),
queue: new InProcessMessageQueue(),
});

federation.setActorDispatcher("/users/{identifier}", (_ctx, _identifier) => {
return new Person({
name: "Example User",
});
});
19 changes: 19 additions & 0 deletions examples/lint/oxlint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@fedify/example-lint-oxlint",
"version": "0.0.0",
"private": true,
"description": "Example project demonstrating @fedify/lint with oxlint",
"type": "module",
"scripts": {
"lint": "oxlint .",
"lint:fixed": "oxlint federation.fixed.ts"
},
"dependencies": {
"@fedify/fedify": "workspace:^",
"@fedify/vocab": "workspace:^"
},
"devDependencies": {
"@fedify/lint": "workspace:^",
"oxlint": "catalog:"
}
}
Loading