144 lines
5.2 KiB
JavaScript
144 lines
5.2 KiB
JavaScript
module.exports = {
|
||
root: true,
|
||
env: {
|
||
browser: true,
|
||
node: true,
|
||
es6: true
|
||
},
|
||
globals: {
|
||
uni: 'writable',
|
||
getApp: 'writable',
|
||
wx: 'writable',
|
||
getCurrentPages: 'writable',
|
||
requirePlugin: 'writable',
|
||
plus: 'writable'
|
||
},
|
||
// 指定如何解析语法
|
||
parser: 'vue-eslint-parser',
|
||
// 优先级低于 parse 的语法解析配置
|
||
parserOptions: {
|
||
ecmaVersion: 'latest',
|
||
sourceType: 'module',
|
||
ecmaFeatures: {
|
||
jsx: false
|
||
}
|
||
},
|
||
// 继承某些已有的规则
|
||
extends: [
|
||
'plugin:vue/vue3-recommended', // 使用插件支持vue3
|
||
'airbnb-base',
|
||
'plugin:prettier/recommended'
|
||
],
|
||
ignorePatterns: ['utils/log.js', 'unpackage/**/*'],
|
||
// 针对不同文件类型使用不同配置
|
||
overrides: [
|
||
{
|
||
files: ['**/*.uts'],
|
||
parser: '@typescript-eslint/parser',
|
||
plugins: ['@typescript-eslint'],
|
||
extends: ['plugin:@typescript-eslint/recommended'],
|
||
parserOptions: {
|
||
ecmaVersion: 'latest',
|
||
sourceType: 'module'
|
||
},
|
||
globals: {
|
||
IUniError: 'readonly',
|
||
UniError: 'readonly',
|
||
uni: 'readonly',
|
||
getApp: 'readonly',
|
||
wx: 'readonly',
|
||
getCurrentPages: 'readonly',
|
||
requirePlugin: 'readonly',
|
||
plus: 'readonly'
|
||
},
|
||
rules: {
|
||
'func-names': 'off',
|
||
'@typescript-eslint/no-unused-vars': 'warn',
|
||
'@typescript-eslint/no-explicit-any': 'warn',
|
||
eqeqeq: 'warn',
|
||
'no-undef': 'off',
|
||
'prettier/prettier': 'off',
|
||
'import/no-unresolved': 'off' // 禁用模块解析检查
|
||
}
|
||
}
|
||
],
|
||
/**
|
||
* "off" 或 0 ==> 关闭规则
|
||
* "warn" 或 1 ==> 打开的规则作为警告(不影响代码执行)
|
||
* "error" 或 2 ==> 规则作为一个错误(代码不能执行,界面报错)
|
||
*/
|
||
rules: {
|
||
// eslint (http://eslint.cn/docs/rules)
|
||
'prettier/prettier': 'error',
|
||
'import/extensions': 0,
|
||
'prefer-template': 0,
|
||
'no-var': 'error', // 要求使用 let 或 const 而不是 var
|
||
'no-multiple-empty-lines': ['error', { max: 1 }], // 不允许多个空行
|
||
'prefer-const': 'off', // 使用 let 关键字声明但在初始分配后从未重新分配的变量,要求使用 const
|
||
'no-use-before-define': 'off', // 禁止在 函数/类/变量 定义之前使用它们
|
||
'no-irregular-whitespace': 'off', // 禁止不规则的空白
|
||
'no-undef': 'error', // 禁止使用未声明的变量
|
||
'no-unused-vars': [
|
||
'error',
|
||
{
|
||
vars: 'all',
|
||
args: 'after-used',
|
||
ignoreRestSiblings: false,
|
||
caughtErrors: 'all'
|
||
}
|
||
], // 禁止出现未使用过的变量
|
||
'vue/script-setup-uses-vars': 'error', // 确保script setup中的变量必须正确定义
|
||
'vue/no-undef-components': 'off', // 关闭组件未定义的检查
|
||
'vue/no-undef-properties': 'off', // 关闭属性未定义的检查
|
||
'vue/no-unused-vars': [
|
||
'error',
|
||
{
|
||
ignorePattern: ''
|
||
}
|
||
], // 禁止Vue组件中出现未使用的变量
|
||
'vue/no-unused-refs': 'error', // 禁止定义但未使用的ref
|
||
'vue/require-component-is': 'error', // 禁止模板中未使用的组件
|
||
'import/no-unused-modules': 'off', // 关闭模块导出检查
|
||
'import/no-cycle': 0,
|
||
'no-nested-ternary': 0,
|
||
'import/prefer-default-export': 0,
|
||
'import/no-unresolved': 0,
|
||
'prefer-destructuring': 0,
|
||
'no-shadow': 0,
|
||
'no-param-reassign': 0,
|
||
'consistent-return': 0,
|
||
'no-case-declarations': 0,
|
||
'prefer-promise-reject-errors': 0,
|
||
'jsx-a11y/click-events-have-key-events': 0,
|
||
'jsx-a11y/no-static-element-interactions': 0,
|
||
camelcase: 0,
|
||
'import/no-extraneous-dependencies': 0,
|
||
'no-underscore-dangle': 0,
|
||
'no-debugger': 0,
|
||
'no-promise-executor-return': 0,
|
||
// vue (https://eslint.vuejs.org/rules)
|
||
'vue/v-slot-style': 'error', // 强制执行 v-slot 指令样式
|
||
'vue/no-mutating-props': 'off', // 不允许组件 prop的改变
|
||
'vue/no-v-html': 'off', // 禁止使用 v-html
|
||
'vue/custom-event-name-casing': 'off', // 为自定义事件名称强制使用特定大小写
|
||
'vue/attributes-order': 'off', // vue api使用顺序,强制执行属性顺序
|
||
'vue/one-component-per-file': 'off', // 强制每个组件都应该在自己的文件中
|
||
'vue/html-closing-bracket-newline': 'off', // 在标签的右括号之前要求或禁止换行
|
||
'vue/max-attributes-per-line': 'off', // 强制每行的最大属性数
|
||
'vue/multiline-html-element-content-newline': 'off', // 在多行元素的内容之前和之后需要换行符
|
||
'vue/singleline-html-element-content-newline': 'off', // 在单行元素的内容之前和之后需要换行符
|
||
'vue/attribute-hyphenation': 'off', // 对模板中的自定义组件强制执行属性命名样式
|
||
'vue/require-default-prop': 'off', // 此规则要求为每个 prop 为必填时,必须提供默认值
|
||
'vue/multi-word-component-names': 'off', // 要求组件名称始终为 "-" 链接的单词
|
||
'vue.prefer-template': 'off',
|
||
'vuejs-accessibility/click-events-have-key-events': 'off',
|
||
'no-console': 'off',
|
||
'no-plusplus': 'off',
|
||
'no-await-in-loop': 'off',
|
||
'no-async-promise-executor': 'off',
|
||
'no-return-await': 'off',
|
||
'no-loop-func': 'off',
|
||
'no-bitwise': 'off'
|
||
}
|
||
}
|