Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions website/docs/en/guide/formatting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,45 @@ define.fmt({

## Cache

`rs fmt` uses a persistent cache by default for file-based `--write`, `--check`, and `--list-different` runs. Formatting results use file content and final formatting options, so changing either causes the file to be formatted again. Unsupported parser lookups normally use the file path and final options. For filenames without an extension, they also use file content because Prettier may infer a parser from the shebang. Installed Prettier plugins are identified by their package name, version, and entry point; local, linked, or unversioned plugins bypass the cache.
`rs fmt` caches results by default to speed up repeated runs on unchanged files. The cache is shared by `--write`, `--check`, and `--list-different`.

The default cache directory is `.rstack/cache/fmt` under the Rstack configuration root. When a command runs from a subdirectory, it continues to use the cache next to the resolved `rstack.config.*` file. Stdin formatting does not use this cache.
### Cache behavior

Use [`--cache-location <path>`](./cli/fmt#--cache-location-path) to store the cache in a different directory. Relative paths are resolved from the current working directory. Custom directories are excluded from file discovery but are not automatically ignored by Git.
Cached results are reused when the file content and formatting options are unchanged. The cache also accounts for Rstack and Prettier versions, as well as the package name, version, and entry point of installed Prettier plugins. Changes to any of these cause the file to be processed again.

Use [`--no-cache`](./cli/fmt#--no-cache) to run without reading, creating, or updating the cache:
The cache is stored in `.rstack/cache/fmt` under the Rstack configuration root. Running from a subdirectory uses the same cache as long as the command resolves to the same `rstack.config.*` file.

### CLI options

Use [`--no-cache`](./cli/fmt#--no-cache) to disable the cache for the current run. Existing cache files are left unchanged:

```bash
rs fmt --no-cache
```

You can safely delete `.rstack/cache` to clear cached results. Do not treat the entire `.rstack` directory as disposable because it may also contain user-maintained Git hook scripts.
Use [`--cache-location <path>`](./cli/fmt#--cache-location-path) to choose a different cache directory. Relative paths are resolved from the current working directory:

```bash
rs fmt --cache-location .cache/rs-fmt
```

The custom directory is excluded from formatting. Add it to `.gitignore` if you do not want to commit it.

### Cache exceptions

`rs fmt` bypasses the persistent cache in the following cases:

- Input comes from stdin or an editor buffer through `--lsp`.
- A file uses a local or linked Prettier plugin, or a plugin without package version information.
- A file uses `prettier-plugin-tailwindcss`. Its class sorting can depend on external stylesheets and configuration files that the cache does not track.

If you enable these plugins only for specific files through `overrides`, only those files bypass the cache. Other files can still use it.

### Clearing the cache

To clear the formatting cache, delete `.rstack/cache/fmt` or the directory specified by `--cache-location`. `rs fmt` recreates the cache as needed.

Keep the rest of `.rstack`: it may contain Git hook scripts maintained by your project.

## Prettier plugins

Expand Down
36 changes: 31 additions & 5 deletions website/docs/zh/guide/formatting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,45 @@ define.fmt({

## 缓存 \{#cache}

`rs fmt` 默认会在基于文件的 `--write`、`--check` 和 `--list-different` 调用中使用持久化缓存。格式化结果基于文件内容和最终格式化选项;任意一项发生变化时,文件都会重新格式化。不支持的 parser 查询结果通常基于文件路径和最终选项。对于没有扩展名的文件,还会基于文件内容,因为 Prettier 可能从 shebang 推断 parser。已安装的 Prettier 插件通过包名、版本和入口进行识别;本地插件、链接插件或缺少版本信息的插件会绕过缓存。
`rs fmt` 默认会缓存结果,加快对未修改文件的重复处理。`--write`、`--check` 和 `--list-different` 共用这份缓存。

默认缓存目录位于 Rstack 配置根目录下的 `.rstack/cache/fmt`。从子目录运行命令时,仍会使用解析到的 `rstack.config.*` 文件旁的缓存。stdin 格式化不会使用该缓存。
### 缓存行为 \{#cache-behavior}

使用 [`--cache-location <path>`](./cli/fmt#--cache-location-path) 可以将缓存保存到其他目录。相对路径基于当前工作目录解析。自定义目录会从文件发现中排除,但不会被 Git 自动忽略。
文件内容和格式化选项未变时,会复用缓存结果。缓存还会记录 Rstack 和 Prettier 的版本,以及已安装 Prettier 插件的包名、版本和入口。以上任意一项发生变化时,都会重新处理文件。

使用 [`--no-cache`](./cli/fmt#--no-cache) 可以在运行时跳过缓存读取、创建和更新:
缓存默认保存在 Rstack 配置根目录下的 `.rstack/cache/fmt`。从子目录运行命令时,只要解析到同一个 `rstack.config.*` 文件,就会使用同一份缓存。

### CLI 选项 \{#cli-options}

使用 [`--no-cache`](./cli/fmt#--no-cache) 可以在本次运行中禁用缓存,已有的缓存文件不会被修改:

```bash
rs fmt --no-cache
```

可以安全删除 `.rstack/cache` 来清理缓存结果。不要将整个 `.rstack` 目录视为可随意删除的内容,因为其中还可能包含用户维护的 Git hook 脚本。
使用 [`--cache-location <path>`](./cli/fmt#--cache-location-path) 可以指定其他缓存目录。相对路径基于当前工作目录解析:

```bash
rs fmt --cache-location .cache/rs-fmt
```

自定义缓存目录不会参与格式化。如果不希望将其提交到 Git,请将它添加到 `.gitignore`。

### 不使用缓存的场景 \{#cache-exceptions}

以下场景中,`rs fmt` 会跳过持久化缓存:

- 输入来自 stdin,或通过 `--lsp` 传入的编辑器缓冲区。
- 文件使用了本地或链接的 Prettier 插件,或插件缺少包版本信息。
- 文件使用了 `prettier-plugin-tailwindcss`。它的类名排序可能依赖外部样式表和配置文件,而缓存不会追踪这些依赖。

如果通过 `overrides` 仅为部分文件启用上述插件,只有这些文件会跳过缓存,其他文件仍可使用缓存。

### 清理缓存 \{#clearing-the-cache}

删除 `.rstack/cache/fmt` 或通过 `--cache-location` 指定的目录,即可清理格式化缓存。`rs fmt` 会在需要时重新生成缓存。

请保留 `.rstack` 中的其他内容,其中可能包含项目维护的 Git hook 脚本。

## Prettier 插件 \{#prettier-plugins}

Expand Down
Loading