Skip to content

Commit 11e0332

Browse files
committed
feat(fmt): ignore Yarn releases by default
1 parent 0164d0a commit 11e0332

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎packages/rstack/src/fmt/ignore.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { loadNativeBinding } from '../native/index.ts';
88
import type { ResolvedFmtConfig } from './types.ts';
99

1010
/**
11-
* Common lock files that Prettier can format but `rs fmt` leaves to their generating tools.
11+
* Generated files and tool distributions that `rs fmt` leaves to their owning tools.
1212
*
1313
* Prettier already skips other generated lock files when it cannot infer a parser, so this list
1414
* contains only the additional defaults owned by `rs fmt`.
@@ -17,6 +17,7 @@ const defaultIgnorePatterns = [
1717
'package-lock.json',
1818
'pnpm-lock.yaml',
1919
'skills-lock.json',
20+
'**/.yarn/releases/',
2021
];
2122

2223
type IgnorePredicate = (filePath: string, isDirectory?: boolean) => boolean;

‎packages/rstack/tests/fmt/discovery.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,28 @@ test('excludes .rstack from discovery', async () => {
124124
});
125125
});
126126

127+
test('ignores Yarn releases by default and allows re-including their directories', async () => {
128+
await withTempProject(async (rootPath) => {
129+
const releases = [
130+
writeProjectFile(rootPath, '.yarn/releases/yarn.cjs'),
131+
writeProjectFile(rootPath, 'packages/app/.yarn/releases/yarn.cjs'),
132+
];
133+
const keepPath = writeProjectFile(rootPath, '.yarn/versions/version.yml');
134+
135+
for (const patterns of [undefined, ['**/*'], [...releases, keepPath]]) {
136+
const files = await discover(rootPath, patterns);
137+
expect(files.map((file) => file.path)).toEqual([keepPath]);
138+
}
139+
140+
const files = await discover(rootPath, undefined, {
141+
ignorePatterns: ['!**/.yarn/releases/'],
142+
});
143+
expect(files.map((file) => file.path).sort()).toEqual(
144+
[...releases, keepPath].sort(),
145+
);
146+
});
147+
});
148+
127149
const customCacheCases: { config?: FmtConfig; name: string }[] = [
128150
{ name: 'without configured ignore patterns' },
129151
{

‎website/docs/en/guide/formatting.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ define.fmt({
103103

104104
Patterns follow Gitignore syntax and are resolved relative to the directory containing the Rstack configuration file. Because they are applied after the files are selected, they also exclude files passed explicitly on the command line.
105105

106+
By default, `rs fmt` ignores `.yarn/releases/` directories at any depth, which contain Yarn CLI distributions. To format these files, add `'!**/.yarn/releases/'` to `ignorePatterns` to re-include their directories.
107+
106108
### Lock files
107109

108110
By default, `rs fmt` ignores common lock files, including `package-lock.json`, `pnpm-lock.yaml`, and `skills-lock.json`.
@@ -122,7 +124,7 @@ define.fmt({
122124
`rs fmt` uses the following three steps to decide which paths to format:
123125

124126
1. **Process command-line arguments and `.gitignore`**: It first processes the files, directories, and glob patterns passed on the command line. A glob that starts with `!` excludes matching paths. Directory and glob scans follow `.gitignore`, while files passed directly do not. Paths excluded in this step cannot be re-included later.
125-
2. **Apply default ignore rules and `ignorePatterns`**: By default, the command ignores [lock files](#lock-files), then applies `ignorePatterns`. These rules are evaluated in order, with later rules taking precedence. For example, `!pnpm-lock.yaml` re-includes the otherwise ignored file.
127+
2. **Apply default ignore rules and `ignorePatterns`**: By default, the command ignores [lock files](#lock-files) and `.yarn/releases/` directories, then applies `ignorePatterns`. These rules are evaluated in order, with later rules taking precedence. For example, `!pnpm-lock.yaml` re-includes the otherwise ignored file.
126128
3. **Apply files specified with [`--ignore-path`](./cli/fmt#--ignore-path-path)**: Each ignore file is evaluated separately, and later rules take precedence within that file. Exclusions from different files and `ignorePatterns` are combined: if any source ignores a path, that path remains excluded, even if another source re-includes it.
127129

128130
> Even when a file is passed directly on the command line, the default ignore rules, `ignorePatterns`, and rules from `--ignore-path` still apply. The same is true for paths specified with [`--stdin-filepath`](./cli/fmt#--stdin-filepath-path) and for documents formatted through [`--lsp`](./cli/fmt#--lsp).

‎website/docs/zh/guide/formatting.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ define.fmt({
103103

104104
这些模式遵循 Gitignore 语法,并且基于 Rstack 配置文件所在的目录解析。由于规则会在确定格式化范围后生效,因此也会排除命令行中显式传入的文件。
105105

106+
`rs fmt` 默认忽略任意层级的 `.yarn/releases/` 目录,其中存放的是 Yarn CLI 发布产物。如果需要格式化这些文件,可以在 `ignorePatterns` 中添加 `'!**/.yarn/releases/'`,重新包含这些目录。
107+
106108
### Lock 文件 \{#lock-files}
107109

108110
`rs fmt` 默认忽略常见的 lock 文件,包括 `package-lock.json`、`pnpm-lock.yaml` 和 `skills-lock.json`。
@@ -122,7 +124,7 @@ define.fmt({
122124
`rs fmt` 会通过以下三个步骤,决定需要格式化哪些路径:
123125

124126
1. **处理命令行参数和 `.gitignore`**:首先处理命令行中指定的文件、目录和 glob 模式。以 `!` 开头的 glob 模式用于排除路径。扫描目录或 glob 模式时会遵循 `.gitignore`,直接指定的文件则不会。在这一步被排除的路径无法被后续规则重新包含。
125-
2. **应用默认忽略规则和 `ignorePatterns`**:默认忽略 [lock 文件](#lock-files),随后应用 `ignorePatterns`。这些规则按顺序匹配,后面的规则优先。例如,`!pnpm-lock.yaml` 可以重新包含默认忽略的文件。
127+
2. **应用默认忽略规则和 `ignorePatterns`**:默认忽略 [lock 文件](#lock-files) 和 `.yarn/releases/` 目录,随后应用 `ignorePatterns`。这些规则按顺序匹配,后面的规则优先。例如,`!pnpm-lock.yaml` 可以重新包含默认忽略的文件。
126128
3. **应用 [`--ignore-path`](./cli/fmt#--ignore-path-path) 指定的文件**:每个 ignore 文件单独匹配,同一文件中后面的规则优先。不同 ignore 文件与 `ignorePatterns` 的排除结果会叠加:只要任一来源忽略某个路径,该路径就会保持排除,即使其他来源尝试重新包含它。
127129

128130
> 即使命令行直接指定了某个文件,默认忽略规则、`ignorePatterns` 和 `--ignore-path` 中的规则仍然有效。通过 [`--stdin-filepath`](./cli/fmt#--stdin-filepath-path) 指定的路径,以及通过 [`--lsp`](./cli/fmt#--lsp) 格式化的文档也是如此。

0 commit comments

Comments
 (0)