# @bfra\.me/eslint-config 中文文档

规范地址：https://npmcn.com/package/%40bfra.me/eslint-config/

版本：0\.54\.0
npm 元数据更新时间：2026-09-26T09:01:33.654Z
中文译文更新时间：2026-11-08T00:51:46.568Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bfra.me/eslint-config
原文对照：https://npmcn.com/package/%40bfra.me/eslint-config/?lang=original
项目主页：https://github.com/bfra-me/works/tree/main/packages/eslint-config#readme
源码仓库：https://github.com/bfra-me/works

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

- 包体积（解压后）：1.9 MB，50 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：^22\.22\.2 \|\| \>=24\.15\.0
- 运行依赖：25 个
- peer 依赖：eslint ^10\.4\.0，astro-eslint-parser ^1\.2\.2 \|\| ^3\.0\.0，eslint-plugin-astro ^1\.3\.1 \|\| ^3\.0\.0，@vitest/eslint-plugin ^1\.1\.21，eslint-config-prettier ^10\.1\.8，eslint-plugin-jsx-a11y \>=6\.10\.2，eslint-plugin-prettier ^5\.5\.4，@next/eslint-plugin-next \>=15\.5\.3，eslint-plugin-react-hooks ^7\.0\.0，@eslint-react/eslint-plugin ^4\.2\.3 \|\| ^5\.0\.0，eslint-plugin-react-refresh ^0\.4\.20 \|\| ^0\.5\.0
- 首次发布：2024-10-01T09:37:08.911Z
- 最新版本发布：2026-09-26T09:01:33.459Z
- 近 30 天下载量：16907（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：128（近 12 个月 39 个）

## 中文简介

Bfra.me 共享的 ESLint 配置

## 安装

```sh
npm install @bfra.me/eslint-config
```

也可以使用：`pnpm add @bfra.me/eslint-config`、`yarn add @bfra.me/eslint-config`、`bun add @bfra.me/eslint-config`

## README

# @bfra.me/slint-config (英语)

> Bfra.me的共享ESLint配置.

## 安装

### 国家预防机制

```sh
npm install --save-dev @bfra.me/eslint-config eslint
```

### 菲律宾

```sh
pnpm add --save-dev @bfra.me/eslint-config eslint
```

### 雅伦

```sh
yarn add --dev @bfra.me/eslint-config eslint
```

## 使用量

添加或更新您的 `eslint.config.js` 包含以下内容的文档 :

```js
import preset from "@bfra.me/eslint-config"

export default preset()
```

## 标记下方支持

输入您的 Markdown 文件, 支持 CommunityMark 和 GitHub Flavored Markdown (GFM) 。 在 YAML 格式、 TOML 格式或 JSON 格式中解析前置事项, 在文档中可选地插入代码块 。 盖在官上 [@ slint/ 标记下](https://github.com/eslint/markdown) 插件 .

### 快速启动

```js
import {defineConfig} from "@bfra.me/eslint-config"

// Enable with defaults (GFM + YAML frontmatter)
export default defineConfig({
  markdown: true
})
```

### 语言模式: CommunityMark vs GFM

选择适合您使用的 Markdown 解析模式 :

#### 通用马克( 标准)

在最大可移植性和严格遵守标准规格时使用CommonMark:

```js
export default defineConfig({
  markdown: {
    language: 'commonmark'
  }
})
```

**最佳服务:**

-   README 文件
-   便携式文件
-   跨平台内容
-   严格Markdown合规

#### GitHub 平地标记( GFM)

GFM 用于 GitHub 和文档站点常用的增强特性 :

```js
export default defineConfig({
  markdown: {
    language: 'gfm'
  }
})
```

**添加支持 :**

-   表格
-   任务列表( E)`- [ ] Todo item`(中文(简体) )
-   切换( R)`~~deleted text~~`(中文(简体) )
-   自动链接( 自动 URL 链接)

**最佳服务:**

-   文件网站
-   GitHub 读取ME 文件
-   博客文章
-   维基页面

**GFM 是默认模式** 当您启用 Markdown 支持时.

### 前题解析

大多数静态站点生成器(Astro,Next.js,Jekyll)使用前置物质存储元数据到Markdown文件的顶端. 您可以配置哪个格式来解析, 或者完全禁用它 .

#### YAML 前题( 建议)

```js
export default defineConfig({
  markdown: {
    frontmatter: 'yaml'
  }
})
```

带有 YAML 前题的 Markdown 文件 :

```markdown
---
title: Getting Started
date: 2025-11-20
tags: [tutorial, documentation]
---

# Getting Started

Your content here...
```

**最佳服务:**

-   文献网站(Astro、Docuraurus、VitePress)
-   博客文章
-   大部分固定地点发电机

#### TOML 前题

```js
export default defineConfig({
  markdown: {
    frontmatter: 'toml'
  }
})
```

带有 TOML 前题的 Markdown 文件 :

```markdown
+++
title = "Getting Started"
date = 2025-11-20
tags = ["tutorial", "documentation"]
+++

# Getting Started

Your content here...
```

**最佳服务:**

-   雨果遗址
-   配置重的前题

#### JSON 前题

```js
export default defineConfig({
  markdown: {
    frontmatter: 'json'
  }
})
```

带有 JSON 前题的 Markdown 文件 :

```markdown
;;;
{
  "title": "Getting Started",
  "date": "2025-11-20",
  "tags": ["tutorial", "documentation"]
}
;;;

# Getting Started

Your content here...
```

#### 禁用前题

对于简单的没有元数据的Markdown文件:

```js
export default defineConfig({
  markdown: {
    frontmatter: false
  }
})
```

**YAML 是默认的前题格式** 当您启用 Markdown 支持时.

### 代码块处理

#### 启用代码块林入

```js
export default defineConfig({
  markdown: {
    codeBlocks: {
      typescript: true,
      javascript: true,
      jsx: true,
      json: true,
      yaml: true
    }
  }
})
```

启用了代码块处理( 默认) , 将栅栏化的代码块取出并作为单独的虚拟文件 :

````markdown
# Example

```typescript
// This TypeScript code will be linted with TypeScript rules
interface User {
  name: string
  age: number
}

const user: User = {
  name: "John",
  age: 30
}
```
````

#### 文件名 Meta 支持

使用文件名注释来更好地报告错误 :

````markdown
```typescript filename="src/user.ts"
export interface User {
  name: string
  age: number
}
```
````

门窗将把这个代码块当作它在里面 `src/user.ts` 用于错误消息和规则上下文.

#### 代码块中支持的语言

支持下列语言:

-   **类型脚本** (单位:千美元)`.ts`, (中文(简体) ), `.tsx`) - 完整类型脚本- ESLint 支持
-   **Java 脚本** (单位:千美元)`.js`, (中文(简体) ), `.jsx`) - ES模块,async/await,现代语法
-   **联合来文X/TSX** - 反应组件并有正放
-   **贾森** - JSON/JSON5语法验证
-   **也门** - YAML 语法验证

### 在 Markdown 中禁用指令

使用 HTML 注释来禁用 Markdown 文件内的 ESLint 规则 :

```markdown
<!-- eslint-disable markdown/no-html -->

<div>Custom HTML content</div>

<!-- eslint-enable markdown/no-html -->
```

### 配置示例

#### 文档站点( Astro, Docusaurus, VitePress) Name

```js
import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      typescript: true,
      javascript: true
    }
  }
})
```

#### 简单读取文件

```js
import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'commonmark',
    frontmatter: false,
    files: ['README.md', '**/README.md']
  }
})
```

#### 有代码示例的博客帖子

```js
import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      typescript: true,
      javascript: true,
      jsx: true
    },
    files: ['blog/**/*.md', 'posts/**/*.md']
  }
})
```

#### 自定义规则覆盖

```js
import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    rules: {
      // Allow HTML in Markdown
      'markdown/no-html': 'off',
      // Warn on missing code block languages
      'markdown/fenced-code-language': 'warn',
      // Enforce alt text for images
      'markdown/require-alt-text': 'error'
    }
  }
})
```

### 默认规则

这些规则被放出框外,以便抓住常见的马克倒置问题:

-   **`markdown/fenced-code-language`** - 需要在有栅栏的代码块上提供语言标识符
-   **`markdown/heading-increment`** - 实施适当的项目级递增
-   **`markdown/no-duplicate-definitions`** - 防止重复的链接/图像定义
-   **`markdown/no-empty-definitions`** - 防止空链接/图像定义
-   **`markdown/no-empty-images`** - 防止空图像替代文本
-   **`markdown/no-empty-links`** - 防止空链接文本
-   **`markdown/no-invalid-label-refs`** - 防止无效的引用样式链接
-   **`markdown/no-missing-label-refs`** - 防止缺少参考定义
-   **`markdown/no-missing-link-fragments`** - 验证标题碎片链接
-   **`markdown/no-multiple-h1`** - 每个文件执行单个h1标题
-   **`markdown/no-unused-definitions`** - 防止未使用的链接/图像定义
-   **`markdown/require-alt-text`** - 图像需要替代文本
-   **`markdown/table-column-count`** - 验证表格列的一致性

### 从简单配置中移入

简单的布尔形式仍然有效:

```js
// Simple form
export default defineConfig({
  markdown: true
})
```

这相当于:

```js
// Explicit defaults
export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      javascript: true,
      json: true,
      jsx: true,
      typescript: true,
      yaml: true
    }
  }
})
```

您需要扩展的窗体, 只要您想要自定义这些默认 .

### 解决问题

#### 代码块处理问题

遇到什么问题吗? 尝试这些修正 :

1.  **选择性启用语言** 在你的环境中工作:
    
    ```js
    export default defineConfig({
     markdown: {
       codeBlocks: {
         typescript: true,
         javascript: true,
         jsx: false,  // Disable if causing issues
         json: false,
         yaml: false
       }
     }
    })
    ```
    
2.  **检查插件冲突** - 一些ESLint插件需要完整SourceCode API,在虚拟代码块文件中不可用
    

#### 前题分析出错

前题分析不正确吗? 检查这些共同问题:

-   验证分隔符 : `---` 也门, `+++` 为TOML, `;;;` 给 JSON 的
-   用专用解析器验证您的前题语法
-   如果你不需要前题,请禁用: `frontmatter: false`

#### 业绩问题

林廷太久了吗? 这是如何加快速度:

-   目标特定目录 : `files: ['docs/**/*.md']`
    
-   使用 `ignores` 选项 :
    
    ```js
    export default defineConfig({
      ignores: ['docs/api/**/*.md', '**/CHANGELOG.md']
    })
    ```
    

## 许可证

[麻省理工学院](https://npmcn.com/package/LICENSE.md)

## 常见问题

### @bfra\.me/eslint-config 是什么？

Bfra\.me 共享的 ESLint 配置

### 如何安装 @bfra\.me/eslint-config？

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

### @bfra\.me/eslint-config 支持 TypeScript 吗？

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

### @bfra\.me/eslint-config 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @bfra\.me/eslint-config 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js ^22\.22\.2 \|\| \>=24\.15\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @bfra\.me/eslint-config 可以商用吗？

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

### @bfra\.me/eslint-config 的下载量有多少？

根据 npm 官方下载统计，@bfra\.me/eslint-config 在 2026/10/08 – 2026/11/06 这 30 天内被下载 16,907 次，日均约 564 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bfra\.me/eslint-config 还在维护吗？

最新版本 0\.54\.0 发布于 2026/09/26（1 个月前）；至今共发布 128 个版本，其中过去 12 个月发布了 39 个；首次发布于 2024/10/01。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

