Skip to content

Commit b9093a9

Browse files
committed
Added documents about @fedify/lint
1 parent dbf2e4c commit b9093a9

4 files changed

Lines changed: 540 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The repository is organized as a monorepo with the following packages:
7676
- *packages/koa/*: Koa integration (@fedify/koa)
7777
- *packages/postgres/*: PostgreSQL drivers (@fedify/postgres)
7878
- *packages/redis/*: Redis drivers (@fedify/redis)
79+
- *packages/lint/*: Linting utilities (@fedify/lint)
7980
- *packages/nestjs/*: NestJS integration (@fedify/nestjs)
8081
- *packages/next/*: Next.js integration (@fedify/next)
8182
- *packages/sqlite/*: SQLite driver (@fedify/sqlite)

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ To be released.
186186
- This package is primarily used by generated vocabulary classes and
187187
provides the runtime infrastructure for ActivityPub object processing.
188188

189+
### @fedify/lint
190+
191+
- Created Fedify linting tools as the *@fedify/lint* package.
192+
This package provides shared Deno Lint and ESLint configurations for
193+
consistent code style across Fedify packages and user projects.
194+
[[#297], [#494] by ChanHaeng Lee]
195+
189196

190197
Version 1.10.0
191198
--------------

docs/tutorial/basics.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,128 @@ should see the actor's followers in the bulleted list.
12791279
[Hono]: https://hono.dev/
12801280
12811281
1282+
Linting your federation code
1283+
-----------------------------
1284+
1285+
As your federated server grows, it's important to maintain code quality and
1286+
catch common mistakes early. Fedify provides linting plugins for both
1287+
[Deno Lint] and [ESLint], which include specialized linting rules for
1288+
federation code.
1289+
1290+
The `@fedify/lint` package helps you avoid common pitfalls such as:
1291+
1292+
- Using incorrect actor IDs (e.g., relative URLs instead of
1293+
`Context.getActorUri()`)
1294+
- Missing required actor properties (inbox, outbox, followers, etc.)
1295+
- Incorrect URL patterns for actor collections
1296+
- Missing public keys or assertion methods
1297+
1298+
### Using Deno Lint
1299+
1300+
If you are using Deno, you can use the Deno Lint plugin. First, install the
1301+
plugin:
1302+
1303+
~~~~ sh
1304+
deno add jsr:@fedify/lint
1305+
~~~~
1306+
1307+
Then add the plugin to your *deno.json* configuration file:
1308+
1309+
~~~~ json
1310+
{
1311+
"lint": {
1312+
"plugins": ["jsr:@fedify/lint"]
1313+
}
1314+
}
1315+
~~~~
1316+
1317+
Now you can run the linter on your code:
1318+
1319+
~~~~ sh
1320+
deno lint
1321+
~~~~
1322+
1323+
### Using ESLint
1324+
1325+
For ESLint users (including Deno, Bun, and Node.js), first install the plugin:
1326+
1327+
::: code-group
1328+
1329+
~~~~ sh [Bun]
1330+
bun add -D @fedify/lint eslint
1331+
~~~~
1332+
1333+
~~~~ sh [Node.js]
1334+
npm add -D @fedify/lint eslint
1335+
~~~~
1336+
1337+
:::
1338+
1339+
Then create an ESLint configuration file (e.g., *eslint.config.ts*) in your
1340+
project directory:
1341+
1342+
~~~~ typescript twoslash
1343+
import fedifyLint from "@fedify/lint";
1344+
1345+
export default [{
1346+
...fedifyLint,
1347+
files: ["**/*.ts"],
1348+
}];
1349+
~~~~
1350+
1351+
Now you can run the linter on your code:
1352+
1353+
::: code-group
1354+
1355+
~~~~ sh [Bun]
1356+
bun run eslint .
1357+
~~~~
1358+
1359+
~~~~ sh [Node.js]
1360+
npx eslint .
1361+
~~~~
1362+
1363+
:::
1364+
1365+
> [!NOTE]
1366+
> When using ESLint with Deno, you may need to exclude some Deno-specific
1367+
> lint rules like `no-unused-vars` to avoid conflicts.
1368+
1369+
### Example
1370+
1371+
For example, if you had written the actor dispatcher like this:
1372+
1373+
~~~~ typescript
1374+
// ❌ Wrong: Using relative URL
1375+
federation.setActorDispatcher(
1376+
"/{identifier}",
1377+
(_ctx, identifier) => {
1378+
return new Person({
1379+
id: new URL(`/${identifier}`), // ❌ Linter will catch this
1380+
name: "Example User",
1381+
});
1382+
},
1383+
);
1384+
~~~~
1385+
1386+
The linter would warn you:
1387+
1388+
~~~~
1389+
error[fedify-lint/actor-id-mismatch]: Actor's `id` property must match
1390+
`_ctx.getActorUri(identifier)`. Ensure you're using the correct context method.
1391+
~~~~
1392+
1393+
This helps you catch mistakes before they cause issues in production. The
1394+
linter includes many other rules to ensure your federation code follows best
1395+
practices.
1396+
1397+
For more information about available rules and configuration options, see
1398+
the [`@fedify/lint` documentation](https://jsr.io/@fedify/lint).
1399+
1400+
[Deno Lint]: https://docs.deno.com/runtime/reference/lint_plugins/
1401+
[ESLint]: https://eslint.org/
1402+
1403+
12821404
Wrapping up
12831405
-----------
12841406

0 commit comments

Comments
 (0)