# @fedify/lint 中文文档

规范地址：https://npmcn.com/package/%40fedify/lint/

版本：2\.1\.32
npm 元数据更新时间：2026-11-17T06:44:41.898Z
中文译文更新时间：2026-11-17T06:45:20.624Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40fedify/lint
原文对照：https://npmcn.com/package/%40fedify/lint/?lang=original
项目主页：https://fedify.dev/
源码仓库：https://github.com/fedify-dev/fedify

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：65.4 kB，8 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：eslint \>=9\.0\.0，@fedify/fedify ^2\.1\.32
- 首次发布：2025-12-31T09:17:49.130Z
- 最新版本发布：2026-11-17T06:44:41.510Z
- 近 30 天下载量：10058（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：571（近 12 个月 571 个）

## 中文简介

合并林化规则和插件

## 安装

```sh
npm install @fedify/lint
```

也可以使用：`pnpm add @fedify/lint`、`yarn add @fedify/lint`、`bun add @fedify/lint`

## README

# @ fedify/lint: 联邦化的ESLint插件

[![JSR](https://jsr.io/badges/@fedify/lint)](https://jsr.io/@fedify/lint) [![npm](https://img.shields.io/npm/v/@fedify/lint?logo=npm)](https://www.npmjs.com/package/@fedify/lint) [![Follow @fedify@hollo.social](https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg)](https://hollo.social/@fedify)

_此包自Fedify 2.0._

此软件包提供 [德诺·林特](https://docs.deno.com/runtime/reference/lint_plugins/) 财务报告和审定财务报表 [ESLint 语录](https://eslint.org/) 带有插件规则的插件 专为 [联邦](https://fedify.dev/) 应用。 它能帮助你找到常见的 在构建联邦服务器应用程序时错误并强制执行最佳做法 联邦.

插件包括检查 :

-   适当的演员身份配置
-   所需的演员属性( 收件箱、 发件箱、 追随者等)
-   正确的演员收藏的 URL 模式
-   公用钥匙和断言方法要求
-   收集过滤执行

### Deno Lint 配置实例

```typescript
// deno.json

{
  "lint": {
    "plugins": {
      "@fedify/lint": "jsr:@fedify/lint"
    },
    "rules": {
      "@fedify/lint/actor-id-required": "error",
      "@fedify/lint/actor-id-mismatch": "error",
      "@fedify/lint/actor-inbox-property-required": "warn"
      // ... other rules
    }
  }
}
```

### ESLint 配置示例

```typescript
// eslint.config.ts

import fedifyLint from "@fedify/lint";

export default fedifyLint;
```

## 特征

这个 `@fedify/lint` 软件包为联邦提供了全面的折叠规则 联邦代码 :

### 演员验证规则

-   **`actor-id-required`**:确保所有行动者 `id` 属性
-   **`actor-id-mismatch`**: 验证演员ID与预期的 URI 匹配 从 `Context.getActorUri()`
-   **`actor-public-key-required`**:确保行为者拥有用于 HTTP 签名
-   **`actor-assertion-method-required`**: 验证 对象完整性证明

### 财产征收规则

-   **`actor-inbox-property-required`**: 当 `setInboxListeners` 设定
-   **`actor-inbox-property-mismatch`**: 验证信箱 URI from `getInboxUri`
-   **`actor-outbox-property-required`**:确保当 `setOutboxDispatcher` 设定
-   **`actor-outbox-property-mismatch`**: 校验发件箱 URI 从 `getOutboxUri`
-   **`actor-followers-property-required`**: 确保在 `setFollowersDispatcher` 设定
-   **`actor-followers-property-mismatch`**: 验证追随者的 URI from `getFollowersUri`
-   **`actor-following-property-required`**: 当 `setFollowingDispatcher` 设定
-   **`actor-following-property-mismatch`**: URI 从 `getFollowingUri`
-   **`actor-liked-property-required`**: 在 `setLikedDispatcher` 设定
-   **`actor-liked-property-mismatch`**: 校验器喜欢来自 `getLikedUri`
-   **`actor-featured-property-required`**: 当 `setFeaturedDispatcher` 设定
-   **`actor-featured-property-mismatch`**: 校验显示 URI 从 `getFeaturedUri`
-   **`actor-featured-tags-property-required`**: 确保显示 标记被定义 何时 `setFeaturedTagsDispatcher` 设定
-   **`actor-featured-tags-property-mismatch`**: 显示的验证符 标记 URI 从 `getFeaturedTagsUri`
-   **`actor-shared-inbox-property-required`**: 确保共享信箱被定义 何时 `setInboxListeners` 设定
-   **`actor-shared-inbox-property-mismatch`**: 验证共享的Inbox URI 来源 `getInboxUri`

### 其他规则

-   **`collection-filtering-not-implemented`**: 关于丢失收藏的警告 过滤执行`setFollowersDispatcher` 暂时的)

## 安装

\* :密码组

```sh
deno add jsr:@fedify/lint
```

```sh
npm add -D @fedify/lint
```

```sh
pnpm add -D @fedify/lint
```

```sh
yarn add -D @fedify/lint
```

```sh
bun add -D @fedify/lint
```

\* :

## 用法 (德诺林特)

### 基本设置

将插件添加到您的 _德诺·杰森_ 配置文件 :

```json
{
  "lint": {
    "plugins": ["jsr:@fedify/lint"]
  }
}
```

默认情况下,这可以实现所有推荐的规则.

### 自定义配置

您可以自定义要启用哪些规则及其严重程度:

```json
{
  "lint": {
    "plugins": ["jsr:@fedify/lint"],
    "rules": {
      "tags": ["recommended"],
      "include": [
        "@fedify/lint/actor-id-required",
        "@fedify/lint/actor-id-mismatch"
      ],
      "exclude": [
        "@fedify/lint/actor-featured-property-required"
      ]
    }
  }
}
```

### 运行 Deno 林特

设置配置后, 运行 Deno 的 linter :

```sh
deno lint
```

您也可以指定要插入的文件 :

```sh
deno lint federation.ts
deno lint src/federation/
```

## 用法( ESLint)

### 基本设置

将插件添加到您的 ESLint 配置文件( 例如, ), _互联网档案馆的存檔,存档日期2013-12-02_ 或者说 _互联网档案馆的存檔,存档日期2013-12-02_:

```typescript
import fedifyLint from "@fedify/lint";

// If your `createFederation` code is in `federation.ts` or `federation/**.ts`
export default fedifyLint; 

// Or specify your own federation files
export default {
  ...fedifyLint,
  files: ["my-own-federation.ts"],
};

// If you use other ESLint configurations

export default [
  otherConfig,
  fedifyLint,
];
```

默认配置对匹配的文件应用推荐规则 与联邦有关的共同模式(例如:, _联邦_, (中文(简体) ), _联合会/\*.ts_) (中文(简体) ).

### 自定义配置

您可以自定义哪些文件可以擦出, 哪些规则可以启用 :

```typescript
import { plugin } from "@fedify/lint";

export default [{
  files: ["src/federation/**/*.ts"],  // Your federation code location
  plugins: {
    "@fedify/lint": plugin,
  },
  rules: {
    "@fedify/lint/actor-id-required": "error",
    "@fedify/lint/actor-id-mismatch": "error",
    "@fedify/lint/actor-inbox-property-required": "warn",
    // ... other rules
  },
}];
```

### 使用配置

该插件提供了两个预设配置:

#### 建议(默认)

允许将关键规则作为错误, 可选规则作为警告 :

```typescript
import fedifyLint from "@fedify/lint";

export default fedifyLint;
```

#### 严格

启用所有规则为错误 :

```typescript
import { plugin } from "@fedify/lint";

export default [{
  files: ["**/*.ts"],
  ...plugin.configs.strict,
}];
```

## 示例

这里有一个代码的例子会引发错误:

```typescript
// ❌ Wrong: Using relative URL for actor ID
import { createFederation, Person } from "@fedify/fedify";

const federation = createFederation({ /* ... */ });

federation.setActorDispatcher(
  "/{identifier}",
  (_ctx, identifier) => {
    return new Person({
      id: new URL(`/${identifier}`),  // ❌ Should use ctx.getActorUri()
      name: "Example User",
    });
  },
);
```

已更正版本 :

```typescript
// ✅ Correct: Using Context.getActorUri() for actor ID
import { createFederation, Person } from "@fedify/fedify";

const federation = createFederation({ /* ... */ });

federation.setActorDispatcher(
  "/{identifier}",
  (ctx, identifier) => {
    return new Person({
      id: ctx.getActorUri(identifier),  // ✅ Correct
      name: "Example User",
      inbox: ctx.getInboxUri(identifier),
      outbox: ctx.getOutboxUri(identifier),
      followers: ctx.getFollowersUri(identifier),
      // ... other required properties
    });
  },
);
```

## 运行电线

### 德诺·林特

用插件运行 Deno 的插件 :

```sh
deno lint
```

您也可以指定要提示的文件或目录 :

```sh
deno lint federation.ts
deno lint src/federation/
```

### ESLint 语录

如上所示设置您的 ESLint 配置, 并添加一个 follwing 脚本 `package.json`数字 :

```jsonc
{
  "scripts": {
    "lint": "eslint ."
  }
}
```

设置配置后, 在您的代码库上运行 ESLint :

\* :密码组

```sh
npm run lint
```

```sh
pnpm lint
```

```sh
yarn lint
```

```sh
bun lint
```

\* :

或直接通过命令行运行 :

\* :密码组

```sh
npx eslint .
```

```sh
pnpx eslint .
```

```sh
yarn eslint .
```

```sh
bunx eslint .
```

\* :

## 另见

-   [合并文档](https://fedify.dev/)
-   [ESLint 文档](https://eslint.org/)
-   [示例项目](https://github.com/fedify-dev/fedify/tree/main/examples/lint)

## 常见问题

### @fedify/lint 是什么？

合并林化规则和插件

### 如何安装 @fedify/lint？

在项目目录运行 npm install @fedify/lint，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@fedify/fedify（^2\.1\.32）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @fedify/lint 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @fedify/lint 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @fedify/lint 可以商用吗？

@fedify/lint 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @fedify/lint 的下载量有多少？

根据 npm 官方下载统计，@fedify/lint 在 2026/10/15 – 2026/11/13 这 30 天内被下载 10,058 次，日均约 335 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @fedify/lint 还在维护吗？

最新版本 2\.1\.32 发布于 2026/11/17（今天）；至今共发布 571 个版本，其中过去 12 个月发布了 571 个；首次发布于 2025/12/31。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

