Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
126 changes: 121 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
Comment thread
nyanrus marked this conversation as resolved.
Outdated
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.
Comment thread
nyanrus marked this conversation as resolved.
Outdated

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/
Comment thread
nyanrus marked this conversation as resolved.
Outdated


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


Oxlint
------

[oxlint] is a fast Rust-based linter that supports ESLint-compatible JS
Comment thread
nyanrus marked this conversation as resolved.
Outdated
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 the loader runs only under
Comment thread
nyanrus marked this conversation as resolved.
Outdated
> Node.js. The `@fedify/lint/oxlint` subpath is therefore distributed via npm
> only, not JSR.

[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 below:
Comment thread
nyanrus marked this conversation as resolved.
Outdated

~~~~ 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"
}
}
~~~~

[Rules]: #rules
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

### 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:
Comment thread
nyanrus marked this conversation as resolved.
Outdated

::: 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 +1331,12 @@ See also
- [`@fedify/lint` on npm]
- [Deno Lint plugins documentation]
- [ESLint documentation]
- [oxlint documentation]
Comment thread
nyanrus marked this conversation as resolved.
Outdated
- [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/
Comment thread
nyanrus marked this conversation as resolved.
Outdated
[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"
}
}
62 changes: 62 additions & 0 deletions examples/lint/oxlint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!-- 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.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
[`@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