适用于vue2的.eslintrc.js
时间: 2023-08-30 09:06:28 浏览: 38
好的,针对你的问题,下面是一份适用于 Vue2 的 .eslintrc.js 配置示例:
```
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/essential',
'eslint:recommended',
],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'indent': ['error', 2],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'vue/html-indent': ['error', 2],
},
};
```
这份配置基于官方推荐的 Vue 插件,同时也包括了 ESLint 的基础规则。其中,我们使用了 babel-eslint 进行代码解析,因为它支持 Vue 文件中的新语法特性。
针对具体的规则,这份配置中禁止了在生产环境下使用 console 和 debugger,同时规定了代码缩进为2个空格、使用单引号和使用分号结尾。此外,还针对 Vue 模板的缩进规则进行了设置。
希望这份配置能帮到你,如果还有其他问题,欢迎继续提问。