@fedify/lint 2.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +410 -0
- package/deno.json +15 -0
- package/dist/index.cjs +751 -0
- package/dist/index.d.cts +160 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.js +726 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024–2025 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@fedify/lint: ESLint plugin for Fedify
|
|
4
|
+
=======================================
|
|
5
|
+
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
8
|
+
[![Follow @fedify@hollo.social][@fedify@hollo.social badge]][@fedify@hollo.social]
|
|
9
|
+
|
|
10
|
+
*This package is available since Fedify 2.0.0.*
|
|
11
|
+
|
|
12
|
+
This package provides [Deno Lint] and [ESLint] plugin with lint rules specifically designed
|
|
13
|
+
for [Fedify] applications. It helps you catch common mistakes and enforce
|
|
14
|
+
best practices when building federated server apps with Fedify.
|
|
15
|
+
|
|
16
|
+
The plugin includes rules that check for:
|
|
17
|
+
|
|
18
|
+
- Proper actor ID configuration
|
|
19
|
+
- Required actor properties (inbox, outbox, followers, etc.)
|
|
20
|
+
- Correct URL patterns for actor collections
|
|
21
|
+
- Public key and assertion method requirements
|
|
22
|
+
- Collection filtering implementation
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Deno Lint Configuration Example
|
|
26
|
+
|
|
27
|
+
~~~~ typescript
|
|
28
|
+
// deno.json
|
|
29
|
+
|
|
30
|
+
{
|
|
31
|
+
"lint": {
|
|
32
|
+
"plugins": {
|
|
33
|
+
"@fedify/lint": "jsr:@fedify/lint"
|
|
34
|
+
},
|
|
35
|
+
"rules": {
|
|
36
|
+
"@fedify/lint/actor-id-required": "error",
|
|
37
|
+
"@fedify/lint/actor-id-mismatch": "error",
|
|
38
|
+
"@fedify/lint/actor-inbox-property-required": "warn"
|
|
39
|
+
// ... other rules
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
~~~~
|
|
44
|
+
|
|
45
|
+
### ESLint Configuration Example
|
|
46
|
+
|
|
47
|
+
~~~~ typescript
|
|
48
|
+
// eslint.config.ts
|
|
49
|
+
|
|
50
|
+
import fedifyLint from "@fedify/lint";
|
|
51
|
+
|
|
52
|
+
export default fedifyLint;
|
|
53
|
+
~~~~
|
|
54
|
+
|
|
55
|
+
[JSR]: https://jsr.io/@fedify/lint
|
|
56
|
+
[JSR badge]: https://jsr.io/badges/@fedify/lint
|
|
57
|
+
[npm]: https://www.npmjs.com/package/@fedify/lint
|
|
58
|
+
[npm badge]: https://img.shields.io/npm/v/@fedify/lint?logo=npm
|
|
59
|
+
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
60
|
+
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
61
|
+
[Deno Lint]: https://docs.deno.com/runtime/reference/lint_plugins/
|
|
62
|
+
[ESLint]: https://eslint.org/
|
|
63
|
+
[Fedify]: https://fedify.dev/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
Features
|
|
67
|
+
--------
|
|
68
|
+
|
|
69
|
+
The `@fedify/lint` package provides comprehensive linting rules for Fedify
|
|
70
|
+
federation code:
|
|
71
|
+
|
|
72
|
+
### Actor Validation Rules
|
|
73
|
+
|
|
74
|
+
- **`actor-id-required`**: Ensures all actors have an `id` property
|
|
75
|
+
- **`actor-id-mismatch`**: Validates that actor IDs match the expected URI
|
|
76
|
+
from `Context.getActorUri()`
|
|
77
|
+
- **`actor-public-key-required`**: Ensures actors have public keys for
|
|
78
|
+
HTTP Signatures
|
|
79
|
+
- **`actor-assertion-method-required`**: Validates assertion methods for
|
|
80
|
+
Object Integrity Proofs
|
|
81
|
+
|
|
82
|
+
### Collection Property Rules
|
|
83
|
+
|
|
84
|
+
- **`actor-inbox-property-required`**: Ensures inbox is defined when
|
|
85
|
+
`setInboxListeners` is set
|
|
86
|
+
- **`actor-inbox-property-mismatch`**: Validates inbox URI from `getInboxUri`
|
|
87
|
+
- **`actor-outbox-property-required`**: Ensures outbox is defined when
|
|
88
|
+
`setOutboxDispatcher` is set
|
|
89
|
+
- **`actor-outbox-property-mismatch`**: Validates outbox URI from
|
|
90
|
+
`getOutboxUri`
|
|
91
|
+
- **`actor-followers-property-required`**: Ensures followers is defined when
|
|
92
|
+
`setFollowersDispatcher` is set
|
|
93
|
+
- **`actor-followers-property-mismatch`**: Validates followers URI from
|
|
94
|
+
`getFollowersUri`
|
|
95
|
+
- **`actor-following-property-required`**: Ensures following is defined when
|
|
96
|
+
`setFollowingDispatcher` is set
|
|
97
|
+
- **`actor-following-property-mismatch`**: Validates following URI from
|
|
98
|
+
`getFollowingUri`
|
|
99
|
+
- **`actor-liked-property-required`**: Ensures liked is defined when
|
|
100
|
+
`setLikedDispatcher` is set
|
|
101
|
+
- **`actor-liked-property-mismatch`**: Validates liked URI from `getLikedUri`
|
|
102
|
+
- **`actor-featured-property-required`**: Ensures featured is defined when
|
|
103
|
+
`setFeaturedDispatcher` is set
|
|
104
|
+
- **`actor-featured-property-mismatch`**: Validates featured URI from
|
|
105
|
+
`getFeaturedUri`
|
|
106
|
+
- **`actor-featured-tags-property-required`**: Ensures featuredTags is defined
|
|
107
|
+
when `setFeaturedTagsDispatcher` is set
|
|
108
|
+
- **`actor-featured-tags-property-mismatch`**: Validates featuredTags URI from
|
|
109
|
+
`getFeaturedTagsUri`
|
|
110
|
+
- **`actor-shared-inbox-property-required`**: Ensures sharedInbox is defined
|
|
111
|
+
when `setInboxListeners` is set
|
|
112
|
+
- **`actor-shared-inbox-property-mismatch`**: Validates sharedInbox URI from
|
|
113
|
+
`getInboxUri`
|
|
114
|
+
|
|
115
|
+
### Other Rules
|
|
116
|
+
|
|
117
|
+
- **`collection-filtering-not-implemented`**: Warns about missing collection
|
|
118
|
+
filtering implementation (`setFollowersDispatcher` only for now)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
Installation
|
|
122
|
+
------------
|
|
123
|
+
|
|
124
|
+
::: code-group
|
|
125
|
+
|
|
126
|
+
~~~~ sh [Deno]
|
|
127
|
+
deno add jsr:@fedify/lint
|
|
128
|
+
~~~~
|
|
129
|
+
|
|
130
|
+
~~~~ sh [npm]
|
|
131
|
+
npm add -D @fedify/lint
|
|
132
|
+
~~~~
|
|
133
|
+
|
|
134
|
+
~~~~ sh [pnpm]
|
|
135
|
+
pnpm add -D @fedify/lint
|
|
136
|
+
~~~~
|
|
137
|
+
|
|
138
|
+
~~~~ sh [Yarn]
|
|
139
|
+
yarn add -D @fedify/lint
|
|
140
|
+
~~~~
|
|
141
|
+
|
|
142
|
+
~~~~ sh [Bun]
|
|
143
|
+
bun add -D @fedify/lint
|
|
144
|
+
~~~~
|
|
145
|
+
|
|
146
|
+
:::
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
Usage (Deno Lint)
|
|
150
|
+
------------------
|
|
151
|
+
|
|
152
|
+
### Basic Setup
|
|
153
|
+
|
|
154
|
+
Add the plugin to your *deno.json* configuration file:
|
|
155
|
+
|
|
156
|
+
~~~~ json
|
|
157
|
+
{
|
|
158
|
+
"lint": {
|
|
159
|
+
"plugins": ["jsr:@fedify/lint"]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
~~~~
|
|
163
|
+
|
|
164
|
+
By default, this enables all recommended rules.
|
|
165
|
+
|
|
166
|
+
### Custom Configuration
|
|
167
|
+
|
|
168
|
+
You can customize which rules to enable and their severity levels:
|
|
169
|
+
|
|
170
|
+
~~~~ json
|
|
171
|
+
{
|
|
172
|
+
"lint": {
|
|
173
|
+
"plugins": ["jsr:@fedify/lint"],
|
|
174
|
+
"rules": {
|
|
175
|
+
"tags": ["recommended"],
|
|
176
|
+
"include": [
|
|
177
|
+
"@fedify/lint/actor-id-required",
|
|
178
|
+
"@fedify/lint/actor-id-mismatch"
|
|
179
|
+
],
|
|
180
|
+
"exclude": [
|
|
181
|
+
"@fedify/lint/actor-featured-property-required"
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
~~~~
|
|
187
|
+
|
|
188
|
+
### Running Deno Lint
|
|
189
|
+
|
|
190
|
+
After setting up the configuration, run Deno's linter:
|
|
191
|
+
|
|
192
|
+
~~~~ sh
|
|
193
|
+
deno lint
|
|
194
|
+
~~~~
|
|
195
|
+
|
|
196
|
+
You can also specify which files to lint:
|
|
197
|
+
|
|
198
|
+
~~~~ sh
|
|
199
|
+
deno lint federation.ts
|
|
200
|
+
deno lint src/federation/
|
|
201
|
+
~~~~
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
Usage (ESLint)
|
|
205
|
+
--------------
|
|
206
|
+
|
|
207
|
+
### Basic Setup
|
|
208
|
+
|
|
209
|
+
Add the plugin to your ESLint configuration file (e.g., *eslint.config.ts*
|
|
210
|
+
or *eslint.config.js*):
|
|
211
|
+
|
|
212
|
+
~~~~ typescript
|
|
213
|
+
import fedifyLint from "@fedify/lint";
|
|
214
|
+
|
|
215
|
+
// If your `createFederation` code is in `federation.ts` or `federation/**.ts`
|
|
216
|
+
export default fedifyLint;
|
|
217
|
+
|
|
218
|
+
// Or specify your own federation files
|
|
219
|
+
export default {
|
|
220
|
+
...fedifyLint,
|
|
221
|
+
files: ["my-own-federation.ts"],
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// If you use other ESLint configurations
|
|
225
|
+
|
|
226
|
+
export default [
|
|
227
|
+
otherConfig,
|
|
228
|
+
fedifyLint,
|
|
229
|
+
];
|
|
230
|
+
~~~~
|
|
231
|
+
|
|
232
|
+
The default configuration applies recommended rules to files that match
|
|
233
|
+
common federation-related patterns (e.g., *federation.ts*, *federation/\*.ts*).
|
|
234
|
+
|
|
235
|
+
### Custom Configuration
|
|
236
|
+
|
|
237
|
+
You can customize which files to lint and which rules to enable:
|
|
238
|
+
|
|
239
|
+
~~~~ typescript
|
|
240
|
+
import { plugin } from "@fedify/lint";
|
|
241
|
+
|
|
242
|
+
export default [{
|
|
243
|
+
files: ["src/federation/**/*.ts"], // Your federation code location
|
|
244
|
+
plugins: {
|
|
245
|
+
"@fedify/lint": plugin,
|
|
246
|
+
},
|
|
247
|
+
rules: {
|
|
248
|
+
"@fedify/lint/actor-id-required": "error",
|
|
249
|
+
"@fedify/lint/actor-id-mismatch": "error",
|
|
250
|
+
"@fedify/lint/actor-inbox-property-required": "warn",
|
|
251
|
+
// ... other rules
|
|
252
|
+
},
|
|
253
|
+
}];
|
|
254
|
+
~~~~
|
|
255
|
+
|
|
256
|
+
### Using Configurations
|
|
257
|
+
|
|
258
|
+
The plugin provides two preset configurations:
|
|
259
|
+
|
|
260
|
+
#### Recommended (default)
|
|
261
|
+
|
|
262
|
+
Enables critical rules as errors and optional rules as warnings:
|
|
263
|
+
|
|
264
|
+
~~~~ typescript
|
|
265
|
+
import fedifyLint from "@fedify/lint";
|
|
266
|
+
|
|
267
|
+
export default fedifyLint;
|
|
268
|
+
~~~~
|
|
269
|
+
|
|
270
|
+
#### Strict
|
|
271
|
+
|
|
272
|
+
Enables all rules as errors:
|
|
273
|
+
|
|
274
|
+
~~~~ typescript
|
|
275
|
+
import { plugin } from "@fedify/lint";
|
|
276
|
+
|
|
277
|
+
export default [{
|
|
278
|
+
files: ["**/*.ts"],
|
|
279
|
+
...plugin.configs.strict,
|
|
280
|
+
}];
|
|
281
|
+
~~~~
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
Example
|
|
285
|
+
-------
|
|
286
|
+
|
|
287
|
+
Here's an example of code that would trigger lint errors:
|
|
288
|
+
|
|
289
|
+
~~~~ typescript
|
|
290
|
+
// ❌ Wrong: Using relative URL for actor ID
|
|
291
|
+
import { createFederation, Person } from "@fedify/fedify";
|
|
292
|
+
|
|
293
|
+
const federation = createFederation({ /* ... */ });
|
|
294
|
+
|
|
295
|
+
federation.setActorDispatcher(
|
|
296
|
+
"/{identifier}",
|
|
297
|
+
(_ctx, identifier) => {
|
|
298
|
+
return new Person({
|
|
299
|
+
id: new URL(`/${identifier}`), // ❌ Should use ctx.getActorUri()
|
|
300
|
+
name: "Example User",
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
);
|
|
304
|
+
~~~~
|
|
305
|
+
|
|
306
|
+
Corrected version:
|
|
307
|
+
|
|
308
|
+
~~~~ typescript
|
|
309
|
+
// ✅ Correct: Using Context.getActorUri() for actor ID
|
|
310
|
+
import { createFederation, Person } from "@fedify/fedify";
|
|
311
|
+
|
|
312
|
+
const federation = createFederation({ /* ... */ });
|
|
313
|
+
|
|
314
|
+
federation.setActorDispatcher(
|
|
315
|
+
"/{identifier}",
|
|
316
|
+
(ctx, identifier) => {
|
|
317
|
+
return new Person({
|
|
318
|
+
id: ctx.getActorUri(identifier), // ✅ Correct
|
|
319
|
+
name: "Example User",
|
|
320
|
+
inbox: ctx.getInboxUri(identifier),
|
|
321
|
+
outbox: ctx.getOutboxUri(identifier),
|
|
322
|
+
followers: ctx.getFollowersUri(identifier),
|
|
323
|
+
// ... other required properties
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
);
|
|
327
|
+
~~~~
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
Running the Linter
|
|
331
|
+
------------------
|
|
332
|
+
|
|
333
|
+
### Deno Lint
|
|
334
|
+
|
|
335
|
+
Run Deno's linter with the plugin enabled:
|
|
336
|
+
|
|
337
|
+
~~~~ sh
|
|
338
|
+
deno lint
|
|
339
|
+
~~~~
|
|
340
|
+
|
|
341
|
+
You can also specify which files or directories to lint:
|
|
342
|
+
|
|
343
|
+
~~~~ sh
|
|
344
|
+
deno lint federation.ts
|
|
345
|
+
deno lint src/federation/
|
|
346
|
+
~~~~
|
|
347
|
+
|
|
348
|
+
### ESLint
|
|
349
|
+
|
|
350
|
+
Set up your ESLint configuration as shown above and add a follwing script on
|
|
351
|
+
`package.json`:
|
|
352
|
+
|
|
353
|
+
~~~~ jsonc
|
|
354
|
+
{
|
|
355
|
+
"scripts": {
|
|
356
|
+
"lint": "eslint ."
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
~~~~
|
|
360
|
+
|
|
361
|
+
After setting up the configuration, run ESLint on your codebase:
|
|
362
|
+
|
|
363
|
+
::: code-group
|
|
364
|
+
|
|
365
|
+
~~~~ sh [npm]
|
|
366
|
+
npm run lint
|
|
367
|
+
~~~~
|
|
368
|
+
|
|
369
|
+
~~~~ sh [pnpm]
|
|
370
|
+
pnpm lint
|
|
371
|
+
~~~~
|
|
372
|
+
|
|
373
|
+
~~~~ sh [Yarn]
|
|
374
|
+
yarn lint
|
|
375
|
+
~~~~
|
|
376
|
+
|
|
377
|
+
~~~~ sh [Bun]
|
|
378
|
+
bun lint
|
|
379
|
+
~~~~
|
|
380
|
+
|
|
381
|
+
:::
|
|
382
|
+
|
|
383
|
+
or run the linter directly via command line:
|
|
384
|
+
|
|
385
|
+
::: code-group
|
|
386
|
+
|
|
387
|
+
~~~~ sh [npm]
|
|
388
|
+
npx eslint .
|
|
389
|
+
~~~~
|
|
390
|
+
|
|
391
|
+
~~~~ sh [pnpm]
|
|
392
|
+
pnpx eslint .
|
|
393
|
+
~~~~
|
|
394
|
+
|
|
395
|
+
~~~~ sh [Yarn]
|
|
396
|
+
yarn eslint .
|
|
397
|
+
~~~~
|
|
398
|
+
|
|
399
|
+
~~~~ sh [Bun]
|
|
400
|
+
bunx eslint .
|
|
401
|
+
~~~~
|
|
402
|
+
|
|
403
|
+
:::
|
|
404
|
+
|
|
405
|
+
See Also
|
|
406
|
+
--------
|
|
407
|
+
|
|
408
|
+
- [Fedify Documentation](https://fedify.dev/)
|
|
409
|
+
- [ESLint Documentation](https://eslint.org/)
|
|
410
|
+
- [Example Project](https://github.com/fedify-dev/fedify/tree/main/examples/lint)
|
package/deno.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fedify/lint",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/mod.ts"
|
|
7
|
+
},
|
|
8
|
+
"imports": {
|
|
9
|
+
"eslint": "npm:eslint@^9.0.0",
|
|
10
|
+
"estree": "npm:@types/estree@^1.0.8"
|
|
11
|
+
},
|
|
12
|
+
"tasks": {
|
|
13
|
+
"test": "deno test --allow-env"
|
|
14
|
+
}
|
|
15
|
+
}
|