zsqy-naive-ui/.eslintrc.cjs

142 lines
3.8 KiB
JavaScript
Raw Normal View History

2024-01-05 17:28:54 +08:00
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true,
},
2024-02-05 10:47:59 +08:00
parser: 'vue-eslint-parser',
2024-01-05 17:28:54 +08:00
extends: [
// https://eslint.vuejs.org/user-guide/#usage
2024-02-05 10:47:59 +08:00
'plugin:vue/vue3-recommended',
'./.eslintrc-auto-import.json',
'prettier',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
2024-01-05 17:28:54 +08:00
],
parserOptions: {
2024-02-05 10:47:59 +08:00
ecmaVersion: 'latest',
sourceType: 'module',
parser: '@typescript-eslint/parser',
project: './tsconfig.*?.json',
2024-01-05 17:28:54 +08:00
createDefaultProgram: false,
2024-02-05 10:47:59 +08:00
extraFileExtensions: ['.vue'],
2024-01-05 17:28:54 +08:00
},
2024-02-05 10:47:59 +08:00
plugins: ['vue', '@typescript-eslint'],
2024-01-05 17:28:54 +08:00
rules: {
// 禁止使用 var用 let 和 const 代替
2024-02-05 10:47:59 +08:00
'no-var': 'error',
2024-01-05 17:28:54 +08:00
// 在 Vue 的 v-for 循环中要求使用 :key
2024-02-05 10:47:59 +08:00
'vue/require-v-for-key': 'error', // vue的for循环是否必须有key
2024-01-05 17:28:54 +08:00
// 关闭 Vue 组件名必须多字的规则
2024-02-05 10:47:59 +08:00
'vue/multi-word-component-names': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 Vue 的 v-model 中的参数规则
2024-02-05 10:47:59 +08:00
'vue/no-v-model-argument': 'off',
2024-01-05 17:28:54 +08:00
// Vue 的 setup() 函数必须使用的变量规则
2024-02-05 10:47:59 +08:00
'vue/script-setup-uses-vars': 'error',
2024-01-05 17:28:54 +08:00
// 关闭 Vue 组件名的保留规则
2024-02-05 10:47:59 +08:00
'vue/no-reserved-component-names': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 Vue 事件名的命名规则
2024-02-05 10:47:59 +08:00
'vue/custom-event-name-casing': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 Vue 属性的顺序规则
2024-02-05 10:47:59 +08:00
'vue/attributes-order': 'off',
2024-01-05 17:28:54 +08:00
// 关闭一个文件只能有一个组件规则
2024-02-05 10:47:59 +08:00
'vue/one-component-per-file': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 HTML 标签闭合换行规则
2024-02-05 10:47:59 +08:00
'vue/html-closing-bracket-newline': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 HTML 属性每行最大数量规则
2024-02-05 10:47:59 +08:00
'vue/max-attributes-per-line': 'off',
2024-01-05 17:28:54 +08:00
// 关闭多行 HTML 元素内容的规则
2024-02-05 10:47:59 +08:00
'vue/multiline-html-element-content-newline': 'off',
2024-01-05 17:28:54 +08:00
// 关闭单行 HTML 元素内容的规则
2024-02-05 10:47:59 +08:00
'vue/singleline-html-element-content-newline': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 HTML 属性连字符的规则
2024-02-05 10:47:59 +08:00
'vue/attribute-hyphenation': 'off',
2024-01-05 17:28:54 +08:00
// 关闭要求 Vue 默认属性的规则
2024-02-05 10:47:59 +08:00
'vue/require-default-prop': 'off',
2024-01-05 17:28:54 +08:00
// 关闭要求 Vue 显式触发事件的规则
2024-02-05 10:47:59 +08:00
'vue/require-explicit-emits': 'off',
2024-01-05 17:28:54 +08:00
// HTML 标签自闭合规则
2024-02-05 10:47:59 +08:00
'vue/html-self-closing': [
'error',
2024-01-05 17:28:54 +08:00
{
html: {
2024-02-05 10:47:59 +08:00
void: 'always', // 自闭合标签必须自闭合
normal: 'never', // 普通标签不得自闭合
component: 'always', // 组件标签必须自闭合
2024-01-05 17:28:54 +08:00
},
2024-02-05 10:47:59 +08:00
svg: 'always',
math: 'always',
2024-01-05 17:28:54 +08:00
},
],
// 警告空方法检查
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-empty-function': 'warn',
2024-01-05 17:28:54 +08:00
// 关闭 any 类型的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-explicit-any': 'off',
2024-01-05 17:28:54 +08:00
// 关闭使用 @ts-ignore 的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/ban-ts-ignore': 'off',
2024-01-05 17:28:54 +08:00
// 关闭使用 @ts-comment 的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/ban-ts-comment': 'off',
2024-01-05 17:28:54 +08:00
// 关闭一些特定类型的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/ban-types': 'off',
2024-01-05 17:28:54 +08:00
// 关闭函数返回类型的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/explicit-function-return-type': 'off',
2024-01-05 17:28:54 +08:00
// 关闭 any 类型的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-explicit-any': 'off',
2024-01-05 17:28:54 +08:00
// 关闭使用 require 的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-var-requires': 'off',
2024-01-05 17:28:54 +08:00
// 关闭使用尚未定义的变量的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-use-before-define': 'off',
2024-01-05 17:28:54 +08:00
// 关闭模块导出类型的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/explicit-module-boundary-types': 'off',
2024-01-05 17:28:54 +08:00
// 未使用的变量的警告
2024-02-05 10:47:59 +08:00
'@typescript-eslint/no-unused-vars': 'warn',
2024-01-05 17:28:54 +08:00
// Prettier 配置
2024-02-05 10:47:59 +08:00
'prettier/prettier': [
'error',
2024-01-05 17:28:54 +08:00
{
useTabs: false, // 不使用制表符
},
],
},
// eslint不能对html文件生效
overrides: [
{
2024-02-05 10:47:59 +08:00
files: ['*.html'],
processor: 'vue/.vue',
2024-01-05 17:28:54 +08:00
},
],
// https://eslint.org/docs/latest/use/configure/language-options#specifying-globals
globals: {
2024-02-05 10:47:59 +08:00
OptionType: 'readonly',
2024-01-05 17:28:54 +08:00
},
};