# @ben\_12/eslint-plugin-dprint 中文文档

规范地址：https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/

版本：1\.30\.1
npm 元数据更新时间：2026-11-01T04:28:40.448Z
中文译文更新时间：2026-11-07T21:55:42.480Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40ben_12/eslint-plugin-dprint
原文对照：https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/?lang=original
项目主页：https://eslint-plugin-dprint.ben12.eu/
源码仓库：https://github.com/ben12/eslint-plugin-dprint

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

- 包体积（解压后）：251 kB，26 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.0\.0
- 运行依赖：4 个
- peer 依赖：eslint \>=7\.0\.0，@dprint/json ^0\.25\.2，@dprint/toml ^0\.9\.0，@dprint/markdown ^0\.28\.2，@dprint/dockerfile ^0\.7\.0，@dprint/typescript ^0\.96\.1，dprint-plugin-yaml ^0\.6\.0，dprint-plugin-malva ^0\.16\.0，dprint-plugin-markup ^0\.27\.6，dprint-plugin-graphql ^0\.2\.3
- 首次发布：2023-09-24T13:52:30.564Z
- 最新版本发布：2026-11-01T04:28:40.076Z
- 近 30 天下载量：29779（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：99（近 12 个月 32 个）

## 中文简介

用 Drprint 修正代码的 ESLint 插件

## 安装

```sh
npm install @ben_12/eslint-plugin-dprint
```

也可以使用：`pnpm add @ben_12/eslint-plugin-dprint`、`yarn add @ben_12/eslint-plugin-dprint`、`bun add @ben_12/eslint-plugin-dprint`

## README

# 埃斯林特- 插图- 德印

[![GitHub](https://img.shields.io/github/license/ben12/eslint-plugin-dprint)](https://github.com/ben12/eslint-plugin-dprint/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/@ben_12/eslint-plugin-dprint.svg)](https://www.npmjs.com/package/@ben_12/eslint-plugin-dprint) [![Downloads/month](https://img.shields.io/npm/dm/@ben_12/eslint-plugin-dprint.svg)](http://www.npmtrends.com/@ben_12/eslint-plugin-dprint)  
[![node-current](https://img.shields.io/node/v/%40ben_12%2Feslint-plugin-dprint)](https://nodejs.org/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/eslint)](https://www.npmjs.com/package/eslint) [![install size](https://packagephobia.com/badge?p=@ben_12/eslint-plugin-dprint)](https://packagephobia.com/result?p=@ben_12/eslint-plugin-dprint)  
[![Build Status](https://github.com/ben12/eslint-plugin-dprint/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/ben12/eslint-plugin-dprint/actions) [![codecov](https://codecov.io/gh/ben12/eslint-plugin-dprint/branch/master/graph/badge.svg)](https://codecov.io/gh/ben12/eslint-plugin-dprint) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ben12_eslint-plugin-dprint&metric=alert_status&branch=master)](https://sonarcloud.io/summary/new_code?id=ben12_eslint-plugin-dprint) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=ben12_eslint-plugin-dprint&metric=code_smells&branch=master)](https://sonarcloud.io/dashboard?id=ben12_eslint-plugin-dprint) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=ben12_eslint-plugin-dprint&metric=vulnerabilities&branch=master)](https://sonarcloud.io/dashboard?id=ben12_eslint-plugin-dprint)

> 这是神秘画/斯林特-插图-德印的更新叉.

运行的插件 [打印](https://github.com/dprint/dprint) 以 ESLint 格式化代码.

## \* 安装

使用 [无](https://www.npmjs.com/) 或兼容的工具.

```sh
$ npm install -D eslint @ben_12/eslint-plugin-dprint
```

然后安装 [打印](https://github.com/dprint/dprint) 用于语言格式的插件.

```sh
$ npm install -D @dprint/dockerfile
$ npm install -D @dprint/json
$ npm install -D @dprint/markdown
$ npm install -D @dprint/toml
$ npm install -D @dprint/typescript
$ npm install -D dprint-plugin-malva
$ npm install -D dprint-plugin-markup
$ npm install -D dprint-plugin-yaml
$ npm install -D dprint-plugin-graphql
```

[![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/%40dprint%2Fdockerfile)](https://dprint.dev/plugins/dockerfile/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/%40dprint%2Fjson)](https://dprint.dev/plugins/json/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/%40dprint%2Fmarkdown)](https://dprint.dev/plugins/markdown/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/%40dprint%2Ftoml)](https://dprint.dev/plugins/toml/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/%40dprint%2Ftypescript)](https://dprint.dev/plugins/typescript/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/dprint-plugin-malva)](https://dprint.dev/plugins/malva/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/dprint-plugin-markup)](https://dprint.dev/plugins/markup_fmt/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/dprint-plugin-yaml)](https://dprint.dev/plugins/pretty_yaml/) [![npm peer dependency version (scoped)](https://img.shields.io/npm/dependency-version/%40ben_12%2Feslint-plugin-dprint/peer/dprint-plugin-graphql)](https://dprint.dev/plugins/pretty_graphql/)

## 使用量

写你的 ESLint 配置 。 例如, 有打字码 :

```mjs
import { defineConfig } from "eslint/config";
import tsPlugin from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import dprint from "@ben_12/eslint-plugin-dprint";

module.exports = defineConfig([
  {
    files: ["**/*.ts", "**/*.js"],

    languageOptions: {
        parser: tsParser
    },

    plugins: {
        "@typescript-eslint": tsPlugin,
        "@ben_12/dprint": dprint,
    },

    rules: {
      ...tsPlugin.configs["eslint-recommended"].rules,
      ...tsPlugin.configs["recommended"].rules,
      ...tsPlugin.configs["strict"].rules,
      ...dprint.configs["typescript-recommended"].rules
      "@ben_12/dprint/typescript": [
        "error",
        {
          // Use dprint JSON configuration file (default: "dprint.json")
          // It may be created using `dprint init` command
          // See also https://dprint.dev/config/
          configFile: "dprint.json",
          config: {
            // The TypeScript configuration of dprint
            // See also https://dprint.dev/plugins/typescript/config/
          },
        },
      ],
    },
  },
]);
```

对于遗留的eslint(slintrc配置),

```js
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@ben_12/dprint/typescript-recommended",
  ],
  rules: {
    "@ben_12/dprint/typescript": [
      "error",
      {
        // Use dprint JSON configuration file (default: "dprint.json")
        // It may be created using `dprint init` command
        // See also https://dprint.dev/config/
        configFile: "dprint.json",
        config: {
          // The TypeScript configuration of dprint
          // See also https://dprint.dev/plugins/typescript/config/
        },
      },
    ],
  },
};
```

然后运行 ESLint 与 `--fix`来啊!

### 通过 `settings`

默认情况下, 插件会在模块加载时通过动态加载每个 dprint formatter `require()` 对应同位素包(`@dprint/typescript`, (中文(简体) ), `dprint-plugin-yaml`(中文(简体) ). 这对 大多数设置, 但它依赖于正在安装的可选对等依赖 _财务报告和审定财务报表_ 可通过 节点解相. 一些捆绑和捆绑的配置软件包(任何做静态模块图的软件包) 分析,例如:. [包装](https://github.com/lukas-bischof/packtory)只跟随真实 `import` 语句,因此 Dprint 插件永远不会在捆绑中结束 。 在这种情况下,插件日志 `Plugin not found: …` 对于每个被衬住的文件和规则 沉默地变成了一个不开放.

通过 ESLint 的预溶物可以避免这种情况 `settings`设置不是 序列化或 `structuredClone`d 由ESLint提供,因此可以携带运行时对象(模块,缓冲器, 预建的格式器)。 当以这种方式提供格式时, 插件直接使用并跳过 动态 `require()` 搜索(以及相关的"无法找到"警告).

每个格式条目的接受形状 :

-   对象为 `getPath(): string` (导出形状的是 `@dprint/typescript`, (中文(简体) ), `@dprint/json`, (中文(简体) ), `@dprint/markdown`, (中文(简体) ), `@dprint/toml`, (中文(简体) ), `@dprint/dockerfile`(中文(简体) )
-   对象为 `getBuffer(): Buffer | Uint8Array` (遗产形状,以前被一些 `@dprint/*` 软件包)
-   原产 `Buffer` 编号 : `Uint8Array` 编号 : `ArrayBuffer` 插件的原字节
-   预建 `Formatter` 返回时间 `@dprint/formatter`是因为 `createFromBuffer`

示例(平面配置) :

```mjs
import { defineConfig } from "eslint/config";
import dprint from "@ben_12/eslint-plugin-dprint";
import typescriptFormatter from "@dprint/typescript";

export default defineConfig([
  {
    files: ["**/*.ts"],
    plugins: { "@ben_12/dprint": dprint },
    settings: {
      "@ben_12/dprint": {
        formatters: {
          typescript: typescriptFormatter,
        },
      },
    },
    rules: {
      "@ben_12/dprint/typescript": ["error", { config: { /* dprint config */ } }],
    },
  },
]);
```

设置密钥是插件命名空间( N)`@ben_12/dprint`) (中文(简体) ). 内部 `formatters`,关键是 规则名称( e)`typescript`, (中文(简体) ), `json`, (中文(简体) ), `markdown`, (中文(简体) ), `toml`, (中文(简体) ), `dockerfile`, (中文(简体) ), `malva`, (中文(简体) ), `markup`, (中文(简体) ), `yaml`, (中文(简体) ), `graphql`) (中文(简体) ).

#### g-平面插件( r)`yaml`, (中文(简体) ), `malva`, (中文(简体) ), `markup`, (中文(简体) ), `graphql`(中文(简体) )

这个 `@dprint/*` 软件包可以直接被导入和传递,如上文的例子. G型飞机包(`dprint-plugin-yaml`, (中文(简体) ), `dprint-plugin-malva`, (中文(简体) ), `dprint-plugin-markup`, (中文(简体) ), `dprint-plugin-graphql`(没有JS入境点,只有船) `plugin.wasm`,所以打电话者必须 解析并读取原文件并传递结果 `createFromBuffer` (或截至 原产 `BufferSource`) (中文(简体) ). 示例 `dprint-plugin-graphql`数字 :

```mjs
import { defineConfig } from "eslint/config";
import dprint from "@ben_12/eslint-plugin-dprint";
import { createFromBuffer } from "@dprint/formatter";
import fs from "node:fs";

const graphqlFormatter = createFromBuffer(
  fs.readFileSync(new URL(import.meta.resolve("dprint-plugin-graphql/plugin.wasm"))),
);

export default defineConfig([
  {
    files: ["**/*.graphql"],
    plugins: { "@ben_12/dprint": dprint },
    settings: {
      "@ben_12/dprint": {
        formatters: { graphql: graphqlFormatter },
      },
    },
    rules: {
      "@ben_12/dprint/graphql": ["error", { config: { /* dprint config */ } }],
    },
  },
]);
```

相同的模式( 匹配包和规则名) 适用于 `yaml`, (中文(简体) ), `malva`,以及 `markup`。 。 。 .

对于未被分解的 Eslint 文件,如 标记下或粘贴文件, 您可以使用 [@ben 12/slint-simple-parser (英语)](https://www.npmjs.com/package/@ben_12/eslint-simple-parser) 作为解析器.

```mjs
import { defineConfig } from "eslint/config";
import dprint from "@ben_12/eslint-plugin-dprint";
import simpleParser from "@ben_12/eslint-simple-parser";

export default defineConfig([
  {
    files: ["**/*.md"],
    plugins: {
        "@ben_12/dprint": dprint,
    },
    languageOptions: {
        parser: simpleParser,
    },
    rules: dprint.configs["markdown-recommended"].rules,
  },
]);
```

### 现行规则

| 规则 | 说明 |
| :-- | :-- |
| [@ ben 12/dprint/ dockerfile (中文(简体) )](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-dockerfile.md) | 格式嵌入文件代码 [@ dprint/ docker file (缩写)](https://github.com/dprint/dprint-plugin-dockerfile)。 。 。 . |
| [@ben 12/dprint/json (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-json.md) | 格式化 json 代码 [@dprint/json (英语)](https://github.com/dprint/dprint-plugin-json)。 。 。 . |
| [@ ben 12/dprint/ markdown (中文(简体) )](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-markdown.md) | 格式化下标码 [@ dprint/ markdown (帮助)](https://github.com/dprint/dprint-plugin-markdown)。 。 。 . |
| [@ben 12/dprint/toml (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-toml.md) | 格式化 Toml 代码 [@dprint/toml (英语)](https://github.com/dprint/dprint-plugin-toml)。 。 。 . |
| [@ ben 12/dprint/typescript](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-typescript.md) | 格式字迹代码 [@dprint/typescript](https://github.com/dprint/dprint-plugin-typescript)。 。 。 . |
| [@ben 12/dprint/malva (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-malva.md) | 格式 cs/ scs/ 少/ ass 代码 [马尔瓦](https://github.com/g-plane/malva)。 。 。 . |
| [@ ben 12/dprint/ 标记](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-markup.md) | 格式 HTML/Vue/Svelte/... 代码 [标记( fmt)](https://github.com/g-plane/markup_fmt)。 。 。 . |
| [@ben 12/dprint/yaml (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-yaml.md) | 格式化 YAML 代码 [漂亮小区](https://github.com/g-plane/pretty_yaml)。 。 。 . |
| [@ben 12/dprint/graphql (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-graphql.md) | 格式图形QL 代码 [漂亮图形ql](https://github.com/g-plane/pretty_graphql)。 。 。 . |

### 可用的配置

| 配置 | 说明 |
| :-- | :-- |
| [插件 : @ ben 12/ dprint/ disable-typescript- 冲突规则](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/disable-typescript-conflict-rules.ts) | 与规则相冲突的地方禁用规则 [@ ben 12/dprint/typescript](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-typescript.md) 规则. |
| [插件 : @ ben 12/ dprint/ dockerfile- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L3) | 启用 [@ ben 12/dprint/ dockerfile (中文(简体) )](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-dockerfile.md) 规则. |
| [插件 : @ ben 12/dprint/json- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L10) | 启用 [@ben 12/dprint/json (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-json.md) 规则. |
| [插件 : @ ben 12/dprint/ markdown- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L17) | 启用 [@ ben 12/dprint/ markdown (中文(简体) )](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-markdown.md) 规则. |
| [插件 : @ ben 12/dprint/toml- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L24) | 启用 [@ben 12/dprint/toml (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-toml.md) 规则. |
| [插件 : @ ben 12/dprint/typescript- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L31) | 启用 [@ ben 12/dprint/typescript](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-typescript.md) 规则与规则 [插件 : @ ben 12/ dprint/ disable-typescript- 冲突规则](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/disable-typescript-conflict-rules.ts) 预设. |
| [插件 : @ ben 12/dprint/ malva- 推荐](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L39) | 启用 [@ben 12/dprint/malva (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-malva.md) 规则. |
| [插件 : @ ben 12/ dprint/ markup- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L46) | 启用 [@ ben 12/dprint/ 标记](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-markup.md) 规则. |
| [插件 : @ ben 12/dprint/yaml- 建议](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L53) | 启用 [@ben 12/dprint/yaml (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-yaml.md) 规则. |
| [插件 : @ ben 12/dprint/graphql- 推荐](https://github.com/ben12/eslint-plugin-dprint/blob/master/lib/configs/recommended.ts#L60) | 启用 [@ben 12/dprint/graphql (英语)](https://npmcn.com/package/%40ben_12/eslint-plugin-dprint/docs/rules/dprint-graphql.md) 规则. |

-   将 \[plugin:@ben 12/dprint/ recommend\] 或 \[plugin:@ben 12/dprint/disabable-conflict-rules\] 配置到您最后的 `extends` 列表,以确保来自其他基础配置的无效冲突规则.

## QQ 更改日志

见 [GitHub 发布](https://github.com/ben12/eslint-plugin-dprint/releases)。 。 。 .

## 捐款

欢迎献礼!

请使用 GitHub 的问题/PR .

### 开发工具

-   `npm test` 进行测试 它生成代码覆盖到 `coverage` 目录.
-   `npm run watch` 编辑文件时进行测试 .
-   `npm version <patch|minor|major>` ...跳出一个新的版本.

## 常见问题

### @ben\_12/eslint-plugin-dprint 是什么？

用 Drprint 修正代码的 ESLint 插件

### 如何安装 @ben\_12/eslint-plugin-dprint？

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

### @ben\_12/eslint-plugin-dprint 支持 TypeScript 吗？

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

### @ben\_12/eslint-plugin-dprint 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @ben\_12/eslint-plugin-dprint 需要什么版本的 Node\.js？

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

### @ben\_12/eslint-plugin-dprint 可以商用吗？

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

### @ben\_12/eslint-plugin-dprint 的下载量有多少？

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

### @ben\_12/eslint-plugin-dprint 还在维护吗？

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

