re0-style
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFix a named change or set of files to match the conventions its repository already keeps, changing style and nothing else.
修复指定变更或一组文件,使其符合仓库自身遵循的约定,仅更改风格,不更改其他内容。
Goal
目标
Code written in one session drifts from the code around it: another quote style, another naming case, imports in another order, errors raised the way the last project raised them. A reader then has to work out whether each difference means something. makes the code in scope read like its neighbours. It takes every convention from the repository itself, first from the formatter and linter the project configures and then from the pattern neighbouring files follow for what no tool decides, and applies the fixes in place with behavior unchanged. Where the repository itself is split between two conventions, it asks rather than picks. The result is a style-only diff and a report of each change by file and rule.
re0-style在一次会话中编写的代码往往会偏离周围代码:quote style 不同、命名大小写不同、import 顺序不同,错误抛出方式也与项目最近采用的方式不同。读者随后不得不判断每处差异是否具有实际含义。 让范围内的代码读起来与相邻代码保持一致。它从仓库自身获取每一项约定,先取自项目配置的 formatter 和 linter,再取自相邻文件对工具无法决定事项所遵循的模式,并就地应用修复,同时保持行为不变。如果仓库自身在两种约定之间存在分歧,它会询问,而不是自行选择。最终结果应是一个仅包含风格变更的 diff,并按文件和规则报告每项更改。
re0-styleWorkflow
工作流程
- Pin the scope. Name the change (the working diff, or the diff against the base the user names) or the file list the user gave. For a change, the unit is the changed lines: a file the change does not touch is out of scope, and so are the untouched lines of a file it does. Run the project's tests once now, by the command its manifest, task runner or CI workflow names, and record the result, so a failure that was already there is not blamed on the pass.
- Drop what is not the repository's own. From this skill's folder, run on the files in scope. It lists, per file,
node scripts/scope.mjs <files...> [--json]andlinguist-generatedattributes, a generated-file header in the first lines, formatter and linter off markers with their line numbers, and the style config files that apply from the file's folder up to the repository root; exit 0 means no file is flagged, 3 that one or more are, 2 a usage error or an unreadable input. A hit is a lead to read, not a verdict: drop a file that is truly generated or vendored, and leave every region under an off marker as it is.linguist-vendored - Read what the tools decide. From the configs step 2 listed and the project's manifests, scripts, lockfile, CI workflows and pre-commit config, name the formatter and linter the repository runs and the options it sets. Resolve each through the project's own resolution (,
npm exec,bun run,./node_modules/.bin/,uv run, the pinned toolchain), print the version about to run (the tool'spoetry runthrough that same resolution), and compare it with the one the lockfile or manifest declares. A mismatch, or a tool reachable only as a global binary or a scratch install, stops tool fixes for that tool and goes in the report.--version - Read what no tool decides. For each question the scope raises that no configured tool settles (identifier case by kind, import grouping and order, file and folder layout, export style, how errors are raised and worded), sample the neighbouring files, nearest first: the same folder, then files of the same kind elsewhere in the repository. Count each pattern. A pattern is the convention when nearly every sampled instance follows it and the exceptions look like drift: scattered single files, often recent. When the other pattern owns a whole folder or module, or recurs across files you cannot call drift, the repository keeps two conventions there; record both counts and where each lives. When you cannot tell, treat it as two conventions and ask. A folder's own consistent convention beats the one the rest of the repository keeps.
- Apply the tool fixes. Run the formatter, then the linter's fix mode, on the files in scope only, and only the fixes the tool marks safe. For a change, first run the formatter's check on the base version of each file (read it with into a scratch copy): if the base was already clean, formatting the whole file touches only the change; if it was not, keep only the edits inside the changed lines (the tool's range option, or the hunks that overlap them) and report the earlier drift as left. When the user asked to set up a formatter or linter that the repository lacks, configure the one its ecosystem and manifests already point to, set each option to what step 4 found the code doing, and run it on the scope alone; whatever it would still change outside the scope is reported, never applied.
git show <base>:<path> - Apply the hand fixes. Fix the remaining lint findings and each deviation from a step 4 convention inside the scope, preserving behavior. Rename a local or private identifier together with every reference to it. A rename that crosses a public API (an export another module or package imports, a CLI flag, a config key, a route, a serialized field) is proposed in the report with every caller it would touch and applied only when the user confirms it. A lint finding that only a logic change can satisfy is left and reported.
- Surface the splits. For each place where step 4 found two conventions, leave the code as it is and write a question into the report: the two patterns, the count of each, where each lives, and the lines in scope that wait on the answer. The run does not stop for it; a later pass applies the answer.
- Verify and report as below.
- 锁定范围。 指定变更(working diff,或相对于用户指定 base 的 diff)或用户给出的文件列表。对于变更,处理单位是 changed lines:变更未触及的文件不在范围内,文件内未被变更触及的行也不在范围内。现在按照 manifest、task runner 或 CI workflow 指定的命令运行一次项目测试并记录结果,以免将原本就存在的失败归咎于本次处理。
- 剔除不属于仓库自身维护的内容。 从本 skill 的目录运行 ,检查范围内的文件。它会按文件列出
node scripts/scope.mjs <files...> [--json]和linguist-generated属性、前几行中的 generated-file header、formatter 和 linter 的 off marker 及其行号,以及从文件所在 folder 向上至仓库根目录适用的 style config 文件;退出码 0 表示没有文件被标记,3 表示至少有一个文件被标记,2 表示用法错误或输入无法读取。命中结果只是需要进一步检查的线索,并非最终结论:确实属于 generated 或 vendored 的文件应被剔除,所有位于 off marker 下的区域都应保持原样。linguist-vendored - 读取由工具决定的内容。 根据第 2 步列出的 config,以及项目的 manifests、scripts、lockfile、CI workflows 和 pre-commit config,确定仓库运行的 formatter 和 linter 及其设置的 options。通过项目自身的工具解析方式运行每个工具(、
npm exec、bun run、./node_modules/.bin/、uv run或固定工具链),打印即将运行的版本(通过同一解析方式执行该工具的poetry run),并将其与 lockfile 或 manifest 中声明的版本比较。如果版本不匹配,或者工具只能通过 global binary 或临时安装获得,则停止使用该工具进行自动修复,并将情况写入报告。--version - 读取工具无法决定的内容。 对于范围内提出、且任何已配置工具都无法确定的每个问题(按类型划分的 identifier 大小写、import 分组与顺序、文件和 folder 布局、export style、错误的抛出与措辞方式),按由近到远的顺序采样相邻文件:先查看同一 folder,再查看仓库内其他位置的同类文件。统计每种模式。当几乎所有采样实例都遵循某种模式,且例外看起来只是 drift 时,该模式就是约定;这些例外通常是零散的单文件,并且往往较新。当另一种模式占据整个 folder 或 module,或者出现在多个无法视为 drift 的文件中时,仓库就在该处保持两种约定;记录两者的数量以及各自所在的位置。无法判断时,将其视为两种约定并询问。某个 folder 自身一致的约定优先于仓库其余部分遵循的约定。
- 应用工具修复。 仅对范围内的文件运行 formatter,然后运行 linter 的 fix mode,并且只应用工具标记为安全的修复。对于变更,先对每个文件的 base 版本运行 formatter 的 check(使用 将其读取到 scratch copy 中):如果 base 已经 clean,对整个文件进行格式化只会触及变更;如果 base 并非 clean,则仅保留 changed lines 内的编辑(使用工具的 range option,或仅保留与 changed lines 重叠的 hunks),并将原有 drift 作为未处理项写入报告。当用户要求配置仓库尚未使用的 formatter 或 linter 时,配置项目生态和 manifests 已经指向的对应工具,将每个 option 设置为第 4 步发现的代码实际采用的风格,然后仅对范围运行该工具;它仍会更改范围外内容的部分只写入报告,绝不应用。
git show <base>:<path> - 应用手动修复。 在范围内修复剩余 lint findings,以及所有偏离第 4 步约定的内容,同时保持行为不变。重命名 local 或 private identifier 时,必须一并更新对它的所有引用。跨越 public API 的重命名(另一个 module 或 package 会 import 的 export、CLI flag、config key、route、serialized field)应在报告中提出,并列出它将影响的所有 caller,只有在用户确认后才能应用。只能通过逻辑变更才能解决的 lint finding 应保留并写入报告。
- 呈现约定分歧。 对于第 4 步发现两种约定each place,保持代码原样,并在报告中写入一个问题:列出两种模式、各自数量、所在位置,以及范围内等待答案的 lines。流程不会因此停止;后续 pass 会应用用户给出的答案。
- 按如下方式验证并报告。
Rules
规则
- Every convention comes from the repository: a config it keeps (including a published style guide that config explicitly extends) or a pattern its own files follow consistently. Never an outside style guide, a language's popular default, or taste the repository does not already follow.
- Stay inside the scope the user named or that a pipeline they invoked passes on. Never restyle an untouched file or untouched lines, and never widen the scope; drift found outside it is reported, not fixed.
- Run every tool through the project's own resolution with its version printed and compared; a global binary or a scratch install is a different toolchain and its verdict is not the project's.
- Style only. No change to a value, condition, call, control flow or public name. Leave the order of imports that run code when loaded (polyfills, registrations, stylesheets) as found, since moving them changes behavior.
- Never pick between two competing conventions silently; the split goes to the user as a question with counts.
- Respect what the repository protects: generated and vendored files and every region under a formatter or linter off marker stay untouched.
- Hand off what other passes own: punctuation in prose and comments (em and en dashes to , Korean middle dots to
dedash), and prose bloat or code that carries nothing (dead code, comments that restate the code) todedot. Name each handoff in the report rather than doing it.debloat - A pass that finds nothing off-convention changes nothing.
- Edit safely: assert each target exists before changing it and report a MISS rather than a silent no-op; read and write files as UTF-8 without changing their line endings; replace per occurrence rather than by blanket sweep; script a large mechanical change.
- 每项约定都必须来自仓库自身:要么来自仓库保留的 config(包括 config 明确扩展的 published style guide),要么来自仓库自身文件持续遵循的模式。绝不能采用外部 style guide、某种语言的流行默认值,或仓库并未遵循的个人偏好。
- 严格保持在用户指定或用户调用的 pipeline 传入的范围内。绝不对未触及的文件或未触及的行进行风格调整,也绝不能扩大范围;在范围外发现的 drift 只报告,不修复。
- 每个工具都必须通过项目自身的解析方式运行,打印并比较其版本;global binary 或临时安装属于不同的工具链,其判断结果不代表项目的结果。
- 仅调整风格。不得更改 value、condition、call、control flow 或 public name。加载时就会运行代码的 imports(polyfills、registrations、stylesheets)应保持原有顺序,因为移动它们会改变行为。
- 绝不能默默选择两种相互竞争的约定之一;遇到分歧时,应将其作为带有数量的询问交给用户。
- 尊重仓库明确保护的内容:generated 和 vendored 文件,以及 formatter 或 linter off marker 下的所有区域都不得修改。
- 将其他 pass 负责处理的内容进行交接:散文和注释中的标点(em dash 和 en dash 交给 ,韩文中点交给
dedash),以及冗长散文或没有实际作用的代码(dead code、重复描述代码的注释)交给dedot。在报告中注明每项 handoff,而不是自行处理。debloat - 如果一次 pass 没有发现任何偏离约定的内容,则不进行任何更改。
- 安全编辑:修改前断言每个目标都存在;如果不存在,应报告 MISS,而不是静默跳过;以 UTF-8 读取和写入文件,且不改变行尾格式;逐处替换,而不是进行无差别批量替换;大型机械修改应编写脚本完成。
Verification
验证
Before finishing, confirm:
- The formatter and linter, run through the project's own resolution, report the touched files clean, or every finding they still report is listed as left with its reason.
- The project's tests give the same result as the run in step 1.
- Every file in the diff is in scope, and every hunk maps to a reported change: read the diff hunk by hunk against the style-only rule.
- Every split carries the count of each pattern, and every public rename was proposed rather than applied unless the user confirmed it.
Report each change by file and rule (the tool's rule id, or the convention with the counts that made it one), then what was left: the splits as questions with counts, findings only a logic change could satisfy, proposed public renames, drift outside the scope, tool version mismatches, and each handoff.
结束前确认:
- formatter 和 linter 通过项目自身的解析方式运行后,报告为已触及文件 clean;或者它们仍然报告的每项 finding 都已列为未处理项并附有原因。
- 项目测试的结果与第 1 步记录的结果相同。
- diff 中的每个文件都在范围内,每个 hunk 都对应一项已报告的更改:逐个 hunk 对照仅修改风格的规则进行检查。
- 每处约定分歧都附有两种模式各自的计数,每项 public rename 在用户确认前都只是提议,并未实际应用。
按文件和规则报告每项更改(工具的 rule id,或构成该约定的模式及其计数),然后报告未处理事项:作为带有数量问题的约定分歧、只能通过逻辑变更解决的 findings、提议的 public renames、范围外的 drift、工具版本不匹配,以及每项 handoff。