eslint.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import js from '@eslint/js'
  2. import eslintConfigPrettier from 'eslint-config-prettier'
  3. import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
  4. import eslintPluginVue from 'eslint-plugin-vue'
  5. import globals from 'globals'
  6. import ts from 'typescript-eslint'
  7. export default [
  8. // 三大基本推荐规则
  9. js.configs.recommended,
  10. ...ts.configs.recommended,
  11. ...eslintPluginVue.configs['flat/recommended'],
  12. // 忽略规则
  13. {
  14. ignores: ['node_modules', 'dist', 'public'],
  15. },
  16. // 全局变量
  17. {
  18. languageOptions: {
  19. globals: {
  20. ...globals.browser,
  21. },
  22. },
  23. },
  24. // vue
  25. {
  26. files: ['**/*.vue'],
  27. languageOptions: {
  28. parserOptions: {
  29. // ts 解析器
  30. parser: ts.parser,
  31. // 允许 jsx
  32. ecmaFeatures: {
  33. jsx: true,
  34. },
  35. },
  36. },
  37. },
  38. // eslint + prettier 的兼容性问题解决规则
  39. eslintConfigPrettier,
  40. eslintPluginPrettierRecommended,
  41. // ts
  42. {
  43. files: ['**/*.{ts,tsx,vue}'],
  44. rules: {
  45. 'no-empty': 'off',
  46. 'no-undef': 'off',
  47. 'no-unused-vars': 'off',
  48. 'no-useless-escape': 'off',
  49. 'no-sparse-arrays': 'off',
  50. 'no-prototype-builtins': 'off',
  51. 'no-use-before-define': 'off',
  52. 'no-case-declarations': 'off',
  53. 'no-console': 'off',
  54. 'no-control-regex': 'off',
  55. 'vue/v-on-event-hyphenation': 'off',
  56. 'vue/custom-event-name-casing': 'off',
  57. 'vue/component-definition-name-casing': 'off',
  58. 'vue/attributes-order': 'off',
  59. 'vue/one-component-per-file': 'off',
  60. 'vue/html-closing-bracket-newline': 'off',
  61. 'vue/max-attributes-per-line': 'off',
  62. 'vue/multiline-html-element-content-newline': 'off',
  63. 'vue/singleline-html-element-content-newline': 'off',
  64. 'vue/attribute-hyphenation': 'off',
  65. 'vue/html-self-closing': 'off',
  66. 'vue/require-default-prop': 'off',
  67. 'vue/no-arrow-functions-in-watch': 'off',
  68. 'vue/no-v-html': 'off',
  69. 'vue/comment-directive': 'off',
  70. 'vue/multi-word-component-names': 'off',
  71. 'vue/require-prop-types': 'off',
  72. 'vue/html-indent': 'off',
  73. '@typescript-eslint/no-unsafe-function-type': 'off',
  74. '@typescript-eslint/no-empty-function': 'off',
  75. '@typescript-eslint/no-explicit-any': 'off',
  76. '@typescript-eslint/no-non-null-assertion': 'off',
  77. '@typescript-eslint/no-unused-expressions': 'off',
  78. '@typescript-eslint/no-unused-vars': [
  79. 'warn',
  80. {
  81. argsIgnorePattern: '^_',
  82. varsIgnorePattern: '^_',
  83. },
  84. ],
  85. },
  86. },
  87. // prettier 规则
  88. {
  89. files: ['**/*.{ts,tsx,vue,js}'],
  90. rules: {
  91. 'prettier/prettier': [
  92. 'warn', // 使用警告而不是错误
  93. {
  94. endOfLine: 'auto', // eslint 无需检查文件换行符
  95. },
  96. ],
  97. },
  98. },
  99. ]