editorconfig在atom中必须满足三个硬性条件才生效:正确识别项目根路径、.editorconfig严格置于add project folder所选根目录且命名无误、atom设置中tab type设为auto且soft tabs开启;状态栏无editorconfig字样即未加载,根本原因是未用add project folder打开目录。

EditorConfig 在 Atom 里不是“装了就生效”,而是必须满足三个硬性条件:项目根路径被正确识别、.editorconfig 文件位置和命名严格合规、Atom 自身设置不与之冲突。缺一不可。
为什么状态栏没出现 EditorConfig 字样
这是最直接的失效信号——说明插件压根没读到配置。根本原因不是插件没启用,而是 Atom 没把当前窗口当“项目”。
- 必须通过 File > Add Project Folder 打开整个目录;用 File > Open File 单独打开一个
.js文件,插件完全不启动 -
.editorconfig必须放在你用Add Project Folder选中的那个目录下,不能藏在/src或/packages子目录里 - 文件名必须是
.editorconfig(开头带点、无扩展名),.editorconfig.json或editorconfig都无效 - 插件启用状态要检查:进入
Settings > Packages,搜editorconfig,确认状态是Enabled(作者是sindresorhus)
缩进没按 indent_size 生效的常见卡点
很多人改了 indent_size = 2 却发现 Tab 还是插 4 个空格,其实是 Atom 的原生设置覆盖了 EditorConfig。
- 进入
Settings > Editor,把Tab Type改成auto(不是soft或hard) - 确保
Soft Tabs开关开启(对应indent_style = space);如果关了,它会强行插\t字符 - 运行命令面板(
Ctrl+Shift+P),输入EditorConfig: Show State,看输出里indent_size和indent_style是否显示具体值,而不是undefined -
tab_width在.editorconfig中是非法字段,必须用indent_size
和 prettier-atom 冲突时怎么分工
两者都动缩进、换行、尾空格,保存时格式会来回跳。关键不是禁用谁,而是让 editorconfig 守住编辑器层底线,prettier 专注结构重排。
- 在
prettier-atom设置中关闭这些选项:Tab Width、Insert Final Newline、Trim Trailing Whitespace、Ensure Single Quote - 把
trim_trailing_whitespace = true和insert_final_newline = true留在.editorconfig中——这是编辑器该兜底的行为 - HTML/Vue 文件缩进错乱?检查
.editorconfig是否漏写[*.html]或[*.vue]段,并显式声明indent_style和indent_size -
prettier-atom只认项目根目录下的.prettierrc(无后缀),不认.prettierrc.json或prettier.config.js
配置文件内容必须满足的最小规范
哪怕只写三行,也得过这几道硬门槛,否则插件静默失败。
- 第一行必须是
root = true,否则 Atom 会继续向上遍历父目录找其他.editorconfig,导致规则被意外覆盖 -
indent_size = 2是数字,不是字符串:indent_size = "2"会解析失败 - 最小可用配置示例(注意空行和段落分隔):
[*] root = true indent_style = space indent_size = 2 end_of_line = lf charset = utf-8
改完 .editorconfig 后,必须关掉所有编辑窗口,重新用 Add Project Folder 加载项目——Atom 不监听配置文件变更。











