87 lines
3.2 KiB
JavaScript
87 lines
3.2 KiB
JavaScript
// .eslintrc.js
|
||
module.exports = {
|
||
root: true,
|
||
parserOptions: {
|
||
parser: '@babel/eslint-parser',
|
||
requireConfigFile: false,
|
||
sourceType: 'module'
|
||
},
|
||
env: {
|
||
browser: true,
|
||
node: true,
|
||
es6: true
|
||
},
|
||
extends: [
|
||
'plugin:vue/vue3-essential',
|
||
'eslint:recommended',
|
||
'plugin:prettier/recommended'
|
||
],
|
||
// add your custom rules here
|
||
rules: {
|
||
'no-undef': 0,
|
||
// "off" or 0 - 关闭规则
|
||
// "warn" or 1 - 将规则视为一个警告
|
||
// "error" or 2 - 将规则视为一个错误
|
||
'prettier/prettier': 'error',
|
||
|
||
// allow async-await
|
||
'generator-star-spacing': 'off',
|
||
// 'no-console': process.env.VITE_ENV === 'production' ? 'error' : 'off',
|
||
// allow debugger during development
|
||
// 'no-debugger': process.env.VITE_ENV === 'production' ? 'error' : 'off',
|
||
|
||
/**
|
||
* 最佳实践
|
||
*/
|
||
eqeqeq: 2, // 强制使用 === 和 !==
|
||
'default-case': 1, // 要求 switch 语句中有 default 分支
|
||
'no-else-return': 1, // 禁止 if 语句中 return 语句之后有 else 块
|
||
'no-empty-function': 0, // 禁止出现空函数
|
||
'no-unused-vars': 0, // 禁止出现空函数
|
||
'no-multi-spaces': 1, // 禁止使用多个空格
|
||
radix: 1, // 强制在parseInt()使用基数参数
|
||
'no-useless-return': 1, // 禁止多余的 return 语句
|
||
'no-with': 2, //禁用 with 语句
|
||
/**
|
||
* 变量声明
|
||
*/
|
||
'init-declarations': ['error', 'always'], // 声明变量必须赋值
|
||
|
||
/**
|
||
* ECMAScript6
|
||
*/
|
||
'arrow-spacing': ['error', { before: true, after: true }], // 强制箭头函数的箭头前后使用空格
|
||
'no-var': 2, // 禁止使用 var 声明变量
|
||
'object-shorthand': 2, // 要求使用对象方法名和属性名简写
|
||
'prefer-arrow-callback': 2, // 要求回调函数使用箭头函数
|
||
'prefer-const': 2, // 使用 const 声明那些声明后不再被修改的变量
|
||
'prefer-rest-params': 2, // 要求使用剩余参数而不是 arguments
|
||
'no-duplicate-imports': 2, // 禁止重复模块导入
|
||
'prefer-destructuring': 1, // 优先使用数组和对象解构
|
||
/**
|
||
* 风格指南
|
||
*/
|
||
'space-before-function-paren': 0, // 函数名称或function关键字与开始参数之间允许有空格
|
||
'array-bracket-spacing': 0, // 数组方括号内必须空格
|
||
'comma-dangle': 2, // 禁止末尾逗号
|
||
'eol-last': 2, // 要求文件末尾存在空行
|
||
// 对象冒号前禁止空格,冒号后必须空格
|
||
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
||
// 关键字(if、else等)前后必须有空格
|
||
'keyword-spacing': ['error', { before: true, after: true }],
|
||
// 禁止出现多行空行
|
||
'no-multiple-empty-lines': ['error', { max: 1 }],
|
||
semi: 0, // 禁止末尾分号
|
||
quotes: ['error', 'single'], // 强制使用单引号
|
||
'space-infix-ops': 2, // 操作符周围必须有空格
|
||
'spaced-comment': ['error', 'always'], // 注释后面必须跟随至少一个空白
|
||
'object-curly-spacing': 0,
|
||
'no-unused-expressions': 0,
|
||
'vue/multi-word-component-names': 0,
|
||
'no-process-env': 2,
|
||
camelcase: 2,
|
||
'no-lonely-if': 2,
|
||
'func-style': 2 // 禁止使用function声明,请使用箭头函数声明
|
||
}
|
||
}
|