@@ -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+
12821404Wrapping up
12831405-----------
12841406
0 commit comments