eslint.config.mjs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import tseslint from '@electron-toolkit/eslint-config-ts'
  2. import eslintConfigPrettier from '@electron-toolkit/eslint-config-prettier'
  3. import eslintPluginVue from 'eslint-plugin-vue'
  4. import vueParser from 'vue-eslint-parser'
  5. export default tseslint.config(
  6. { ignores: ['**/node_modules', '**/dist', '**/out'] },
  7. tseslint.configs.recommended,
  8. eslintPluginVue.configs['flat/recommended'],
  9. {
  10. files: ['**/*.vue'],
  11. languageOptions: {
  12. parser: vueParser,
  13. parserOptions: {
  14. ecmaFeatures: {
  15. jsx: true
  16. },
  17. extraFileExtensions: ['.vue'],
  18. parser: tseslint.parser
  19. }
  20. }
  21. },
  22. {
  23. files: ['**/*.{ts,mts,tsx,vue}'],
  24. rules: {
  25. 'vue/require-default-prop': 'off',
  26. 'vue/multi-word-component-names': 'off',
  27. // eslint (http://eslint.cn/docs/rules)
  28. 'no-useless-escape': 0, // 关闭不必要的转义
  29. 'no-var': 'error', // 要求使用 let 或 const 而不是 var
  30. 'no-multiple-empty-lines': ['error', { max: 1 }], // 不允许多个空行
  31. 'prefer-const': 1, // 使用 let 关键字声明但在初始分配后从未重新分配的变量,要求使用 const
  32. 'no-use-before-define': 0, // 禁止在 函数/类/变量 定义之前使用它们
  33. 'prettier/prettier': [
  34. 'warn',
  35. {
  36. singleQuote: true,
  37. semi: false
  38. }
  39. ],
  40. // typeScript (https://typescript-eslint.io/rules)
  41. '@typescript-eslint/no-unused-vars': 0, // 禁止定义未使用的变量
  42. '@typescript-eslint/no-empty-function': 0, // 禁止空函数
  43. 'no-empty': 0, // 判据可以为空
  44. '@typescript-eslint/prefer-ts-expect-error': 'error', // 禁止使用 @ts-ignore
  45. '@typescript-eslint/ban-ts-comment': 'error', // 禁止 @ts-<directive> 使用注释或要求在指令后进行描述
  46. '@typescript-eslint/no-inferrable-types': 0, // 可以轻松推断的显式类型可能会增加不必要的冗长
  47. '@typescript-eslint/no-namespace': 0, // 禁止使用自定义 TypeScript 模块和命名空间
  48. '@typescript-eslint/no-explicit-any': 0, // 禁止使用 any 类型
  49. '@typescript-eslint/ban-types': 0, // 禁止使用特定类型
  50. '@typescript-eslint/no-var-requires': 0, // 允许使用 require() 函数导入模块
  51. '@typescript-eslint/no-non-null-assertion': 0, // 不允许使用后缀运算符的非空断言(!)
  52. '@typescript-eslint/no-unused-expressions': 0, // 方法可以不返回
  53. // vue (https://eslint.vuejs.org/rules)
  54. 'vue/script-setup-uses-vars': 'error', // 防止<script setup>使用的变量<template>被标记为未使用,此规则仅在启用该 no-unused-vars 规则时有效
  55. 'vue/v-slot-style': 'error', // 强制执行 v-slot 指令样式
  56. 'vue/no-mutating-props': 'error', // 不允许改变组件 prop
  57. 'vue/custom-event-name-casing': 'error', // 为自定义事件名称强制使用特定大小写
  58. 'vue/attribute-hyphenation': 'error', // 对模板中的自定义组件强制执行属性命名样式:my-prop="prop"
  59. 'vue/attributes-order': 0, // vue api使用顺序,强制执行属性顺序
  60. 'vue/no-v-html': 0, // 禁止使用 v-html
  61. 'vue/no-setup-props-destructure': 0, // 禁止解构 props 传递给 setup
  62. // singleline...单行元素的配置。如果元素没有属性或最后一个属性与左括号位于同一行,则它是单行元素。"never"(默认)...不允许在右括号前换行。"always"...要求在右括号前有一个换行符。
  63. // multiline...多行元素的配置。如果最后一个属性不在左括号的同一行上,则它是一个多行元素。"never"...不允许在右括号前换行。"always"(默认)...要求在右括号前有一个换行符。
  64. 'vue/html-closing-bracket-newline': [
  65. 'error',
  66. {
  67. singleline: 'never',
  68. multiline: 'never'
  69. }
  70. ],
  71. 'vue/block-lang': [
  72. 'error',
  73. {
  74. script: {
  75. lang: 'ts'
  76. }
  77. }
  78. ]
  79. }
  80. },
  81. eslintConfigPrettier
  82. )