atom中linter-eslint默认不检查.vue文件,需勾选“lint html files”并安装eslint-plugin-html;main.js中no-new警告应行级禁用;配置文件需设root: true防继承;prettier与eslint共存须用eslint-config-prettier并删格式规则。

Atom 里装了 linter-eslint 却不检查 .vue 文件?
默认情况下,linter-eslint 只处理 .js 文件,对 .vue 文件里的 <script></script> 块完全静音——这不是插件坏了,是它根本没被告诉“要解析 HTML 类型的文件”。
- 打开 Atom 设置 → Packages → 搜索
linter-eslint→ 点击 Settings - 勾选
Lint HTML Files(关键一步,必须开) - 确保项目已安装
eslint-plugin-html:npm install eslint-plugin-html --save-dev - 如果仍无效,检查
.eslintrc.js中是否配置了overrides,让 Vue 的 script 块走正确解析器:
overrides: [{
files: ["*.vue"],
processor: "vue/vue",
rules: { "no-unused-vars": "off" }
}]
为什么 main.js 总报 no-new 错误?
Vue 2/3 启动代码里 new Vue({ ... }) 或 createApp(...) 被 ESLint 当作“无意义的 new 表达式”警告,因为规则默认禁止孤立的构造函数调用——但它在这里是合法且必需的。
- 不要全局关掉
no-new,只在具体行禁用: -
/* eslint-disable no-new */放在new Vue(...)上一行 - 或更精准:
// eslint-disable-next-line no-new放在该行末尾 - 注意:Vue CLI 创建的项目若用
eslint-config-airbnb,它会继承这条规则;而eslint-plugin-vue默认已适配,建议优先用后者
ESLint 配置文件该放哪?"root": true 是干啥的?
ESLint 会从当前文件向上逐级查找配置文件(.eslintrc.js、package.json 中的 eslintConfig 等),直到找到第一个含 "root": true 的配置才停止——否则可能意外继承父目录的规则,导致本地开发行为和 CI 不一致。
- 项目根目录下新建
.eslintrc.js,开头就写:module.exports = { root: true, ... } - 避免在
node_modules或用户主目录下留残留配置 - 如果用了
eslint-plugin-vue,记得在extends中加入plugin:vue/vue3-essential(Vue 3)或plugin:vue/essential(Vue 2)
格式化和校验怎么不打架?Prettier + ESLint 在 Atom 里怎么共存
ESLint 检查逻辑和风格,Prettier 负责统一格式;两者规则重叠(比如 semi、quotes)会导致保存时反复修改、光标乱跳。必须让 ESLint “信任” Prettier 的格式决定。
- 安装
prettier-atom插件,并启用Format on Save - 安装
eslint-config-prettier:npm install eslint-config-prettier --save-dev - 在
.eslintrc.js的extends数组末尾加上prettier(顺序很重要!必须放最后) - 删掉所有和格式相关的 ESLint 规则,比如
semi、quotes、indent—— 全交给.prettierrc管
真正容易被忽略的是:Atom 的 linter-eslint 和 prettier-atom 插件都得设成“仅对 JS/TS/Vue 文件生效”,否则对 .json 或 .md 强行格式化会出错。










