---
title: "代码检查"
description: "使用 nimbus-docs lint 捕获编写质量问题——人类可读输出、智能体可用的 JSON 格式和自动修复。"
---

> Documentation Index
> Fetch the complete documentation index at: https://nimbus-docs.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 代码检查

文档站点的内容质量下降会损害产品本身。Nimbus 对待编写质量就像代码检查工具对待源码——一套你按需运行的规则。

<h2 id="two-layers">两层机制</h2>

构建前的**校验器**自动运行，仅在问题会导致站点无法正常工作时才阻止构建——配置结构、frontmatter schema、[MDX 组件](/writing/markdown-and-mdx)、重复路由。

**lint 引擎**是按需的编写质量层。规则有稳定的 ID，如 `nimbus/single-h1` 和 `nimbus/bare-url`。构建**永远不会**被 lint 发现所阻止——草稿仍会渲染，警告仍然突出但不会阻塞。

<h2 id="run-it">运行</h2>

```sh
npx lint
pnpm dlx lint
yarn dlx lint
bunx lint
```

标志——与 `lint` 组合使用：

| 标志 | 效果 |
|---|---|
| `--format=json` | 智能体可读的诊断信息 |
| `--rule=nimbus/single-h1` | 运行单条规则 |
| `--fix` | 就地应用自动修复 |
| `--quiet` | 仅显示错误 |

它遍历 `src/content/`，运行你启用的每条编写规则，当任何 `error` 级别的发现存在时以非零状态退出。

<h2 id="configure-severities">配置严重级别</h2>

严重级别覆盖在集成中配置。将规则映射为 `"error"`、`"warn"` 或 `"off"`：

```ts title="astro.config.ts"
nimbus(config, {
  rules: {
"nimbus/single-h1": "error",
"nimbus/bare-url": "warn",
  },
  collections: {
partials: { rules: { "nimbus/single-h1": "off" } },
  },
});
```

集合级 `rules` 与顶层集合进行浅合并。编写规则**默认关闭**——完全省略 `rules` 不会运行任何规则；你需要逐条规则启用。

<h2 id="in-file-disables">文件内禁用</h2>

使用 `nimbusDisableRules` frontmatter 或行内注释对单个文件禁用规则——无需配置。上面配置的严重级别会被物化到 `.nimbus/lint.json`，这样独立 CLI 读取到的配置与集成相同。

Source: https://nimbus-docs.cn/writing/linting/index.mdx
