module.exports = {
root: true, // 标识当前配置文件为eslint的根配置文件,让其停止在父级目录中继续寻找。
parserOptions: { // 解析器配置项
parser: "babel-eslint" // 代码需要经过babel转化,则对应使用这个解析器
},
env: {
browser: true // 浏览器环境
},
extends: [ // 规则继承
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
"plugin:vue/essential", // 额外添加的规则
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
"standard",
"eslint:recommended", // eslint内置推荐规则
"plugin:vue/essential"
],
// required to lint *.vue files
/**
* 插件
* http://eslint.cn/docs/user-guide/configuring#configuring-plugins
* 【】插件同样需要在node_module中下载
* 【】注意插件名忽略了「eslint-plugin-」前缀,所以在package.json中,对应的项目名是「eslint-plugin-vue」
* 【】插件的作用类似于解析器,用以扩展解析器的功能,用于检测非常规的js代码。也可能会新增一些特定的规则。
* 【】如 eslint-plugin-vue,是为了帮助我们检测.vue文件中 <template> 和 <script> 中的js代码
*/
plugins: ["vue"],
// add your custom rules here
/**
* 自定义规则
* http://eslint.cn/docs/user-guide/configuring#configuring-rules
* 【】基本使用方式
* "off" 或者0 关闭规则
* "warn" 或者1 将规则打开为警告(不影响退出代码)
* "error" 或者2 将规则打开为错误(触发时退出代码为1)
* 如:'no-restricted-syntax': 0, // 表示关闭该规则
* 【】如果某项规则,有额外的选项,可以通过数组进行传递,而数组的第一位必须是错误级别。如0,1,2
* 如 'semi': ['error', 'never'], never就是额外的配置项
*/
rules: {
// allow async-await
"prettier.semi": false, // 句尾添加分号
"generator-star-spacing": "off", // 生成器中'*'两侧都要有间距
// allow debugger during development
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off", // 只有开发环境可以使用debugger
"indent": ["off", 2], // 缩进风格
"vue/require-v-for-key": 0, v-for的时候,可以不用v-bind:key,当然我觉得还是保留好
"vue/valid-v-for": 0,
"vue/no-parsing-error": 0,
"no-return-assign": 0, // 消除return陈述中的任务,除非用括号括起来
"no-unneeded-ternary": 0, // 不允许将条件表达式作为默认的分配模式
"handle-callback-err": 0, // nodejs 处理错误
"no-console": "off", // 禁止使用console
"vue/script-indent": [ // script标签缩进设置
"error",
2,
{
baseIndent: 1,
switchCase: 1
}
]
},
/**
* 针对特定文件的配置
* 【】可以通过overrides对特定文件进行特定的eslint检测
* 【】特定文件的路径书写使用Glob格式,一个类似正则的路径规则,可以匹配不同的文件
* 【】配置几乎与 ESLint 的其他配置相同。覆盖块可以包含常规配置中的除了 extends、overrides 和 root 之外的其他任何有效配置选项,
*/
overrides: [
{
'files': ['*.vue'],
'rules': {
'indent': 'off' // 缩进风格
}
}
]
};